In today's web environment, having a stable and efficient PHP environment is crucial. This guide provides detailed steps for installing and configuring PHP 5.5 on CentOS 6.5, ensuring that your PHP environment runs smoothly and securely.
Before starting, make sure your CentOS 6.5 system is updated to the latest version. You can update the system using the following command:
sudo yum update
Before installing PHP 5.5, you need to install some necessary dependencies. Run the following command:
sudo yum install httpd gcc make libxml2-devel bzip2-devel curl-devel
Since PHP 5.5 is not available in the default CentOS 6.5 yum repository, you need to add a third-party yum repository. Run the following commands to add the repository:
sudo rpm --import http://rpms.remirepo.net/RPM-GPG-KEY-remi
sudo curl -O http://rpms.remirepo.net/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6.rpm
Once the repository is added, you can install PHP 5.5 using the following command:
sudo yum --enablerepo=remi install php php-cli php-common
After installation, you can verify that PHP is correctly installed by running the following command:
php -v
You should see an output similar to the following (version number may vary):
PHP 5.5.x (cli) (built: ...)
After installation, you may need to perform some basic configurations to adjust PHP settings according to your needs. You can edit the PHP configuration file, typically located at /etc/php.ini:
sudo vi /etc/php.ini
Here are some common configuration options:
Find and modify the corresponding options in the configuration file, for example:
upload_max_filesize = 20M
post_max_size = 20M
max_execution_time = 30
After installing Apache and PHP, you need to start the Apache service and test it. Use the following command to start Apache:
sudo service httpd start
Next, create a PHP test file in the web root directory, usually located at /var/www/html:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Now, you can visit http://your-server-ip/info.php in your browser to test if PHP is working correctly. If you see the PHP information page, the installation and configuration were successful.
By following these steps, you should be able to successfully install and configure PHP 5.5 on CentOS 6.5. Make sure to regularly check and update your PHP version to maintain security and performance.