How to Install Apache, PHP and MySQL on CentOS 6.2

by skytech on May 16, 2012

CentOS 6.2

Install Apache, PHP and MySQL on centOS 6.2

In this post, i will share with you on how to install Apache Httpd, PHP and MySQL on linux CentOS 6.2 server. All these steps has been tested on CentOS 6.2. Assume that you have installed minimal installation type CentOS 6.2 and has setup your own local yum repository. You can use internet CentOS yum repository instead if you have direct internet connection to your server.

How to Setup Local Yum Repository from CD-ROM/DVD-ROM image on CentOS 6.2

1.0 How to Install Httpd on CentOS 6.2

Apache httpd is one of the most popular web servers and has a lot of features that make it very extensible and useful for many different types of websites.

[root@centos6 ~]# yum install httpd
Loaded plugins: fastestmirror
Determining fastest mirrors
CentOS6.2-Repository                                                        | 1.3 kB     00:00 ...
CentOS6.2-Repository/primary                                                | 1.2 MB     00:00 ...
CentOS6.2-Repository                                                                     3042/3042
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.i686 0:2.2.15-15.el6.centos will be installed
--> Processing Dependency: httpd-tools = 2.2.15-15.el6.centos for package: httpd-2.2.15-15.el6.centos.i686
--> Processing Dependency: libaprutil-1.so.0 for package: httpd-2.2.15-15.el6.centos.i686
--> Processing Dependency: libapr-1.so.0 for package: httpd-2.2.15-15.el6.centos.i686
--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-15.el6.centos.i686
--> Processing Dependency: /etc/mime.types for package: httpd-2.2.15-15.el6.centos.i686
--> Running transaction check
---> Package apr.i686 0:1.3.9-3.el6_1.2 will be installed
---> Package apr-util.i686 0:1.3.9-3.el6_0.1 will be installed
---> Package apr-util-ldap.i686 0:1.3.9-3.el6_0.1 will be installed
---> Package httpd-tools.i686 0:2.2.15-15.el6.centos will be installed
---> Package mailcap.noarch 0:2.1.31-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================
 Package              Arch          Version                      Repository                   Size
===================================================================================================
Installing:
 httpd                i686          2.2.15-15.el6.centos         CentOS6.2-Repository        818 k
Installing for dependencies:
 apr                  i686          1.3.9-3.el6_1.2              CentOS6.2-Repository        129 k
 apr-util             i686          1.3.9-3.el6_0.1              CentOS6.2-Repository         89 k
 apr-util-ldap        i686          1.3.9-3.el6_0.1              CentOS6.2-Repository         15 k
 httpd-tools          i686          2.2.15-15.el6.centos         CentOS6.2-Repository         70 k
 mailcap              noarch        2.1.31-2.el6                 CentOS6.2-Repository         27 k

Transaction Summary
===================================================================================================
Install       6 Package(s)

Total download size: 1.1 M
Installed size: 3.4 M
Is this ok [y/N]: y
Downloading Packages:
---------------------------------------------------------------------------------------------------
Total                                                              3.8 MB/s | 1.1 MB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : mailcap-2.1.31-2.el6.noarch                                                     1/6
  Installing : apr-1.3.9-3.el6_1.2.i686                                                        2/6
  Installing : apr-util-1.3.9-3.el6_0.1.i686                                                   3/6
  Installing : httpd-tools-2.2.15-15.el6.centos.i686                                           4/6
  Installing : apr-util-ldap-1.3.9-3.el6_0.1.i686                                              5/6
  Installing : httpd-2.2.15-15.el6.centos.i686                                                 6/6

Installed:
  httpd.i686 0:2.2.15-15.el6.centos

Dependency Installed:
  apr.i686 0:1.3.9-3.el6_1.2                     apr-util.i686 0:1.3.9-3.el6_0.1
  apr-util-ldap.i686 0:1.3.9-3.el6_0.1           httpd-tools.i686 0:2.2.15-15.el6.centos
  mailcap.noarch 0:2.1.31-2.el6

Complete!

2.0 How to Install php on CentOS 6.2

Next we proceed to Install the php packages on CentOS 6.2.

Simply run the following command :

