How to Install Apache, PHP and MySQL on CentOS 6.2

In the realm of web hosting, there are a few names that come up time and time again. Apache, PHP, and MySQL are three such names, and they form the backbone of many a website. If you’re looking to set up a robust, high-performance website, you’ll likely need to install these three components on your server. This guide will walk you through the process of installing Apache, PHP, and MySQL on a CentOS 6.2 server.

Before we dive in, it’s worth noting that this guide assumes you have a minimal installation of CentOS 6.2 and have configured your local yum repository. If your server has a direct internet connection, you can use the internet CentOS yum repository.

Installing Apache Httpd on CentOS 6.2

Apache Httpd is a widely used web server, known for its extensibility and suitability for various types of websites. To install Apache Httpd, use the following command:

[root@centos6 ~]# yum install httpd

This command tells the package manager (yum) to install the Apache Httpd package. Once the command is executed, the package manager will fetch the necessary files and install Apache Httpd on your server.

Example:

[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!

Installing PHP on CentOS 6.2

After setting up Apache, the next step is to install PHP packages. Use the following command to install PHP:

[root@centos6 ~]# yum install php*

This command instructs the package manager to install all PHP packages. Once the command is executed, the package manager will retrieve the necessary files and install PHP on your server.

See also  How to Check Concurrent user using Netstat Command on Linux Web Server

Example:

[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!

Installing MySQL Database Server on CentOS 6.2

The final step in this guide is to install the MySQL server. Use the following command to install MySQL:

[root@centos6 ~]# yum install mysql mysql-server

This command instructs the package manager to install the MySQL server and its associated packages. Once the command is executed, the package manager will fetch the necessary files and install MySQL on your server.

See also  How to Install 389 Directory Server on CentOS 6.2

Example:

[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!

Commands Mentioned

  • yum install httpd – This command installs the Apache Httpd web server.
  • yum install php* – This command installs all PHP packages.
  • yum install mysql mysql-server – This command installs the MySQL server and its associated packages.
See also  How to Install ImageMagick and Imagick PHP extension in CentOS

In this comprehensive guide, we’ve walked through the process of installing Apache, PHP, and MySQL on a CentOS 6.2 server. These three components form the backbone of many web applications and understanding how to install and configure them is a crucial skill for any webmaster or website administrator.

We started by installing Apache Httpd, a powerful and flexible web server that can serve a wide variety of websites. Next, we installed PHP, a server-side scripting language that allows for dynamic web content. Finally, we installed MySQL, a robust database management system that stores and retrieves data for your website.

By following this guide, you should now have a fully functional web server ready to host your website. Remember, this is just the beginning of your journey in web hosting. There’s a lot more to learn and explore. For more in-depth information about web servers and hosting, be sure to check out our guides on the best web servers and different hosting options like dedicated server, VPS server, cloud hosting, and shared hosting.

We hope this guide has been informative and helpful. If you have any further questions, don’t hesitate to reach out. Happy hosting!

FAQ Section

  1. What is the role of Apache in a web server?

    Apache is a web server software that serves files and content to the internet. It interprets HTTP requests and delivers the requested content from the server to the client’s web browser.

  2. Why is PHP important in web development?

    PHP is a server-side scripting language that allows for dynamic content on web pages. It can interact with databases, manage user sessions, and perform other tasks that static HTML cannot.

  3. How does MySQL contribute to a website’s functionality?

    MySQL is a database management system that stores and retrieves data for the website. It allows the website to store user information, post content, and other data that can be retrieved and displayed as needed.

  4. What is the purpose of the yum command in CentOS?

    Yum is a package manager in CentOS. It’s used to install, update, and remove software packages. Yum also resolves dependencies and can automatically download and install additional packages as needed.

  5. Why should I use CentOS for my server?

    CentOS is a free, open-source platform that is highly stable and reliable, making it a popular choice for servers. It’s also backed by a large community and extensive documentation, making it easier to manage and troubleshoot.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *