The cart is empty

CentOS 7, being a popular Linux distribution for server deployments, provides a stable platform for running web applications. PHP, a dynamic scripting language, is a key component of many modern web applications including Wordpress, Drupal, and Joomla. This article will guide you through the steps required to install and perform basic configuration of PHP on CentOS 7.

Preparing the System

Before you begin, ensure that your system is up to date. Open a terminal and run the following command:

sudo yum update

This command will update all installed packages to their latest available versions.

Installing PHP

CentOS 7 by default uses YUM (Yellowdog Updater Modified) as the package manager. PHP and its modules can be installed using YUM. First, check the available versions of PHP:

yum search php

Install PHP along with commonly used modules:

sudo yum install php php-cli php-fpm php-mysql php-xml php-mbstring

After installation, verify the PHP version:

php -v

Configuring PHP

The configuration file for PHP, php.ini, is typically located at /etc/php.ini. Use a text editor such as nano or vim to edit this file. Here's an example of basic configuration:

sudo vim /etc/php.ini

Here, you can adjust various directives such as upload_max_filesize, max_execution_time, memory_limit, and others according to your application's needs.

Configuring Apache with PHP

If you're using Apache as your web server, ensure it's properly configured to work with PHP. Install Apache:

sudo yum install httpd

Then configure Apache to process PHP files:

  1. Ensure you have the directive for handling PHP files in your httpd.conf file.
  2. Restart Apache to apply the changes:
    sudo systemctl restart httpd
    ​

Testing PHP

To verify that PHP is functioning correctly, create a PHP test file in the root directory of your web server, typically /var/www/HTML:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php

 

Then open your server's address followed by /phpinfo.php in a web browser. You should see a page displaying information about the PHP configuration.

 

You now have PHP installed and basic configuration done on CentOS 7. This process forms the foundation for running many different types of web applications and content management systems. Further steps may involve deeper configuration of PHP and Apache, securing your system, and perhaps installing additional PHP extensions depending on your application's needs.