How to install Apache2, PHP5 with MySQL (LAMP) support on Linux

LAMP is short for Linux, Apache, MySQL, and PHP. On this tutorial I’ll show you how to install an Apache2 web server with PHP5 and MYSQL5 support.

I will be using the hostname “localhost” with an IP address of “”. The real settings differ and you must supply them with your own setting.

1. First we update the server software. Do this now:

apt-get update

apt-get upgrade

2. After this we can now install the MySQL Server:

apt-get install mysql-server mysql-client

You will be asked to provide a password for the MySQL root user – this password is valid for the user [email protected], so we don’t have to specify a MySQL root password manually later on:

New password for the MySQL “root” user: yourrootsqlpassword
Repeat password for the MySQL “root” user: yourrootsqlpassword

The default setting of MySQL is somewhat memory hungry. You can change it to the setting below, thereby saving you about 25% – 50% memory:

nano /etc/mysql/my.cnf

Locate these settings:

key_buffer = 16K
max_allowed_packet = 1M
thread_stack = 64K
thread_cache_size = 8

3. Apache2 is available as a Debian package, therefore we can install it easily like this:

apt-get install apache2

Point your browser to

and you should see the Apache2 placeholder page. Apache2’s default document root is /var/www , and the configuration file is /etc/apache2/apache2.conf

4. Install PHP5 and the Apache PHP5 module (libapache2-mod-php5) as follows. To get MySQL support in PHP, we can install the php5-mysql package. It’s a good idea to install some other PHP5 modules as well as you might need them for your applications.

apt-get install php5 libapache2-mod-php5 php5-common php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-suhosin

5. You will need to restart the Apache2 and MySQL server:

/etc/init.d/mysql restart
/etc/init.d/apache2 restart

6. We will now create a small PHP file (info.php) in that directory and call it in a browser. The document root of the default web site is /var/www. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

nano /var/www/phpinfo.php

Enter this:

< ?php

Now we load the file in a browser and you will see that the server is up and running.

7. Install a web-based MySQL manager. phpMyAdmin is a web interface which you can manage your MySQL databases easily:

apt-get install phpmyadmin

You will see the following prompt:

Web server to reconfigure automatically: [x] apache2

You can access phpMyAdmin under

You’re done!

Leave a Reply

Your email address will not be published. Required fields are marked *