Best Apache VirtualHost configuration for PHP projects

Here is an example of an Apache VirtualHost config that provides your site with security through open_basedir and writes both a regular access log, as well as a PHP error log.

<VirtualHost *:80>
ServerName      example.com
ServerAlias     www.example.com

DocumentRoot    /var/www/html/example.com

php_admin_value open_basedir /var/www/html/example.com

CustomLog       /var/log/httpd/example.com-access.log common
ErrorLog        /var/log/httpd/example.com-error.log
</VirtualHost>

Note
In order for open_basedir to work with file uploads, you need to add the following to your php.ini configuration file:

upload_tmp_dir = /tmp

I’m always looking to improve this configuration – send me a comment if you have a better version!

One thought on “Best Apache VirtualHost configuration for PHP projects

Leave a Reply

Your email address will not be published. Required fields are marked *

Markdown is allowed in comments.