Install PHP on CentOS 7: Step-by-Step Guide

You can install and configure PHP in CentOS 7 by following these steps:

  1. To install PHP: use the yum package manager to install PHP, you can run the following command:
sudo yum install php
  1. To install PHP extension modules: If you need to use a specific PHP extension module, you can install the corresponding extension module using the yum package manager. For example, to install the MySQL extension module for PHP, you can run the following command:
sudo yum install php-mysql
  1. To configure PHP: The PHP configuration file is located in /etc/php.ini, where you can modify various PHP configuration options such as changing the timezone, adjusting memory limits, etc.
  2. Restart Apache: If you are running PHP through an Apache server, you will need to restart the Apache server for the configuration changes to take effect. You can do so by running the following command:
sudo systemctl restart httpd
  1. Test PHP: Create a simple PHP file to check if PHP is correctly installed and configured. For example, create a file named info.php in the directory /var/www/html/ with the following content:
<?php
phpinfo();
?>

After that, access http://your_server_ip/info.php in the browser. If you can see the PHP information page, it means PHP has been successfully installed and configured.

bannerAds