In today’s internet era, PHP is a popular programming language widely used for dynamic website and application development. This article offers a comprehensive guide to help you smoothly set up a PHP environment on CentOS 7, ensuring efficient development and deployment.
First, ensure your CentOS 7 system is updated to the latest version. Run the following command to update the system:
sudo yum update
Before installing PHP, some dependencies need to be installed. Use the following command to install the EPEL repository:
sudo yum install -y epel-release
Next, add the Remi repository to access the latest PHP versions:
sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
Install PHP 7.4 from the Remi repository by running:
sudo yum --enablerepo=remi-php74 install -y php
After installation, check the PHP version to confirm it was installed correctly:
php -v
To enhance PHP functionality, it’s recommended to install extensions like MySQL support, GD for graphics, and mbstring for multibyte strings:
sudo yum --enablerepo=remi-php74 install -y php-mysqlnd php-gd php-mbstring php-xml
Edit the PHP configuration file to adjust parameters such as memory_limit and upload_max_filesize according to your needs:
sudo vi /etc/php.ini
Save and exit the editor after making changes.
Restart your web server to apply configuration changes.
If you are using Apache, run:
sudo systemctl restart httpd
If you are using Nginx, run:
sudo systemctl restart nginx
Create a test file to verify PHP is working correctly. Create a file named info.php with the following content:
<?php phpinfo(); ?>
Place this file in your web server’s root directory (e.g., /var/www/html/), then access it in your browser at:
http://your_server_ip/info.php
If the PHP information page is displayed, your environment is set up successfully.
Following the above steps, you have successfully set up a PHP development environment on CentOS 7. Proper configuration and extension installation will ensure smooth project development. It’s recommended to stay updated with PHP best practices to enhance server performance and security.