Install PHP 8

Install the latest (currently PHP 8.0.*)

If you already have Apache + PHP installed, I would recommend to run a command to disable current version PHP (mine is 7.3) for Apache

sudo a2dismod php7.3

Add the repository

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update

Now, it’s time to start

sudo apt install -y php8.0-common php8.0-cli

You can check the version installed

php --version

For the most application a few more modules are required

sudo apt install -y php8.0-curl php8.0-gd php8.0-mbstring php8.0-xml php8.0-zip

and for databases support

sudo apt install -y php8.0-mysqli php8.0-mongo

It’s time to add PHP to Apache

sudo apt install -y libapache2-mod-php8.0

and restart the server

sudo service apache2 restart

All steps in one

# if have PHP already installed
sudo a2dismod php7.3
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update
sudo apt install -y php8.0-common php8.0-cli
sudo apt install -y php8.0-curl php8.0-gd php8.0-mbstring php8.0-xml php8.0-zip
sudo apt install -y php8.0-mysqli php8.0-mongo
sudo apt install -y libapache2-mod-php8.0
# to change max_ size
sudo nano /etc/php/8.0/apache2/php.ini
sudo service apache2 restart

Default Installation (Default Repository)

sudo apt install php

Unfortunately, only basic/common modules will be install: no mbstring, mysqli, etc. So, let’s add them

sudo apt install php-cli php-common php-curl php-gd php-mbstring php-mysql php-xml php-phpseclib php-mysqli php-pear php-gettext libapache2-mod-php php-zip

If you are planning to upload huge files, as me, go to

sudo nano /etc/php/7.3/apache2/php.ini

i did not set any specific version in ‘sudo apt install php-cli php-common php-curl php-gd php-mbstring’, so the latest will be installed. BUT, in ‘sudo nano /etc/php/7.3/apache2/php.ini’ you can see 7.3. that’s the current version installed at the time of writing.

… and search for ‘max’ and change the values. for ex:

post_max_size = 256M
upload_max_filesize = 256M

find them, put a values you want, save it, but do not forget

sudo service apache2 restart

Sources: https://computingforgeeks.com/install-php-on-debian-10-buster/

Leave a Reply

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

Yandex.Metrica