Skip to main content
PHP

How to upgrade PHP version from 7.2 to 7.3 on a Ubuntu Server?

By July 7, 2021January 4th, 2022No Comments

The following are the commands I ran in order to upgrade PHP version from 7.2 to 7.3 for a laravel project.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Run commands one by one. Do not paste whole chunk.

sudo apt-get install software-properties-common;
sudo add-apt-repository ppa:ondrej/php;
sudo apt-get update;
sudo apt-get upgrade;
sudo apt-get install -y php7.3;

# Instantly php version changes
php -v;

# For a Laravel Project

sudo apt-get install php7.3-zip -y;
sudo apt-get install php7.3-gd -y;
sudo apt-get install php7.3-xml -y;
sudo apt-get install php7.3-curl -y;
sudo apt-get install php-mbstring -y;
sudo apt-get install php7.3-mbstring -y;
sudo apt install php7.3-mysql -y;

# do this too - https://stackoverflow.com/a/35240511/6275860
# Restart is not needed but we should still do it to see all is well.

sudo service apache2 restart;

sudo update-alternatives --config php;

# We are good to test now the websites.

# If required
sudo a2dismod php7.2 // disable
sudo a2dismod php8.0 // disable
sudo a2enmod php7.3;

sudo apt-get install libapache2-mod-php;

sudo update-alternatives --config php;
sudo update-alternatives --config phar;
sudo update-alternatives --config phar.phar;


# https://stackoverflow.com/a/46296973/6275860

# if nothig works, try this not sure though
sudo a2enmod mpm_prefork;

The process should be same for the other upgrades as well such as: 7.0 to 7.4, 7.2 to 7.4 etc.