[root@centos6 ~]# yum install php*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
CentOS6.2-Repository                                                            | 1.3 kB     00:00 ...
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php.i686 0:5.3.3-3.el6_1.3 will be installed
---> Package php-cli.i686 0:5.3.3-3.el6_1.3 will be installed
--> Processing Dependency: libedit.so.0 for package: php-cli-5.3.3-3.el6_1.3.i686
---> Package php-common.i686 0:5.3.3-3.el6_1.3 will be installed
---> Package php-gd.i686 0:5.3.3-3.el6_1.3 will be installed
--> Processing Dependency: libpng12.so.0(PNG12_0) for package: php-gd-5.3.3-3.el6_1.3.i686
--> Processing Dependency: libpng12.so.0 for package: php-gd-5.3.3-3.el6_1.3.i686
--> Processing Dependency: libjpeg.so.62 for package: php-gd-5.3.3-3.el6_1.3.i686
--> Processing Dependency: libfreetype.so.6 for package: php-gd-5.3.3-3.el6_1.3.i686
--> Processing Dependency: libXpm.so.4 for package: php-gd-5.3.3-3.el6_1.3.i686
--> Processing Dependency: libX11.so.6 for package: php-gd-5.3.3-3.el6_1.3.i686
---> Package php-ldap.i686 0:5.3.3-3.el6_1.3 will be installed
---> Package php-mysql.i686 0:5.3.3-3.el6_1.3 will be installed
---> Package php-odbc.i686 0:5.3.3-3.el6_1.3 will be installed
--> Processing Dependency: libodbc.so.2 for package: php-odbc-5.3.3-3.el6_1.3.i686
---> Package php-pdo.i686 0:5.3.3-3.el6_1.3 will be installed
---> Package php-pear.noarch 1:1.9.4-4.el6 will be installed
---> Package php-pecl-apc.i686 0:3.1.3p1-1.2.el6.1 will be installed
---> Package php-pecl-memcache.i686 0:3.0.5-3.el6 will be installed
---> Package php-pgsql.i686 0:5.3.3-3.el6_1.3 will be installed
--> Processing Dependency: libpq.so.5 for package: php-pgsql-5.3.3-3.el6_1.3.i686
---> Package php-soap.i686 0:5.3.3-3.el6_1.3 will be installed
---> Package php-xml.i686 0:5.3.3-3.el6_1.3 will be installed
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.24) for package: php-xml-5.3.3-3.el6_1.3.i686
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.18) for package: php-xml-5.3.3-3.el6_1.3.i686
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.13) for package: php-xml-5.3.3-3.el6_1.3.i686
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.11) for package: php-xml-5.3.3-3.el6_1.3.i686
--> Processing Dependency: libxslt.so.1 for package: php-xml-5.3.3-3.el6_1.3.i686
--> Processing Dependency: libexslt.so.0 for package: php-xml-5.3.3-3.el6_1.3.i686
---> Package php-xmlrpc.i686 0:5.3.3-3.el6_1.3 will be installed
--> Running transaction check
---> Package freetype.i686 0:2.3.11-6.el6_1.7 will be installed
---> Package libX11.i686 0:1.3-2.el6 will be installed
--> Processing Dependency: libX11-common = 1.3-2.el6 for package: libX11-1.3-2.el6.i686
--> Processing Dependency: libxcb.so.1 for package: libX11-1.3-2.el6.i686
---> Package libXpm.i686 0:3.5.8-2.el6 will be installed
---> Package libedit.i686 0:2.11-4.20080712cvs.1.el6 will be installed
---> Package libjpeg.i686 0:6b-46.el6 will be installed
---> Package libpng.i686 2:1.2.46-1.el6_1 will be installed
---> Package libxslt.i686 0:1.1.26-2.el6 will be installed
---> Package postgresql-libs.i686 0:8.4.9-1.el6_1.1 will be installed
---> Package unixODBC.i686 0:2.2.14-11.el6 will be installed
--> Processing Dependency: libltdl.so.7 for package: unixODBC-2.2.14-11.el6.i686
--> Running transaction check
---> Package libX11-common.noarch 0:1.3-2.el6 will be installed
---> Package libtool-ltdl.i686 0:2.2.6-15.5.el6 will be installed
---> Package libxcb.i686 0:1.5-1.el6 will be installed
--> Processing Dependency: libXau.so.6 for package: libxcb-1.5-1.el6.i686
--> Running transaction check
---> Package libXau.i686 0:1.0.5-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================
 Package                 Arch         Version                         Repository                  Size
