Installing Apache with PHP
First you need to switch yourself to root:
Install packages for Apache and PHP:
apt-get install apache2-mpm-worker php5-fpm php5-cli
Then you need to install FastCGI module for Apache, but because this one is not available as binary (.deb) package in Rasbian repository, it is needed to be compiled from the source.
Install all dependencies first:
apt-get install debhelper cdbs apache2-threaded-dev dpatch libtool libapr1-dev
Add line to /etc/apt/sources.list to enable sourca packages repository:
deb-src http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
Then download libapache-mod-fastcgi source package, compile and then install from binary package:
apt-get -b source libapache-mod-fastcgi
dpkg -i libapache2-mod-fastcgi*.deb
Configuring Apache and PHP
Create directory /var/www/fastcgi and make sure it’s accessible for user www-data
chown www-data:www-data /var/www/fastcgi
Edit file /etc/apache2/mods-available/fastcgi.conf to look following way:
AddHandler fastcgi-script .fcgi
Alias /php5.fastcgi /var/www/fastcgi/php5.fastcgi
AddHandler php-script .php
FastCGIExternalServer /var/www/fastcgi/php5.fastcgi -socket /var/run/php5-fpm.sock
Action php-script /php5.fastcgi virtual
# This part is not necessary to get it to work, but it stops anything else from being
# accessed from it by mistake or maliciously.
Your server will work even without this module, but usage of APC can significantly speed up your PHP applications. I personally tried with default WordPress installation and with APC the response time was about 200 % faster. The APC (Alternative PHP Cache) is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code. It just mean that the PHP code isn’t parsed everytime is needed again and again, but instead it’s saved in cache and parsed only first time. Which is of course huge performance improvement.
The only drawback is that APC is not very well compatible with common php-cgi setup, because the cache is not shared among all spawned PHP processes. That’s reason I used mod_fastcgi and PHP-FPM instead.
Let’s install APC:
apt-get install php-apc
When needed you can optionally install MySQL server. Installation is straightforward:
apt-get install mysql-server mysql-client php5-mysql
apt-get install phpmyadmin
Restart Apache and PHP-FPM to reload new configuration:
service apache2 restart && service php5-fpm restart
Add your website source code to /var/www