Install PHP on Linux: Complete Setup Guide

To set up a PHP environment on Linux, you can follow the steps below:

  1. Update the operating system.
  2. Please update and upgrade the system using the following commands:
    sudo apt update
    sudo apt upgrade
  3. Install Apache server:
  4. Please install apache2 using the sudo apt command.
  5. Install PHP and its related modules.
  6. Install php, libapache2-mod-php, and php-mysql using sudo apt.
  7. Configure Apache2 to use the PHP module.
  8. Open the directory configuration file using the nano text editor by running the command with root privileges.
  9. Between the lines in the section and , move index.php to the first position, save and exit.
  10. Restart the Apache server.
  11. Please restart the apache2 service using systemctl.
  12. To confirm if PHP is installed correctly:
    Create a file named info.php in the root directory of your website, and add the following content to the file:
  13. Display information about PHP by calling the phpinfo() function.
  14. Accessing http://your_domain_or_IP/info.php in a web browser will confirm that PHP has been successfully installed if you can see the PHP information page.

The steps above are instructions for Debian-based Linux distributions (such as Ubuntu). For other Linux distributions, you may need to use different package managers and commands to install the corresponding software packages.

bannerAds