PHP is a widespread open-source scripting language that is widely utilized for web development. It is commonly used to create dynamic web pages, process form data, generate PDFs and images, and interact with databases. Being a widely used language, PHP is available on all the famous OS platforms, i.e., Linux, Windows, and macOS.
This guide will offer the step by step instructions to install PHP on CentOS.
- How to Install PHP on CentOS?
- Update the Package Manager
- Install PHP
- Verify the Installation
- Install Additional PHP Modules
- Restart Apache
- How to Remove PHP From CentOS?
How to Install PHP on CentOS?
Here’s a step-by-step guide to installing PHP on CentOS:
Step 1: Update the Package Manager
Before installing, it is a good idea to update the packages list on the CentOS system. For this, run the following command:
# yum update
It updates the system to the latest version of all installed packages.
Step 2: Install PHP
Once the system is up to date, users can install PHP by executing the following command:
# yum install php
It installs the latest version of PHP and any required dependencies.
Step 3: Verify the Installation
Once the installation is completed, verify the installed PHP in the operating system by running the following command:
# php -v
It displays the version number of PHP currently installed on the system.
Step 4: Install Additional PHP Modules
Users may also need additional PHP modules depending on requirements. To do this, run the below command:
# yum install php-module-name
Replace “module-name” with the module’s name that users want to install. For example, if users need the MySQL module, run the below command:
# yum install php-mysqlnd
The output shows that the MySQL module has been installed in the system.
Step 5: Restart Apache
After installing PHP and any necessary modules, restart Apache to ensure the changes take effect:
# systemctl restart httpd
Finally, the Apache server has been restarted on CentOS.
How to Remove PHP From CentOS?
To remove the PHP along with dependent packages, use the “autoremove” command with the php as below:
# yum remove php # Remove PHP package
# yum autoremove php # Remove PHP package with all dependencies
It removes PHP along with all dependent packages.
Conclusion
To install PHP on CentOS, execute the “yum install php” command. Users can install additional PHP modules by executing the “sudo yum install <php-module-name>” command. PHP is essential to many websites that enable users to create interactive web pages.
This guide has explained the step-by-step instructions to install PHP on CentOS.