How-To Install Apache2, PHP5 and MySQL.

Posted: 23 December, 2012 in Computers, Linux, Web
Tags: , , , , , , , ,

Creating a Web server is a very useful thing, most developers have their own local server when developing. You can also use this server as a personal Web server in your own home. This tutorial created under Ubuntu 12.10, but probably works on other Linux distributions.

We will explain how to install and set up Apache2, PHP and MySQL.

Install Apache:

It is simple as this command:

sudo apt-get install apache2

It will start automatically, you can check it browsing your http://localhost , should look like this:


Here you go, you Apache server is installed.

Install PHP5

Again as simple as one command:

sudo apt-get install libapache2-mod-php5 php5

This command with install PHP5 and the libraries to link it with Apache, now you need to restart Apache in order to activate this libraries:

sudo etc/init.d/apache2 restart

To test it out, create a file called test.php in your Web directory

sudo nano /var/www/test.php

And simply add this call to a PHP function, it will test if the PHP interpreter is working.

<?php phpinfo(); ?>

It should look like this:testphp
You can inspect your options and if you want to change anything, your php location is here:

sudo gedit /etc/php5/apache2/php.ini

Install MySQL

Now its time to install MySQL server, also the links to Apache and PHP. Again with one command:

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

In the installation, MySQL will ask you for a password, you shouldn’t leave this blank, its a potential security vulnerability.
Log into MySQL monitor and check if works properly:

mysql -u root -p
<Enter Password>
show databases;

It should look something like this:
database mysql
Now everything is set up!.
You may want the web manager for MySQL, is called PHPMyAdmin, and u can install it like this:

sudo apt-get install phpmyadmin

You can access to this tool via: http://localhost/phpmyadmin
Note: If you get a 404 error upon visiting http://localhost/phpmyadmin: You will need to configure apache2.conf to work with PHPMyAdmin including this line at the bottom of the Apache configuration file:

echo "Include /etc/phpmyadmin/apache.conf"|sudo tee -a /etc/apache2/apache2.conf

Making it accessible from Internet

To make your server being accessible from Internet, you must port forward the port 80 to your computer in your router, you can check how to do this in this page: How to port-forward.

You maybe need to allow access from outside, also configure the port you want to forward. You can do that in the file: /etc/apache2/ports.conf


It is so easy to create a Web Server in Linux with PHP and MySQL, you only need these 3 programs and few easy steps to set them up. Of course there are programs like XAMPP that install everything at once, but now you know which programs you have installed to run the minimum server configuration.

Any question? just ask in the comments 🙂

@VIA: Jeremy Morgan.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s