Install PHP on Linux: Complete Setup Guide
To set up a PHP environment on Linux, you can follow the steps below:
- Update the operating system.
- Please update and upgrade the system using the following commands:
sudo apt update
sudo apt upgrade - Install Apache server:
- Please install apache2 using the sudo apt command.
- Install PHP and its related modules.
- Install php, libapache2-mod-php, and php-mysql using sudo apt.
- Configure Apache2 to use the PHP module.
- Open the directory configuration file using the nano text editor by running the command with root privileges.
- Between the
lines in the section and , move index.php to the first position, save and exit. - Restart the Apache server.
- Please restart the apache2 service using systemctl.
- 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: - Display information about PHP by calling the phpinfo() function.
- 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.