Setting up a development Apache 2 web-server on Ubuntu 12.10 or 13.04

Submitted by Andy on Fri, 31/05/2013 - 19:24

The most common type of web-server available is based on the LAMP (Linux, Apache, MySQL, PHP) bundle, so in this tutorial I will cover creating a web development server based on these components. Another common component is phpMyAdmin which is a web base MySQL administration tool so we are going to include it in our tutorial.

This tutorial guides you through installing Apache 2, MySQL 5, PHP 5 and phpMyAdmin for use as a development web-server on Ubuntu Linux. All these packages are available in the Ubuntu software centre at the versions we require.

To make a fully secure publicly available web-server it would require many other steps that aren't always necessary when developing websites.

If you want to use the XAMPP installation instead please see my Installing XAMPP on Ubuntu tutorial.

Step 1 - Updating the system

Open the terminal from the launcher or by pressing Ctrl-Alt-t.

Before we start installing anything you need to check for updates by typing:

sudo apt-get update

You should enter your password when prompted. If there are any updates found you should agree to update and let them install before continuing on with the installation.

Step 2 - Installing the Apache 2 web server and PHP

Now that the system is up to date we can install the Apache 2 web server by typing

sudo apt-get install apache2

Next we will install PHP by typing

sudo apt-get install php5

If asked asked to confirm the installation press Y  or Enter to proceed with the installation.

As these instructions are for a development web-server we will now install the Xdebug PHP 5 debugging library (this can be skipped if you just want to host PHP websites)

sudo apt-get install php5-xdebug

Step 3 - Installing the MySQL Database server

Now we need to install the MySQL Database server that we will be using to provide data for our websites by typing:

sudo apt-get install mysql-server

You may be asked to confirm the installation so press Y or Enter if needed to proceed with the installation.

You will be asked for a password for the root (administrator) user.

MySQL Password Prompt

You will then be prompted to repeat the password that you just entered to confirm that it's correct.

MySQL Password Confirmation

Now to allow PHP to work with MySQL we need to the php5-mysql package by typing:

sudo apt-get install php5-mysql

Step 4 - Testing the Installation


Test the web-server installation in Firefox by typing localhost in the address bar.

Step 5 - Installing the MySQL administration system (optional)

To help us create, manage and delete MySQL databases we are goin to install the web based phpMyAdmin database administration system.

To install phpMyAdmin type the following in the terminal:

sudo apt-get install phpmyadmin

If asked asked to confirm the installation press Y  or Enter to proceed with the installation. Once downloaded you will be presented with a series of dialogs to configure phpMyAdmin with your database server and web server.

The first dialog asks what type of web server you are using. You will see a red box showing the highlighted option. The currently selected option will have beside it.

First phpMyAdmin set-up dialog to select the web-server type.

On the screen above make sure that the apache2 has the red highlight (use the arrow keys to select it if required) and press Space to select it (you will see a *) then press Enter.

The dialog will allow you to create the dbconfig-common database used by phpMyAdmin.

Second phpMyAdmin set-up dialog to configure the database.

Make sure that the Yes option is highlighted and press Enter to configure the database.

The next dialog requests the database administrator password to create and manage databases. You need to type the password for the administrative (root) account for the database server then press Enter. The password will be obscured.

   Third phpMyAdmin set-up dialog to enter the root database password.

For the next dialog you can safely select <OK> (by using the Tab key) then press Enter to generate a random database password for the phpmyadmin user.

Fourth phpMAdmin set-up dialog to configure the database password.

Next we will test the php, mysql and phpmyadmin installations by typing localhost/phpmyadmin in the Firefox address bar.

Testing PHP, MySQL and phpMyAdmin

The user name is root and the password is the database server root password. If you can login then PHP, MySQL and phpMyAdmin are correctly installed.

Final Steps

To make the new web server usable we will set-up a websites folder, set-up virtual hosts and enable some required Apache modules.