Question

I am building a web application with Zend Framework, and I need to point my app to the "public" folder of the application:

So basically when I call http://localhost/myapp it should display http://localhost/myapp/public/

I created a virtual host file called myapp into /etc/apache2/sites-available/:

    <VirtualHost *:80>
DocumentRoot /var/www/myapp/public/
 <Directory />
  Options FollowSymLinks
  AllowOverride None
 </Directory>
 <Directory /var/www/myapp/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
 </Directory>

</VirtualHost>

But it doesn't work. When I call http://localhost/myapp, it displays the directory structure of the app, and when I click on the "public" folder, then it displays what I want to be displayed by default... I never configured vhosts before and that's as far as I got with the tutorials about it.

Was it helpful?

Solution 2

Ok I found a way somehow... I don't think it's necessary the right/best way but...

in httpd.conf (in apache2 folder):

Listen 10089

<VirtualHost *:10089>

    DocumentRoot "/var/www/myapp/public"

    <Directory "/var/www/myapp/public">

        Order allow,deny

        Allow from all

    AllowOverride all

</Directory>

</VirtualHost>

My app is now accessible via localhost:10089 After enabling the rewrite mod in apache, I added the necessary .htaccess, one at the root of my app, redirecting everything to index.php (Zend framework support friendly url navigation and works that way):

RewriteEngine on

RewriteRule .* index.php

and a second .htaccess file inside my public folder to allow people to access .jpg,.ico,etc files and not being redirected to index for everything:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]

RewriteCond %{REQUEST_FILENAME} -l [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ /index.php [NC,L]

Hope this will help some!

OTHER TIPS

In your first listing, you had a different value for the Directory tag, leaving off 'public' altogether. There was also a trailing slash after 'public' in the DocRoot value, but removed on your second attempt. Not sure that made a difference, but I believe it's recommended that you don't include trailing slashes.

Also, just wondering...are you running this on a local machine? I had trouble with Skype wanting to use port 80 if I started running that before my apache server. Skype will use a different port if 80 is already used. If not Skype, there may be another app that's using port 80 and interfering. That could be why you had success on another port.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top