=======================================================================================================
Installing:
 php                     i686         5.3.3-3.el6_1.3                 CentOS6.2-Repository       1.1 M
 php-cli                 i686         5.3.3-3.el6_1.3                 CentOS6.2-Repository       2.2 M
 php-common              i686         5.3.3-3.el6_1.3                 CentOS6.2-Repository       522 k
 php-gd                  i686         5.3.3-3.el6_1.3                 CentOS6.2-Repository       102 k
 php-ldap                i686         5.3.3-3.el6_1.3                 CentOS6.2-Repository        35 k
 php-mysql               i686         5.3.3-3.el6_1.3                 CentOS6.2-Repository        76 k
 php-odbc                i686         5.3.3-3.el6_1.3                 CentOS6.2-Repository        47 k
 php-pdo                 i686         5.3.3-3.el6_1.3                 CentOS6.2-Repository        71 k
 php-pear                noarch       1:1.9.4-4.el6                   CentOS6.2-Repository       393 k
 php-pecl-apc            i686         3.1.3p1-1.2.el6.1               CentOS6.2-Repository        93 k
 php-pecl-memcache       i686         3.0.5-3.el6                     CentOS6.2-Repository        60 k
 php-pgsql               i686         5.3.3-3.el6_1.3                 CentOS6.2-Repository        66 k
 php-soap                i686         5.3.3-3.el6_1.3                 CentOS6.2-Repository       138 k
 php-xml                 i686         5.3.3-3.el6_1.3                 CentOS6.2-Repository        98 k
 php-xmlrpc              i686         5.3.3-3.el6_1.3                 CentOS6.2-Repository        50 k
Installing for dependencies:
 freetype                i686         2.3.11-6.el6_1.7                CentOS6.2-Repository       362 k
 libX11                  i686         1.3-2.el6                       CentOS6.2-Repository       585 k
 libX11-common           noarch       1.3-2.el6                       CentOS6.2-Repository       188 k
 libXau                  i686         1.0.5-1.el6                     CentOS6.2-Repository        22 k
 libXpm                  i686         3.5.8-2.el6                     CentOS6.2-Repository        58 k
 libedit                 i686         2.11-4.20080712cvs.1.el6        CentOS6.2-Repository        73 k
 libjpeg                 i686         6b-46.el6                       CentOS6.2-Repository       133 k
 libpng                  i686         2:1.2.46-1.el6_1                CentOS6.2-Repository       184 k
 libtool-ltdl            i686         2.2.6-15.5.el6                  CentOS6.2-Repository        45 k
 libxcb                  i686         1.5-1.el6                       CentOS6.2-Repository       104 k
 libxslt                 i686         1.1.26-2.el6                    CentOS6.2-Repository       448 k
 postgresql-libs         i686         8.4.9-1.el6_1.1                 CentOS6.2-Repository       201 k
 unixODBC                i686         2.2.14-11.el6                   CentOS6.2-Repository       382 k

Transaction Summary
=======================================================================================================
Install      28 Package(s)

Total download size: 7.8 M
Installed size: 26 M
Is this ok [y/N]: y
Downloading Packages:
-------------------------------------------------------------------------------------------------------
Total                                                                  7.2 MB/s | 7.8 MB     00:01
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : libX11-common-1.3-2.el6.noarch                                                     1/28
  Installing : php-common-5.3.3-3.el6_1.3.i686                                                    2/28
  Installing : php-pdo-5.3.3-3.el6_1.3.i686                                                       3/28
  Installing : libxslt-1.1.26-2.el6.i686                                                          4/28
  Installing : postgresql-libs-8.4.9-1.el6_1.1.i686                                               5/28
  Installing : libedit-2.11-4.20080712cvs.1.el6.i686                                              6/28
  Installing : php-cli-5.3.3-3.el6_1.3.i686                                                       7/28
  Installing : 1:php-pear-1.9.4-4.el6.noarch                                                      8/28
  Installing : libjpeg-6b-46.el6.i686                                                             9/28
  Installing : libtool-ltdl-2.2.6-15.5.el6.i686                                                  10/28
  Installing : unixODBC-2.2.14-11.el6.i686                                                       11/28
  Installing : 2:libpng-1.2.46-1.el6_1.i686                                                      12/28
  Installing : freetype-2.3.11-6.el6_1.7.i686                                                    13/28
  Installing : libXau-1.0.5-1.el6.i686                                                           14/28
  Installing : libxcb-1.5-1.el6.i686                                                             15/28
  Installing : libX11-1.3-2.el6.i686                                                             16/28
  Installing : libXpm-3.5.8-2.el6.i686                                                           17/28
  Installing : php-gd-5.3.3-3.el6_1.3.i686                                                       18/28
  Installing : php-odbc-5.3.3-3.el6_1.3.i686                                                     19/28
  Installing : php-pecl-apc-3.1.3p1-1.2.el6.1.i686                                               20/28
  Installing : php-pecl-memcache-3.0.5-3.el6.i686                                                21/28
  Installing : php-5.3.3-3.el6_1.3.i686                                                          22/28
  Installing : php-pgsql-5.3.3-3.el6_1.3.i686                                                    23/28
  Installing : php-xml-5.3.3-3.el6_1.3.i686                                                      24/28
  Installing : php-mysql-5.3.3-3.el6_1.3.i686                                                    25/28
  Installing : php-xmlrpc-5.3.3-3.el6_1.3.i686                                                   26/28
  Installing : php-ldap-5.3.3-3.el6_1.3.i686                                                     27/28
  Installing : php-soap-5.3.3-3.el6_1.3.i686                                                     28/28

