Install PHP and Apache2 on Debian Buster
Login as root and write you Password.
Update your package list, instead of apt-get we will use apt.
# apt update
1- Install ca-certificates, apt-transport-https, lsb-release, curl, aptitude wget y unzip .
apt install ca-certificates apt-transport-https aptitude lsb-release wget curl unzip -y
2- Download the public key (OpenPGP Key) from https://packages.sury.org and add it to your Debian folder, as Debian advises.
wget -O /usr/share/keyrings/apt.gpg https://packages.sury.org/php/apt.gpg
3- Now we are going to add the public key (OpenPGP Key) to our sources.list.d, so you will always have your PHP updated, we do it as Debian says.
sh -c 'echo "deb [signed-by=/usr/share/keyrings/apt.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list'
4- Update you Debian
You have to know that PHP version you want to install, I will use as an example of installation php7.3
5- Sometimes missing PHP modules for Apache Apache, libapache2-mod-php7.3 , we install it.
apt install libapache2-mod-php7.3
6- Install Apache2 server
apt install apache2 -y
7- Install PHP, I repeat, I install the php7.3 version, if you want another one, you have to change for the version number you want to have.
apt install php7.3 php7.3-cli php7.3-curl php7.3-gd php7.3-intl php7.3-json php7.3-mbstring php7.3-mysql php7.3-opcache php7.3-readline php7.3-xml php7.3-xsl php7.3-zip php7.3-bz2 libapache2-mod-php7.3 -y
8- Check if you have installed the version php7.3, write,
You'll see a window telling you which version you are using. It will look like this.
9- Create a phpinfo file. It will display you with more detailed information about your PHP configuration.
With nano write this address /var/www/html which is the default route that the most popular web servers use, as an example, apache2, and phpinfo is the common name for the file, anyway, you can use a different name.
sudo nano /var/www/html/phpinfo.php
A blank file will open, copy this code and add it to the file.
<?php phpinfo(); ?>
To save it, we press the
Ctrl + O
keys and press the
↵ enter key to enter.
To exit from nano we press the keys
Crtl + X
systemctl restart apache2
You have to connect to your virtual network interface, Loopback, for display, this file, typing in your web browser, in the address bar, localhost and phpinfo.php
And if everything went well, you will get a window like this