PHP remains a widely used server-side scripting language in modern web development. Especially in Linux environments, knowing how to install and configure PHP is crucial for setting up a robust development or deployment platform.
Before installing PHP, it is recommended to update your system to avoid compatibility issues. Use the command below to ensure your system is up to date:
sudo apt-get update && sudo apt-get upgrade
Some essential libraries are required for PHP to function properly. Install them with the following command:
sudo apt-get install software-properties-common
To install the latest version of PHP, you need to add the official PHP repository:
sudo add-apt-repository ppa:ondrej/php
After adding the repository, update the package list:
sudo apt-get update
Now install PHP and some commonly used modules. The following example installs PHP version 8.0:
sudo apt-get install php8.0 php8.0-cli php8.0-fpm php8.0-mysql
Explanation of modules:
After installation, you can confirm PHP is working with the following command:
php -v
If PHP version info is displayed, the installation was successful.
Depending on your project needs, you may want to adjust PHP’s configuration file. Open php.ini to make changes:
sudo nano /etc/php/8.0/fpm/php.ini
Important settings to consider modifying:
After making changes, restart the PHP service to apply the new configuration:
sudo systemctl restart php8.0-fpm
With the steps outlined in this guide, you can install and configure PHP on a Linux system efficiently. Whether you're setting up a local development environment or a live server, mastering this process will boost your productivity in PHP web development.