≑ Menu

How To Install Or Upgrade LAMP: Linux, Apache, MySQL and PHP Stack Using Yum

LAMP Stack LogoPreviously we discussed about how to install Apache and PHP from source. Installing LAMP stack from source will give you full control to configure different parameters.

Installing LAMP stack using yum is very easy and takes only minutes. This is a good option for beginners who don’t feel comfortable installing from source. Also, Installing LAMP stack using yum is a good choice, if you want to keep things simple and just use the default configuration.

1. Install Apache using Yum

Apache
# rpm -qa | grep httpd

[Note: If the above command did not return anything,
          install apache as shown below]

# yum install httpd

Verify that Apache got installed successfully

# rpm -qa | grep -i http

httpd-tools-2.2.9-1.fc9.i386
httpd-2.2.9-1.fc9.i386

Enable httpd service to start automatically during system startup using chkconfig.Β  Start the Apache as shown below.

# chkconfig httpd on

# service httpd start
Starting httpd:                   [  OK  ]

2. Upgrade Apache using Yum

If you’ve selected web server package during Linux installation, Apache is already installed on your Linux. In which case, you can upgrade Apache to the latest version as shown below.

Check whether Apache is already installed.

# rpm -qa | grep -i http

httpd-tools-2.2.8-3.i386
httpd-2.2.8-3.i386
[Note: This indicates that Apache 2.2.8 version is installed already]

Check whether latest version of Apache is available for installation using yum.

# yum check-update httpd

Loaded plugins: refresh-packagekit
httpd.i386      2.2.9-1.fc9       updates
[Note: This indicates that the latest Apache version 2.2.9
       is available for upgrade]

Upgrade Apache to latest version using yum.

# yum update httpd

Output of the yum update httpd command:

Loaded plugins: refresh-packagekit
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.i386 0:2.2.9-1.fc9 set to be updated
--> Processing Dependency: httpd-tools = 2.2.9-1.fc9 for package: httpd
--> Running transaction check
---> Package httpd-tools.i386 0:2.2.9-1.fc9 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Updating:
httpd                   i386       2.2.9-1.fc9      updates           975 k
httpd-tools             i386       2.2.9-1.fc9      updates            69 k

Transaction Summary
=============================================================================
Install      0 Package(s)
Update       2 Package(s)
Remove       0 Package(s)

Total download size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): httpd-tools-2.2.9-1.fc9.i386.rpm                  |  69 kB     00:00
(2/2): httpd-2.2.9-1.fc9.i386.rpm                        | 975 kB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Updating       : httpd-tools                                       [1/4]
Updating       : httpd                                             [2/4]
Cleanup        : httpd                                             [3/4]
Cleanup        : httpd-tools                                       [4/4]

Updated: httpd.i386 0:2.2.9-1.fc9 httpd-tools.i386 0:2.2.9-1.fc9
Complete!

Verify whether the Apache got upgraded successfully.

# rpm -qa | grep -i http

httpd-tools-2.2.9-1.fc9.i386
httpd-2.2.9-1.fc9.i386
[Note: This indicates that Apache was upgraded to 2.2.9 successfully]

3. Install MySQL using Yum

MySQL Logo

Yum is very smart to identify all the dependencies and install those automatically. For example, while installing mysql-server using yum, it also automatically installs the depended mysql-libs, perl-DBI, mysql, perl-DBD-MySQL packages as shown below.

# yum install mysql-server

Output of yum install mysql-server command:

Loaded plugins: refresh-packagekit
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package mysql-server.i386 0:5.0.51a-1.fc9 set to be updated
--> Processing Dependency: libmysqlclient_r.so.15 for mysql-server
--> Processing Dependency: libmysqlclient.so.15 for mysql-server
--> Processing Dependency: perl-DBI for package: mysql-server
--> Processing Dependency: mysql = 5.0.51a-1.fc9 for package: mysql-server
--> Processing Dependency: libmysqlclient.so.15 for package: mysql-server
--> Processing Dependency: perl(DBI) for package: mysql-server
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server
--> Processing Dependency: libmysqlclient_r.so.15 for package: mysql-server
--> Running transaction check
---> Package mysql.i386 0:5.0.51a-1.fc9 set to be updated
---> Package mysql-libs.i386 0:5.0.51a-1.fc9 set to be updated
---> Package perl-DBD-MySQL.i386 0:4.005-8.fc9 set to be updated
---> Package perl-DBI.i386 0:1.607-1.fc9 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
mysql-server            i386       5.0.51a-1.fc9    fedora            9.8 M
Installing for dependencies:
mysql                   i386       5.0.51a-1.fc9    fedora            2.9 M
mysql-libs              i386       5.0.51a-1.fc9    fedora            1.5 M
perl-DBD-MySQL          i386       4.005-8.fc9      fedora            165 k
perl-DBI                i386       1.607-1.fc9      updates           776 k

