How to Install php on CentOS 6.2

PHP is a popular scripting language widely used for web development. If you’re using CentOS 6.2, you may need to install PHP to run dynamic websites and applications. In this guide, we will walk you through the steps to install PHP on CentOS 6.2.

Step 1: Update System Packages:

Before installing PHP, it’s a good practice to update the system packages to their latest versions. Open your terminal or SSH into your CentOS 6.2 server and run the following command:

sudo yum update

This command will update the package lists and upgrade the installed packages on your system.

Step 2: Install PHP and Required Packages:

To install PHP and its required packages, use the following command:

sudo yum install php php-cli php-common

This command will install PHP, the PHP command-line interface, and the common PHP modules on your CentOS 6.2 system.

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

Step 3: Verify PHP Installation:

Once the installation is complete, you can verify PHP installation by running the following command:

php -v

This command will display the PHP version and other related information if PHP is installed correctly.

See also  How to Change 389 LDAP Password using PHP Scripting

Step 4: Configure PHP:

By default, PHP is configured with the basic settings, but you may need to modify the configuration based on your requirements. The PHP configuration file is located at /etc/php.ini. Open the file in a text editor and make the necessary changes.

For example, if you want to enable error reporting, find the following line:

; display_errors = Off

And change it to:

display_errors = On

Save the file after making the changes.

Step 5: Restart Web Server:

To apply the changes and make PHP available for web server processes, you need to restart the web server. On CentOS 6.2, the most commonly used web server is Apache. Restart Apache using the following command:

sudo service httpd restart

This command will restart the Apache web server, allowing it to recognize PHP and serve PHP-enabled web pages.

See also  How to check php-apc has been loaded or not ?

Commands Mentioned:

  • sudo yum update – Updates system packages.
  • sudo yum install php php-cli php-common – Installs PHP and its required packages.
  • php -v – Verifies the PHP installation and displays the PHP version.
  • sudo service httpd restart – Restarts the Apache web server.

Conclusion:

Congratulations! You have successfully installed PHP on CentOS 6.2. Now you can start developing dynamic websites and applications using PHP. Remember to regularly update PHP and its modules to ensure security and performance.

If you have any further questions or suggestions, please feel free to comment below.

Comments

Leave a Reply

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