Current Location: Home> Latest Articles> Complete Guide to Installing and Configuring PHP on CentOS 6.9

Complete Guide to Installing and Configuring PHP on CentOS 6.9

gitbox 2025-07-28

Introduction

PHP is a widely-used server-side scripting language for web development. For CentOS 6.9 users, installing and configuring PHP properly is a critical step in setting up a reliable development environment. This guide walks you through every step of the process to help you install and configure PHP on CentOS 6.9 effectively.

System Preparation

Before installing PHP, it's recommended to update your system to ensure stability and compatibility. Use the following command to update your packages:

sudo yum update

Install Required Dependencies

PHP requires several system components. Install Apache (httpd), PHP, and related modules with this command:

sudo yum install httpd php php-cli php-mysql

Installing PHP

You can install PHP directly from the default CentOS repository using this command:

sudo yum install php

Installing a Specific PHP Version

If you need a specific version, such as PHP 5.6, you must first enable the EPEL and Remi repositories:

sudo yum install epel-release
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-6.rpm

Next, enable the repository for PHP 5.6:

sudo yum-config-manager --enable remi-php56

Then install PHP again using:

sudo yum install php

Configuring PHP

Once installed, you can configure PHP by editing the php.ini file, usually located at /etc/php.ini:

sudo nano /etc/php.ini

Common Configuration Options

Here are a few key settings you might want to modify based on your application requirements:

  • memory_limit: Recommended to be set to at least 128M.
  • error_reporting: Set to E_ALL to display all errors during development.
  • upload_max_filesize: Adjust this based on your file upload needs (e.g., 50M).

Verifying PHP Installation

Create a simple test file to ensure PHP is working properly. Place the following into a file named info.php in your web root:

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Then access it via a browser at: http://your_server_ip/info.php. If the PHP information page loads, your installation was successful.

Conclusion

With this guide, you now know how to install and configure PHP on CentOS 6.9. From preparing your system to fine-tuning PHP settings, every step is essential to building a reliable web server environment. If you encounter issues, consider consulting official documentation or community forums for additional help.