Transaction Summary
=============================================================================
Install      5 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 15 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): perl-DBD-MySQL-4.005-8.fc9.i386.rpm           | 165 kB     00:00
(2/5): perl-DBI-1.607-1.fc9.i386.rpm                 | 776 kB     00:00
(3/5): mysql-libs-5.0.51a-1.fc9.i386.rpm             | 1.5 MB     00:00
(4/5): mysql-5.0.51a-1.fc9.i386.rpm                  | 2.9 MB     00:00
(5/5): mysql-server-5.0.51a-1.fc9.i386.rpm           | 9.8 MB     00:01
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing     : mysql-libs                                        [1/5]
Installing     : perl-DBI                                          [2/5]
Installing     : mysql                                             [3/5]
Installing     : perl-DBD-MySQL                                    [4/5]
Installing     : mysql-server                                      [5/5]

Installed: mysql-server.i386 0:5.0.51a-1.fc9
Dependency Installed:
  mysql.i386 0:5.0.51a-1.fc9 mysql-libs.i386 0:5.0.51a-1.fc9
  perl-DBD-MySQL.i386 0:4.005-8.fc9 perl-DBI.i386 0:1.607-1.fc9
Complete!

Verify whether MySQL got installed properly.

# rpm -qa | grep -i mysql

php-mysql-5.2.6-2.fc9.i386
mysql-libs-5.0.51a-1.fc9.i386
mysql-server-5.0.51a-1.fc9.i386
perl-DBD-MySQL-4.005-8.fc9.i386
mysql-5.0.51a-1.fc9.i386

# mysql -V

mysql  Ver 14.12 Distrib 5.0.51a, for redhat-linux-gnu (i386) using readline 5.0

Configure MySQL to start automatically during system startup.

# chkconfig mysqld on

Start MySQL service.

# service mysqld start

The first time when you start mysqld, it will give additional information message indicating to perform post-install configuration as shown below.

Initializing MySQL database:
Installing MySQL system tables... OK
Filling help tables... OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h dev-db password 'new-password'

Alternatively you can run: /usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
highly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com

Starting MySQL:                                            [  OK  ]

4. Perform MySQL post-installation activities

After the mysql installation, you can login to mysql root account without providing any password as shown below.

# mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.51a Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

To fix this problem, you need to assign a password to mysql root account as shown below. Execute mysql_secure_installation script, which performs the following activities:

  • Assign the root password
  • Remove the anonymous user
  • Disallow root login from remote machines
  • Remove the default sample test database
# /usr/bin/mysql_secure_installation

Output of mysql_secure_installation script:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: [Note: Enter the mysql root password here]
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
... Success!

Cleaning up...
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!

Verify the MySQL post-install activities:

# mysql -u root

ERROR 1045 (28000):Access denied for user 'root'@'localhost'(using password:NO)
[Note: root access without password is denied]

# mysql -u root -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.0.51a Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)
[Note: test database is removed]

5. Upgrade MySQL using Yum

Check whether MySQL is already installed.

# rpm -qa | grep -i mysql

Check whether a latest version of MySQL is available for installation using yum.

# yum check-update mysql-server

Upgrade MySQL to latest version using yum.

# yum update mysql-server

6. Install PHP using Yum

PHP Logo
# yum install php

Output of yum install php:

Loaded plugins: refresh-packagekit
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package php.i386 0:5.2.6-2.fc9 set to be updated
--> Processing Dependency: php-common = 5.2.6-2.fc9 for package: php
--> Processing Dependency: php-cli = 5.2.6-2.fc9 for package: php
--> Running transaction check
---> Package php-common.i386 0:5.2.6-2.fc9 set to be updated
---> Package php-cli.i386 0:5.2.6-2.fc9 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved
=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
php                     i386       5.2.6-2.fc9      updates           1.2 M
Installing for dependencies:
php-cli                 i386       5.2.6-2.fc9      updates           2.3 M
php-common              i386       5.2.6-2.fc9      updates           228 k

