Installing PHP 7 on a CentOS 7 system can significantly improve server performance and enhance security. This article provides a step-by-step guide to installing PHP 7 in a CentOS 7 environment, including configuration and extension management.
Before installing PHP 7, you’ll need to set up several required packages. Run the following commands as the root user:
yum -y install epel-release
yum -y update
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
Once the repositories are set up, install PHP 7 using this command:
yum -y install php7.4
This will install PHP 7.4 along with its recommended modules, providing enhanced features and performance.
To verify that PHP has been installed correctly, use the command below:
php -v
If successful, this will display the current PHP version installed on the system.
The main configuration file for PHP is located at /etc/php.ini. You can open and edit it using:
vi /etc/php.ini
Common adjustments include modifying the maximum execution time or increasing memory limits. After editing the file, restart your web server to apply changes:
systemctl restart httpd
# or
systemctl restart nginx
To enable features like MySQL database access, image processing, and XML handling, install the following common PHP extensions:
yum -y install php7.4-mysql php7.4-gd php7.4-xml php7.4-mbstring php7.4-json php7.4-curl
These modules enhance PHP's functionality and compatibility with various applications.
Use the following command to verify whether a specific extension is installed:
php -m | grep extension_name
Replace extension_name with the actual module name (e.g., mbstring or curl). If installed, the module name will appear in the output.
This guide covered the full process of installing PHP 7 on CentOS 7, from setting up dependencies to configuring the environment and installing essential extensions. With this setup, your server is now better equipped for modern web development and application deployment.