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>
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!

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

zend_extension=opcache.so
extension=apcu.so

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

opcache.max_accelerated_files=30000
opcache.memory_consumption=160
opcache.revalidate_freq=0

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.

Example

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

Source