Wednesday, September 21, 2022

[FIXED] Why am I getting the wrong document root?

Issue

I am working through this tutorial- https://docs.zendframework.com/tutorials/getting-started/skeleton-application/

In trying to get it setup on an Apache local server I have used this code-

<VirtualHost *:80>
ServerName zf-tutorial.localhost
DocumentRoot /var/www/html/skeleton-application/public
SetEnv APPLICATION_ENV "development"
<Directory /var/www/html/skeleton-application/public>
    DirectoryIndex index.php
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

When I try and go to http://zf-tutorial.localhost I see a directory listing that looks like this-

https://imgur.com/a/zrUuXrf

This url- http://zf-tutorial.localhost/skeleton-application/public/ actually displays the correct index.php file.

How do I get http://zf-tutorial.localhost to display the index.php file?


Solution

I like to have everything sorted and connected well. I care about directory names to match configuration files and names so I will leave you here how I would do that.

  1. Install your aplication in /var/www/zf-tutorial.localhost
  2. cd /etc/apache2/sites-available
  3. sudo cp 000-default.conf zf-tutorial.localhost.conf
  4. Open that file and change ServerName to zf-tutorial.localhost
  5. Change DocumentRoot to /var/www/zf-tutorial.localhost/public
  6. You can add additional parameters/settings like SetEnv APPLICATION_ENV "development"
  7. You can change access log and error log for easier debugging and troubleshooting. For me it would be ${APACHE_LOG_DIR}/zf-tutorial.localhost.access.log and ${APACHE_LOG_DIR}/zf-tutorial.localhost.error.log
  8. Save and close
  9. sudo a2ensite zf-tutorial.localhost.conf
  10. sudo service apache2 reload

Here you should be ready to go. With this, you don't need that separate VirtualHost rule up there since you set it now in separated configuration file.



Answered By - Tpojka
Answer Checked By - Marie Seifert (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.