Configuring zf2 on ubuntu 13.10 with an Apache virtual host

I am setting up a Zend application (ZF2) in ubuntu 13.10. Following the instructions below:

  • Enter the code /var/www/ with the name zfapp

Virtual host configuration:

  <VirtualHost *:80> ServerName zfapp.com DocumentRoot /var/www/zfapp/ <Directory /> Options FollowSymLinks AllowOverride All </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined </VirtualHost> 
  • Creating a virtual host for it in /etc/hosts

    127.0.0.1 zfapp.com

  • Add file to /etc/apache2/sites-available/zfapp.cof

  • sudo a2enmod rewrite

  • sudo a2ensite zfapp.conf

  • sudo service apache2 restart

However, when I browse the site ( zfapp.com/api/user/auth ); It gives the following error:

Not Found Requested Url /api/user/auth not found on this server

I have an MVC javascript project in which I use PHP as a server language.

Here is the structure of the project directory:

ProjectDir javascriptMVC folder-> jsfiles models / controllers api folder → Zend project

I made an api symbolic link that points to api/public inside the javascriptMVC directory that I use in AJAX calls on a PHP server. like /api/user/auth . The same structure works on an old Ubuntu machine.

I think this has something to do with Apache configuration; or maybe i need to set any alias?

+7
php ubuntu apache virtualhost zend-framework2
source share
3 answers

Thanks everyone

I found a problem.

In apache 2.4.6 and ubuntu 13.10 we need to update apache2.conf to change

 <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> 

from

 <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> 

and create your virtual host file something like this

 <VirtualHost zfapp.com:80> ServerName zfapp.com DocumentRoot /var/www/zfapp/index <Directory /var/www/zfapp/index> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog /var/log/apache2/error.log CustomLog /var/log/apache2/access.log combined </VirtualHost> 

I found a solution from: https://askubuntu.com/questions/423514/how-to-enable-mod-rewrite-for-virtual-host

By the way, thanks @Bilal, @jmleroux

+10
source share

Without code, it's hard to diagnose ...

Perhaps the problem of rewriting the URL:

Did you enable mod_rewrite?

Have you installed AllowOverride All ?

+2
source share

@Bilal probably means your ZF2 routing configuration: http://framework.zend.com/manual/2.0/en/modules/zend.mvc.routing.html

0
source share

All Articles