Transaction Summary
=============================================================================
Install      3 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 3.8 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): php-common-5.2.6-2.fc9.i386.rpm  | 228 kB     00:00
(2/3): php-5.2.6-2.fc9.i386.rpm         | 1.2 MB     00:00
(3/3): php-cli-5.2.6-2.fc9.i386.rpm     | 2.3 MB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing     : php-common     [1/3]
Installing     : php-cli        [2/3]
Installing     : php            [3/3]

Installed: php.i386 0:5.2.6-2.fc9
Dependency Installed: php-cli.i386 0:5.2.6-2.fc9 php-common.i386 0:5.2.6-2.fc9
Complete!

Verify that php got installed successfully.

# rpm -qa | grep -i php

php-cli-5.2.6-2.fc9.i386
php-5.2.6-2.fc9.i386
php-common-5.2.6-2.fc9.i386

Install MySQL module for PHP.

# yum search php-mysql

Loaded plugins: refresh-packagekit
=========== Matched: php-mysql =============
php-mysql.i386 : A module for PHP applications that use MySQL databases

# yum install php-mysql

Output of yum install php-mysql:

Loaded plugins: refresh-packagekit
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package php-mysql.i386 0:5.2.6-2.fc9 set to be updated
--> Processing Dependency: php-pdo for package: php-mysql
--> Running transaction check
---> Package php-pdo.i386 0:5.2.6-2.fc9 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
php-mysql               i386       5.2.6-2.fc9      updates            81 k
Installing for dependencies:
php-pdo                 i386       5.2.6-2.fc9      updates            62 k

Transaction Summary
=============================================================================
Install      2 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 143 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): php-pdo-5.2.6-2.fc9.i386.rpm     |  62 kB     00:00
(2/2): php-mysql-5.2.6-2.fc9.i386.rpm   |  81 kB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing     : php-pdo                [1/2]
Installing     : php-mysql              [2/2]

Installed: php-mysql.i386 0:5.2.6-2.fc9
Dependency Installed: php-pdo.i386 0:5.2.6-2.fc9
Complete!

If you need additional PHP modules, install them using yum as shown below.

# yum install php-common php-mbstring php-mcrypt php-devel php-xml php-gd

7. Upgrade PHP using Yum

Check whether PHP is installed.

# rpm -qa | grep -i php

Check whether a latest version of PHP is available for installation using yum.

# yum check-update php

Upgrade PHP to the latest version using yum.

# yum update php

Upgrade any additional PHP modules that you’ve installed using yum.

# yum check-update php-common php-mbstring php-mcrypt php-devel php-xml php-gd

# yum update php-common php-mbstring php-mcrypt php-devel php-xml php-gd

Verify the PHP installation by creating a test.php file as shown below.

# cat /var/www/html/test.php

<? phpinfo(); ?>

Invoke the test.php from the browser http://{lamp-server-ip}/test.php , which will display all PHP configuration information and the installed modules.

