Setting up a web server with Apache, PHP, and MySQL on any Debian-based system is really easy thanks to APT (Advanced Packaging Tool). Follow along and you’ll have a web server set up within fifteen minutes.


Install Apache

sudo apt-get install apache2

Enabling .htaccess overrides

.htaccess overrides are a common component of many web applications. To enable .htaccess overrides, first open /etc/apache2/sites-available/default with the text editor of your choice (e.g. sudo nano /etc/apache2/sites-available/default). Inside the <VirtualHost *:80> section, set AllowOverride to All.

Next, create a symbolic link to the rewrite module in the mods-enabled directory:

sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

Now restart Apache for the changes to take effect (see Starting and stopping the web server).

Install PHP

sudo apt-get install php5
sudo apt-get install libapache2-mod-php5

Note that the php5 package may already include libapache2-mod-php5, so the second command might not be required.

Install MySQL

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

Starting and stopping the web server

After installing everything, you should restart Apache to make sure it reads your updated configuration file. Simply use sudo apache2ctl graceful-stop to stop the server and sudo apache2ctl start to start it again. (It is good to get into the habit of doing a graceful-restart instead of a plain restart, as well as doing a graceful-stop instead of a regular stop.)

Optional Extras

Below is a list of useful tools and modules that I recommend installing. Remember to restart your web server after installing a new module.


phpMyAdmin is an in-browser MySQL administration interface written in PHP. Installing phpMyAdmin will require an extra 20MB of disk space, as it is dependant on several other packages.

sudo apt-get install phpmyadmin

Once phpMyAdmin is installed, open /etc/apache2/apache2.conf with the text editor of your choice (e.g. sudo nano /etc/apache2/apache2.conf) and add this line at the bottom of the file:

Include /etc/phpmyadmin/apache.conf


APC (Alternative PHP Cache) can provide significant performance boosts to PHP applications by optimising and caching PHP intermediate code. I highly recommend installing APC as it a great caching mechanism and will even be built into the PHP core as of version 5.4.

sudo apt-get install php-apc

The APC team have written a script which is useful for monitoring the cache and fine-tuning settings. Unfortunately the script isn’t downloaded when you install APC using apt-get, but you can get the script here.


cURL is a PHP library that allows you to communicate with different types of servers using many protocols including APTTP, HTTPS, FTP, telnet, LDAP, and more. cURL is especially useful for making API calls.

sudo apt-get install php5-curl


The GD library allows you to create and manipulate images in various formats including GIFPNGJPEGWBMP, and XPM. It is almost essential for any image processing like cropping and resizing.

sudo apt-get install php5-gd