What are the steps to install PHP on Linux?
Installing PHP on a Linux system can be achieved using package management tools. Below are the general steps to install PHP on Linux.
- Open the terminal and update the package management tool.
sudo apt update
- Install PHP and its related extensions.
sudo apt install php
You can also install a specific version of PHP, such as PHP 7.4.
sudo apt install php7.4
You can use the following command to install additional PHP extensions.
sudo apt install php-<extension-name>
For example, installing the MySQL extension:
sudo apt install php-mysql
- Install common dependencies for PHP:
sudo apt install php-cli php-fpm php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
- Check if PHP has been successfully installed.
php -v
- Set up PHP
The configuration file for PHP is usually located at /etc/php/{version}/apache2/php.ini or /etc/php/{version}/cli/php.ini, and you can modify the settings as needed.
- Restart the web server to apply the changes:
sudo systemctl restart apache2
After installation is complete, you can start using PHP on your Linux system.