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.

  1. Open the terminal and update the package management tool.
sudo apt update
  1. 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
  1. 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
  1. Check if PHP has been successfully installed.
php -v
  1. 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.

  1. 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.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds