2
votes

Hi everyone I'm new with Zend Framework and apparently quite unable to make it work.

When I try to access localhost the browser throws a 403 forbidden access error at me. Here's my virtual host file:

  NameVirtualHost *:80
<VirtualHost *:80>
    ServerName zf2-tutorial.localhost
    DocumentRoot /var/www/html/zf2-tutorial/public
    SetEnv APPLICATION_ENV "development"
    <Directory /var/www/html/zf2-tutorial/public>
        Options +Indexes +FollowSymLinks +ExecCGI
    DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

And my htacces file wich is located into the public directory within the zend application folder on /var/www/html/zf2-tutorial/:

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

I also have 775 permission for all files on that directory. However the apache error_log seems to think otherwise:

[Thu Mar 14 12:15:48.751980 2013] [core:crit] [pid 5755] (13)Permission denied: [client 127.0.0.1:60849] AH00529: /var/www/html/zf2-tutorial/public/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/var/www/html/zf2-tutorial/public/' is executable

Finally I also have FileInfo set on httpd.conf in order to allow htaccess reading.

So, any clue of what's happening here? Thanks!

UPDATE: I post the file list of /var/www/html/zf2-tutorial/public folder with their permissions:

total 28
drwxrwxr-x. 5 gerard root 4096 mar 14 14:01 .
drwxr-xr-x. 7 gerard root 4096 mar 14 11:20 ..
drwxrwxr-x. 2 gerard root 4096 ene 31 17:19 css
-rwxrwxr-x. 1 gerard root  711 mar 14 12:25 .htaccess
drwxrwxr-x. 2 gerard root 4096 ene 31 17:19 images
-rwxrwxr-x. 1 gerard root  303 ene 31 17:19 index.php
drwxrwxr-x. 2 gerard root 4096 ene 31 17:19 js
4
Could you edit your question to include the output of ls -al /var/www/html/zf2-tutorial/public? - Tim Fountain
There you have it. gerard is my username (I changed the owner of public folder to my account to check if that was the problem) - Gerard Clos

4 Answers

3
votes

I had the same problem using EasyPHP DevServ 14.

The problem came from a missing line inside httpd.conf file

Require all granted

<Directory "PATH TO YOUR DIR">
    Options FollowSymLinks Indexes
    AllowOverride All
    Order deny,allow
    Allow from any
    Deny from none
    Require all granted
</Directory>

Hope it helps!

1
votes

in the virtual host setup ensure you have added

     Require all granted

but also make sure your DocumentRoot path is correct and you have included something like this for Xampp users:

DocumentRoot "C:/xampp/htdocs/zf2-tutorial/public"

to enable access

0
votes

Ok problem solved! It was SELinux forbidding access to those files so I simply did what it recommended me to do on bash:

1. /sbin/restorecon -v /var/www/html/zf2-tutorial/public/.htaccess 
2. setsebool -P httpd_read_user_content 1

But now I have a more serious problem! The browser shows "literaly" the content of index.php instead of loading the script itself. The browser window simply displays this as a text:

    <?php
/**
 * This makes our life easier when dealing with paths. Everything is relative
 * to the application root now.
 */
chdir(dirname(__DIR__));

// Setup autoloading
require 'init_autoloader.php';

// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();

Any idea of what's happening ? Thank you!

0
votes

Are you sure your Apache server is running correctly? If the apache server is down php files cannot be executed and are displayed as text