How To Install LAMP

how to install LAMPLAMP is an acronym which stands for Linux, Apache, MySQL and PHP. The letter P also stands for Perl and Python programming languages. LAMP is a free software stack which powers, primarily, web servers. Most GNU/Linux distributions bundle these packages in the install media and repositories. Let us take a look at how to install LAMP using Fedora. I will restrict the P in LAMP to PHP only for this article. Perl and Python fans, bear with me.

While installing Fedora you can choose to install "Web Sever" which contains these packages. You can install them later also. Let me walk you through the actual steps to get LAMP working on your computer. I assume you are running Fedora 8 on your computer.

1. Launch the terminal by clicking

Applications>System Tools>Terminal

2. Switch to super user mode. You will require the root password.

su -

3. Check if Apache HTTP Server is installed already

rpm -q httpd

If you see the package name httpd-x.x.x-x, Apache web server is already installed on your computer. If it is not you can install it using the yum command. We will discuss how to install it in a few moments.

4. Check if PHP and MySQL are installed already

rpm -q php 

If PHP is installed, you will see the package name on the screen. Otherwise the shell returns the prompt without any message. Similarly check if MySQL is installed.

rpm -q mysql 

5. Installing the necessary packages using yum

yum install httpd php php-pdo php-mysql php-gd mysql mysql-server 

The yum package management tool resolves dependencies and displays the packages that are available for installation with their version numbers, architectures and repository details. You can choose to say yes or no when it asks for your confirmation to proceed. If you choose yes, yum downloads the necessary packages and installs it for you. You can sit back and relax for a while until all the packages are installed on your computer. If some of the packages are already installed on your computer, yum skips them and downloads only the missing packages.

6. Starting the services: You must start the services to make use of them.

service mysqld start
service httpd start

7. You can set these services to start when your computer starts using the
chkconfig command.

chkconfig httpd on
chkconfig mysqld on

To print the list of services with the runlevel information type:

chkconfig --list 

Runlevel 5 is the technical name for graphical multiuser mode and runlevel 3 for command line multi user mode on Red Hat like systems. Check if mysqld and httpd are set to runlevel 3 and 5. Alternatively you can use the graphical tool ntsysv to start or stop services at system start-up.

ntsysv --level 5
ntsysv --level 3

PHP runs as an Apache HTTP server module. PHP starts when httpd starts.
8. Verifying LAMP installation: In your web browser address bar type http://localhost/ and hit the return key. If you see the Fedora test page you have done everything correctly. Pat on your back.

The default DocumentRoot is /var/www/html directory. Place your HTML and PHP scripts in /var/www/html directory and view them in action at http://localhost from your web browser. You can change the DocumentRoot and even run multiple websites simultaneously using name-based virtual hosts.

The phpinfo() function in the PHP scripting language is very useful and prints important information about the LAMP stack. Open a text editor and copy the below code and paste it.


Save the file as phpinfo.php in the /var/www/html directory. View it from the web browser by typing http://localhost/phpinfo.php.

By default MySQL's root password is set to blank. Connect to the local MySQL server using the MySQL client and change it immediately.

mysql -u root -p

The screen looks something like

[root@localhost test]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 60
Server version: 5.0.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

In the MySQL client(where you see mysql> before the blinking cursor), use the below SQL to change the root password.

SET PASSWORD FOR 'root'@'localhost' = password('newpassword');

9. Installing optional packages: There are many software tools available to make your life easier with LAMP. There are GUI tools available to mange MySQL server, databases, http server and many more. I have listed couple of them below

  1. phpMyAdmin to manage MySQL databases from the web browser. You can install phpMyAdmin by using yum
    yum install phpmyadmin

    Once you install phpMyAdmin you can access it by typing localhost/phpMyAdmin in your web browser.

  2. yum install system-config-httpd

Go ahead and build great applications on your LAMP stack. Feel free to use the forums to discuss it further. You may also post comments to this post.

Taxonomy upgrade extras: 


very easy step for lamp installation

Indeed, Sachin. Managing software packages on Linux systems is damn easy once you get the hang of it.

Much thanks for writing this up!

This tutorial was really helpful. Keep up the good work!

where to store cgi files and how to config the server to run those files????

Great Info!

thanks a lot!!

Thanks for the guiding to install the LAMP. Very easy to install.

yea i get an error when i get to step 5

ERROR MESSAGE: Error: Cannot retrieve repository metadata (repomd.xml) for repository: updates-newkey. Please verify its path and try again

hello I am a learner in the bigining level. Trying to install LAMP. In step 8 I am unable to change the password for mysql because i don't know how to give blank as my password to get (mysql>) prompt and therefore eventually unable to change the password for mysql server. My error is as follows:

[root@localhost ~]# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

please help me
thanks in advance

Excellent! Thanks for that!

Easy to follow, no waffle and works perfectly. Thanks.

Very good no nonsense document on LAMP installation. Thanks Much.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.