With continuous technological advancements, more developers and businesses aim to use the latest PHP versions to improve project performance and features. PHP 7 stands out with its excellent execution efficiency and new functionalities, becoming the preferred choice for many projects. This guide focuses on CentOS 6.5 and offers a detailed walkthrough for installing and configuring PHP 7 to help you quickly set up a stable and efficient PHP environment.
Before starting, ensure your CentOS 6.5 system is fully updated to avoid installation issues. Run the following command to update your system:
sudo yum updateAfter updating, install the necessary tools and dependencies to prepare for the PHP 7 installation.
PHP 7 is not available in CentOS 6.5’s default repositories, so you need to enable the EPEL and Remi third-party repositories. Use the following commands to install these repositories:
sudo yum install epel-release
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-6.rpmOnce installed, you can access PHP 7 packages from the Remi repository.
Enable the PHP 7 repository from Remi and install PHP by running:
sudo yum --enablerepo=remi-php70 install phpThis step ensures that PHP 7 is installed on your system.
With the PHP 7 repository enabled, install PHP along with commonly used extensions to cover various application needs:
sudo yum install php php-cli php-fpm php-mysql php-gd php-mbstring php-xmlThese extensions include command line tools, FastCGI process manager, database support, and image processing capabilities suitable for most PHP projects.
After installation, configure PHP to ensure it meets your requirements. The main PHP configuration file is located at:
/etc/php.iniEdit this file using a text editor to adjust settings as needed. For example, you can change the maximum upload file size and set the timezone:
upload_max_filesize = 20M
date.timezone = "Asia/Shanghai"After configuring PHP, start the PHP-FPM service and enable it to launch on boot:
sudo service php-fpm start
sudo chkconfig php-fpm onVerify the service is running correctly by checking its status with:
sudo service php-fpm statusTo confirm that PHP 7 is properly installed and working, create a test file named info.php in your web server’s root directory with the following content:
<?php
phpinfo();
?>Then, access http://your_server_ip/info.php in your browser. If the PHP info page appears, your installation and configuration were successful.
This guide covered the complete process of installing and configuring PHP 7 on CentOS 6.5. From system updates, adding repositories, installing PHP and extensions, to configuration tweaks and service management, each step ensures a smooth setup. Following these instructions, you will have a robust PHP 7 environment that enhances your applications’ performance and security.