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.
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
I also had to make the following changes…
- Changed the owner of
/var/log/apache2to www-data – I used the command
chown www-data:www-data apache2
- Created an empty file at
This was to fix a few errors I saw on my system – you may not have to do it.
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…
Start the Servers
First, turn on the MySQL database server…
Then, start the Apache Web Server…
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.
- How To Install Or Upgrade LAMP: Linux, Apache, MySQL and PHP Stack Using Yum
- Apache2 installation and configuration with php support
- Install and Configure Apache2 with PHP5 and SSL Support in Debian Etch
- Setting Up Your PHP Server Environment Using Linux, Apache, MySQL, and PHP
- Quick Linux Server w/ Apache+PHP+MySQL
- LAMP (Linux Apache Mysql PHP) Configuration and Installing in Debian
- HOWTO: Installing MySQL and Apache with PHP support on Linux
- How to install Apache2, PHP5, MySQL5 on RedHat
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.