If you liked this article, please bookmark it on del.icio.us and Stumble it.

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Robin September 15, 2008, 5:16 am

    Thanks for the great article, I’ve been writing a tutorial site for MySQL and PHP development, and the hardest bit for people seems to be actually installing LAMP!

  • Ajith Edassery September 16, 2008, 2:05 pm

    Ramesh,
    Thanks for the big LAMP upgrade story πŸ™‚ No matter, how many times I have done it, I still goof up… One thing that I finally figured out is that, carefully going through the phpinfo() dump helps a lot to debug the issue…

    Cheers,
    Ajith

  • Binny V A September 16, 2008, 11:41 pm

    Nice timing – I just wrote an article on how to Install LAMP using apt(Debian, Ubuntu). Now I have the YUM version as well.

    Yes, I have updated the post with a link to your page πŸ™‚

  • joseph September 20, 2008, 6:24 am

    I issued a simpe testing yesterday here: http://admon.org/node/87, It’s not suggested to run the default configured apache without any optimization for high load sites, you may frequently face SIGNUP issue with abnormal quitting

  • Roshan Bhattarai September 20, 2008, 10:10 am

    Though I’ve been using WAMP ….this is really a great tutorial and will become handy when I start using Linux…

  • jaesisha September 28, 2008, 12:49 am

    Good concise guide.

  • David October 8, 2008, 2:48 pm

    Perfect, just walked through this with a fresh Fedora 9 install and it went absolutely smoothly. Very nice instruction set.

  • Safdar Imam October 31, 2008, 8:14 am

    Simply amazing stuff – I thank you for the nice, clear and concise information to help every developer.

    Nice work.

    Sincere thanks.

  • billy November 17, 2008, 12:19 am

    thanks for the guide πŸ™‚
    It doesn’t mind if the right of the folder www is root ?

    thanks

  • Anonymous February 19, 2009, 5:22 am

    Great Work Dude πŸ™‚

  • Bob Schoening May 19, 2009, 9:53 pm

    Very nice site. You helped me a lot and I appreciate it. Thanks much.

  • Balwinder Singh July 10, 2009, 1:39 am

    this is very good material for everyone to using LAMP. i m very much appreciate to THE GEEK STUFF. m highly thankfull to THE GEEK STUFF. which provied us to great material for linux use…..!!

    nobody was born with linux knowledge……
    enjoy with free linux…..!!

    thanks n regarding
    Balwinder Singh
    MCA,RHCE

  • mobquest September 3, 2009, 7:03 am

    Hi,

    Thankyou for providing such a useful document on installation of LAMP. Could you please suggest steps for installation of phpmyadmin for fedora core 9.

  • bruno November 28, 2009, 3:26 pm

    Thanks a lot.

    I’d tried another tutorial to install AMP but it doesn’t work.

    Yours work fine

    Thanks again

  • Olsi February 10, 2010, 4:23 am

    greatful , thanks a lot

  • Anil Rathod January 10, 2011, 3:38 am

    Thanks for such a great article.

    Tahnks a lot

  • Paul S February 20, 2011, 5:32 pm

    Great! This is the smoothest install I have ever done!
    Highly recommend.

  • bb October 2, 2011, 5:48 am

    HaHa…The best advice is to give up RedHat… poor guys.

    If you install AMP from yum, you only got the out-dated packages with security holes.
    If you install the packages from the source, your system will be out of control since more and more packages and libs scattered in your system.

    Go for Debian, Ubuntu or FreeBSD, you can have your coffee and sit to watch the Redhat poor guys.

  • Anand Kumar December 8, 2011, 2:35 am

    Its a very good blog. its a awesome steps as given to help me for upgrading my server.

  • Paul April 9, 2012, 6:13 am

    Only one VITAL part missing from the end of your tutorial, and that is you need to make sure you restart the Apache web-server after you’ve installed PHP / Any module that will run on your httpd server.

    To do this it’s just one more terminal command:
    service httpd restart

    This will restart apache/httpd and when you visit http://localhost/test.php your phpinfo() will output the correct details.

    Hope this helps,
    Paul
    e-swoosh Limited

  • Nisha June 19, 2012, 2:35 am

    This Article is amazingly great!!
    Good work Man!!U Rock!!

  • Doug August 29, 2013, 9:40 pm

    I followed all of your instructions and everything worked according to script – I think. When I attempt to view the test.php file in my browser is does not display. But when I view the source code for the web page everything is correct. I also saw and followed the instructions above to restart the Apache service with the “service restart httpd” command; no change.

  • John February 5, 2014, 4:26 pm

    Hello and thank you for all your great articles, they have always been a big help. I am seeing the same problem as Doug:
    “I followed all of your instructions and everything worked according to script – I think. When I attempt to view the test.php file in my browser is does not display. But when I view the source code for the web page everything is correct. I also saw and followed the instructions above to restart the Apache service with the β€œservice restart httpd” command; no change.”

    I am installing on a CentOS 6.5 system.
    Thank you.

  • Farrukh October 3, 2014, 9:55 am

    Has anyone done WIKI server migration. I am working on this project, source compiled LAMP stack, however having an issue with installing the Wiki Media. I would really appreciate any help.

  • olivedev December 6, 2016, 8:12 am

    Nice tutorial for simple linux, but is the process for distro same? I was wondering if I can follow this tutorial to install PHP LAMP on Debian. Currently, my website is build with PHP but it was installed on Debian using Cloudways platform that automates the process.

  • Ray March 14, 2019, 9:29 am

    On Ubuntu is super easy:
    sudo apt-get update
    sudo apt-get install tasksel
    sudo tasksel install lamp-server