Installing LAMP(Apache Web Server/PHP/MySQL) in Debian/Ubuntu

LAMP - Linux, Apache, MySQL, PHP

Installing the LAMP environment on a Linux system is easy if you are comfortable with using the native package management software. If you on a Red Hat/Fedora/CentOS system, that will be yum – and for Debian/Ubuntu systems, that will be apt. This tutorial shows you how to install Apache 2, PHP 5 and MySQL 5 in Debian using apt.

Before installation, a few points to remember. These instruction are not for a production environment – this is for a development environment. To install the software, you need root access. You can get that using this command…

su -
[Enter root password]

Installing Apache 2

Use this command to install Apache 2.

apt-get install apache2

Make sure you specify ‘apache2’ – or else, apache 1.3 will be installed.

PHP Logo

Install PHP 5

Now, install the PHP 5 packages…

apt-get install libapache2-mod-php5 php5-cli php5-common php5-cgi

No go to the folder /etc/apache2/sites-enabled/ and edit the file in that directory(usually 000-default). Find the line that says
RedirectMatch ^/$ /apache2-default/
and remove it.

Now your document root is /var/www/ – place all your HTML documents and scripts in this folder. If you want to make some other configuration changes, edit the configuration files at /etc/apache2/apache2.conf

I also had to make the following changes…

  • Changed the owner of /var/log/apache2 to www-data – I used the command chown www-data:www-data apache2
  • Created an empty file at /etc/apache2/httpd.conf

This was to fix a few errors I saw on my system – you may not have to do it.

Install MySQL

This is the command to install MySQL server, its client and PHP’s MySQL libraries…

apt-get install mysql-client mysql-common mysql-server php5-mysql

Finally, Install the other packages you need as well

apt-get install php5-sqlite php5-gd ...

Testing the System

Go to your document root(/var/www) and create a php files called ‘info.php’ and put this code inside that…

<?php
phpinfo();

Start the Servers

First, turn on the MySQL database server…

/etc/init.d/mysql start

Then, start the Apache Web Server…

/etc/init.d/apache2 start

Now fire up a browser and go to localhost – you should see a file listing page with a ‘info.php’ in the list. Click on that link – if you see a PHP information page, your web server is setup correctly.

To make sure MySQL-PHP connection is working, install phpMyAdmin – or write a database connection script – whatever is easier for you.

Related Links

Shameless Plug: If you are a Linux user, you may want to check out my Linux Blog – LinDesk – its about Linux on the Desktop – Articles, Application Reviews and Tutorials about many aspects of Linux included configuration and scripting.

1 Comment

3 Trackbacks / Pingbacks

  1. Compile and Install a LAMP(Linux/Apache/MySQL/PHP) Server from Source | Bin-Blog
  2. Installing lighttpd Web Server in Linux with PHP and MySQL | Bin-Blog
  3. Yo Super » Install Apache2 + PHP5 + MySQL5 on Debian

Comments are closed.