1

I'm following this tutorial to learn how to start a project using ZendFramework

http://framework.zend.com/manual/1.12/en/learning.quickstart.create-project.html

When I get to setup a virtual host I get stuck. If I do exactly as the tutorial says, it shows me an error (in all my project, zend or not), says the file wasn't found.

Then I found this tutorial on StackOverflow very handy

Can't run zend framework MVC application on WAMP

Following what the guy on the bottom of the page says takes me to the same error when I try to access my app as zendProject.local/

This is what I got

on hosts (Windows/System32/drivers/etc/hosts) file

127.0.0.1       blog.local

on httpd-vhosts.conf file

<VirtualHost 127.0.0.1>
ServerName blog.local
DocumentRoot /blog/public

SetEnv APPLICATION_ENV "development"

<Directory /blog/public>
    DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Can you tell me what I am doing wrong? The browser still says Not Found The requested URL /public was not found on this server when I go to http://blog.local/

I'm running WAMP on Windows. And this is the absolute path to the 'blog' project C:\wamp\www\blog

@Edit RiggsFolly

this is what I got now in the httpd-vhosts.conf file

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:/wamp/www"

    <Directory "C:/wamp/www">
        AllowOverride All
        # make sure this is only allowed to be accessed by the local machine
        # then if/when you open one of your other sites up to the internet and somebody uses your IP
        # they will get directed here as its the first VH def and then receive a 403 not allowed to access
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName blog.local
    DocumentRoot "C:/websites/blog/public"
    Options Indexes FollowSymLinks
    SetEnv APPLICATION_ENV "development"

    <Directory "C:/websites/blog/public">
        DirectoryIndex index.php
        AllowOverride All
        Require all granted        
    </Directory>
</VirtualHost>

And I created a new directory at C:/ called 'websites' as you suggested

1 Answer 1

4

You need to be a little more specific with your folder locations. I guess this tutorial was written for Unix and you are using windows.

For Apache 2.2.x use this syntax:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName blog.local
    DocumentRoot "C:/wamp/www/blog/public"
    Options Indexes FollowSymLinks
    SetEnv APPLICATION_ENV "development"

<Directory "C:/wamp/www/blog/public">
    DirectoryIndex index.php
    AllowOverride All
    Order Allow,Deny
    Allow from all
</Directory>

You would be better avoiding the Allow from all and using Allow from localhost 127.0.0.1 ::1 until you actually want to allow the universe to see your sites.

For Apache 2.4.x use this syntax:

<VirtualHost *:80>
    ServerName blog.local
    DocumentRoot "C:/wamp/www/blog/public"
    Options Indexes FollowSymLinks
    SetEnv APPLICATION_ENV "development"

<Directory "C:/wamp/www/blog/public">
    DirectoryIndex index.php
    AllowOverride All
    Require all granted        
</Directory>

Note NameVirtualHost *:80 no longer required for Apache 2.4.x

Again you would be better avoiding the Require all granted and using Require local until you actually want to allow the universe to see your sites.

EDITED After comment from Questioner:

Right, that's the Apache default. If you enter a url it cannot find a Virtual Host definition for it will default to the first Virtual Host definition you gave it, the blog in your case.

Ok, so now you need to create a Virtual Host for each of your other projects, and MOST IMPORTANTLY the first one needs to be localhost and only be allowed to be accessed from the local PC for a bit of extra security.

Now personally I would take this opportunity to move my actual sites to a totally separate folder structure outside the \wamp\ folder structure so there is no confusion with rights given to the \wamp\www folder and my other sites.

So for example, create a folder c:\websites\www and in that folder create a folder for each of your projects eg

c:\websites\www\blog
c:\websites\www\project2

Then point your virtual hosts to the relevant folder containing the site code ( this can be on another disk if you like ). This allows you to specify the Apache security ( who is allowed in to this site) specifically for each of your VHOSTS. So when you want a client or friend to be able to play with one site, you just change the security on that one site while you let them play.

Like this:

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:/wamp/www"

    <Directory "C:/wamp/www">
        AllowOverride All
        # make sure this is only allowed to be accessed by the local machine
        # then if/when you open one of your other sites up to the internet and somebody uses your IP
        # they will get directed here as its the first VH def and then receive a 403 not allowed to access
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName blog.local
    DocumentRoot "C:/websites/www/blog/public"
    Options Indexes FollowSymLinks
    SetEnv APPLICATION_ENV "development"

    <Directory "C:/websites/www/blog/public">
        DirectoryIndex index.php
        AllowOverride All
        Require all granted        
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName project2.dev
    DocumentRoot "C:/websites/www/project2"
    Options Indexes FollowSymLinks

    <Directory "C:/websites/www/project2">
        DirectoryIndex index.php
        AllowOverride All
        Require local
        # this site also available to other PC's on my internal network
        Require ip 192.168.0
    </Directory>
</VirtualHost>

Remember, for each new Virtual Host site you create you also need to add that ServerName (project2.dev) to the hosts file.

hosts file:
127.0.0.1  blog.local
127.0.0.1  project2.dev

I hope this helps.

7
  • hey, man! thank you! I did what you said and it's working. But now if I try to go to any of my other projects apache redirects to the ZendApplication (using localhost). What do I need to do to see the Blog App only if I go to localhost/blog ? Feb 12, 2014 at 14:07
  • thanks for your reply. Now after adding the localhost directive it is working like I did nothing, just like before starting to set up VirtualHosts. Do you know why? How am I supposed to access the Blog with this new configuration? @edit have a look at my latest edit on the post Feb 12, 2014 at 15:47
  • Well if I got it right, you should be able to use http://localhost to get to the WAMPServr home page and http://blog.local to get to your bloging site.
    – RiggsFolly
    Feb 12, 2014 at 15:59
  • IF when you use http://blog.local it goes to the WAMP Homepage then there is something wrong with the VHOST definition for blog.local
    – RiggsFolly
    Feb 12, 2014 at 16:01
  • when I use blog.local it says the URL wasn't found on the current server. This is the message, notice the / on The requested URL / was not found on this server Feb 12, 2014 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.