How to install PHP on Ubuntu?

Installing PHP on Ubuntu typically involves performing the following steps:

  1. Open the terminal and update the list of software packages.
sudo apt update
  1. Install PHP and its related extensions.
sudo apt install php libapache2-mod-php php-mysql
  1. Install PHP extension modules as needed.
sudo apt install php-xml php-mbstring php-ldap php-zip php-gd
  1. Restart the Apache server to apply the changes.
sudo systemctl restart apache2
  1. You can verify if PHP was successfully installed by creating a simple PHP file and accessing it through a web browser.
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php

Then, access http://localhost/phpinfo.php in the browser. If the PHP information page is successfully displayed, it means that PHP has been installed successfully.

Please note that the above steps are for installing PHP with Apache server. If you are using a different web server or need a different PHP version, please adjust accordingly.

bannerAds