Installed:
  php.i686 0:5.3.3-3.el6_1.3                        php-cli.i686 0:5.3.3-3.el6_1.3
  php-common.i686 0:5.3.3-3.el6_1.3                 php-gd.i686 0:5.3.3-3.el6_1.3
  php-ldap.i686 0:5.3.3-3.el6_1.3                   php-mysql.i686 0:5.3.3-3.el6_1.3
  php-odbc.i686 0:5.3.3-3.el6_1.3                   php-pdo.i686 0:5.3.3-3.el6_1.3
  php-pear.noarch 1:1.9.4-4.el6                     php-pecl-apc.i686 0:3.1.3p1-1.2.el6.1
  php-pecl-memcache.i686 0:3.0.5-3.el6              php-pgsql.i686 0:5.3.3-3.el6_1.3
  php-soap.i686 0:5.3.3-3.el6_1.3                   php-xml.i686 0:5.3.3-3.el6_1.3
  php-xmlrpc.i686 0:5.3.3-3.el6_1.3

Dependency Installed:
  freetype.i686 0:2.3.11-6.el6_1.7                libX11.i686 0:1.3-2.el6
  libX11-common.noarch 0:1.3-2.el6                libXau.i686 0:1.0.5-1.el6
  libXpm.i686 0:3.5.8-2.el6                       libedit.i686 0:2.11-4.20080712cvs.1.el6
  libjpeg.i686 0:6b-46.el6                        libpng.i686 2:1.2.46-1.el6_1
  libtool-ltdl.i686 0:2.2.6-15.5.el6              libxcb.i686 0:1.5-1.el6
  libxslt.i686 0:1.1.26-2.el6                     postgresql-libs.i686 0:8.4.9-1.el6_1.1
  unixODBC.i686 0:2.2.14-11.el6

Complete!

3.0 How to Install MySQL Database Server on CentOS 6.2

This post will show you on how to install MySQL server using yum command.

Simply run the following command :

[root@centos6 ~]# yum install mysql mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql.i686 0:5.1.52-1.el6_0.1 will be installed
---> Package mysql-server.i686 0:5.1.52-1.el6_0.1 will be installed
--> Processing Dependency: perl-DBI for package: mysql-server-5.1.52-1.el6_0.1.i686
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.52-1.el6_0.1.i686
--> Processing Dependency: perl(DBI) for package: mysql-server-5.1.52-1.el6_0.1.i686
--> Running transaction check
---> Package perl-DBD-MySQL.i686 0:4.013-3.el6 will be installed
---> Package perl-DBI.i686 0:1.609-4.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================
 Package                Arch         Version                  Repository                    Size
=================================================================================================
Installing:
 mysql                  i686         5.1.52-1.el6_0.1         CentOS6.2-Repository         898 k
 mysql-server           i686         5.1.52-1.el6_0.1         CentOS6.2-Repository         8.3 M
Installing for dependencies:
 perl-DBD-MySQL         i686         4.013-3.el6              CentOS6.2-Repository         134 k
 perl-DBI               i686         1.609-4.el6              CentOS6.2-Repository         705 k

Transaction Summary
=================================================================================================
Install       4 Package(s)

Total download size: 10 M
Installed size: 27 M
Is this ok [y/N]: y
Downloading Packages:
-------------------------------------------------------------------------------------------------
Total                                                             13 MB/s |  10 MB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : perl-DBI-1.609-4.el6.i686                                                     1/4
  Installing : perl-DBD-MySQL-4.013-3.el6.i686                                               2/4
  Installing : mysql-5.1.52-1.el6_0.1.i686                                                   3/4
  Installing : mysql-server-5.1.52-1.el6_0.1.i686                                            4/4

Installed:
  mysql.i686 0:5.1.52-1.el6_0.1               mysql-server.i686 0:5.1.52-1.el6_0.1

Dependency Installed:
  perl-DBD-MySQL.i686 0:4.013-3.el6                  perl-DBI.i686 0:1.609-4.el6

Complete!

Hope all these three steps will be useful when installing Apache, PHP and MySQL on linux Centos 6.2 server

As always if you need any help you can reach us on twitter @ehowstuff or drop us a comment below. Jumping through archives page to read more articles..



Previous post:

Next post: