Category Archives: Apache

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>

DocumentRoot    /var/www/html/

php_admin_value open_basedir /var/www/html/

CustomLog       /var/log/httpd/ common
ErrorLog        /var/log/httpd/

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!

Debian LAMP stack in one command

Start out with the basics – Apache, MySQL and PHP + extensions

apt-get install mysql-server mysql-client apache2 php5 php5-cli libapache2-mod-php5 php5-mysql php5-curl php5-gd php-pear php5-imagick php5-mcrypt php5-memcache php5-mhash php5-sqlite php5-xmlrpc php5-xsl php5-json php5-dev libpcre3-dev

I recommend using this on Debian Jessie. That way you get a bleeding edge version of PHP (5.5.8 as of right now)

OpCode cache and APCu (Optional)

pecl install ZendOpcache-beta
pecl install apcu-beta

Add the following to /etc/php5/apache2/php.ini

Configure Opcache by adding this to /etc/php5/apache2/php.ini


Restart apache. The extensions should be available and configured. (You can verify this via phpinfo(); )

Useful tools (Optional)

apt-get install htop vim

Multiple paths in open_basedir

It is possible to separate paths with a colon when setting open_basedir folders.

This is useful to give access to the /tmp folder, which many CMS and frameworks use per default to store temporary files such as uploads.


php_admin_value     open_basedir /var/www/html/