1# Ondřej Surý, a Debian developer, maintains a repository that includes
2# multiple PHP versions. To enable the repository , run:
3
4sudo apt install software-properties-common
5sudo add-apt-repository ppa:ondrej/php
6
7# Installing PHP 8.0 with Apache
8
9#If you’re using Apache as a web server,
10#you can run PHP as an Apache module or PHP-FPM.
11
12#Install PHP as Apache Module
13
14#Installing PHP as an Apache module is a straightforward task:
15
16sudo apt update
17sudo apt install php8.0 libapache2-mod-php8.0
18
19#Once the packages are installed,
20#restart Apache for the PHP module to get loaded:
21
22sudo systemctl restart apache2
23
24#Configure Apache with PHP-FPM
25
26#Php-FPM is a FastCGI process manager for PHP.
27#Run the following command to install the necessary packages:
28
29
30sudo apt update
31sudo apt install php8.0-fpm libapache2-mod-fcgid
32
33#By default PHP-FPM is not enabled in Apache. To enable it, run:
34
35sudo a2enmod proxy_fcgi setenvif
36sudo a2enconf php8.0-fpm
37
38#To activate the changes, restart Apache:
39
40systemctl restart apache2
41
42#Installing PHP 8.0 with Nginx
43
44#Nginx doesn’t have built-in support for processing PHP files.
45#We’ll use PHP-FPM (“fastCGI process manager”) to handle the PHP files.
46
47#Run the following commands to install PHP and PHP FPM packages:
48
49sudo apt update
50sudo apt install php8.0-fpm
51
52#Once the installation is completed,
53#the FPM service will start automatically.
54#To check the status of the service, run
55
56systemctl status php8.0-fpm
57
58Output
59● php8.0-fpm.service - The PHP 8.0 FastCGI Process Manager
60 Loaded: loaded (/lib/systemd/system/php8.0-fpm.service; enabled; vendor preset: enabled)
61 Active: active (running) since Thu 2020-12-03 16:10:47 UTC; 6s ago
62
63#You can now edit the Nginx server block
64#and add the following lines so that Nginx can process PHP files:
65
66server {
67
68 # . . . other code
69
70 location ~ \.php$ {
71 include snippets/fastcgi-php.conf;
72 fastcgi_pass unix:/run/php/php8.0-fpm.sock;
73 }
74
75#Do not forget to restart the Nginx service so that the new
76#configuration takes effect:
77
78sudo systemctl restart nginx
79
80#Installing PHP extensions
81#PHP extensions are compiled libraries that extend the core functionality
82#of PHP. Extensions are available as packages and can be easily
83#installed with apt :
84
85sudo apt install php8.0-[extname]
86
87#For example, to install MySQL and GD extensions,
88#you would run the following command:
89
90
91sudo apt install php8.0-mysql php8.0-gd
92
93#After installing a new PHP extension,
94#do not forget to restart Apache or PHP FPM service,
95#depending on your setup.
96
97
98#Testing PHP Processing
99#To test whether the web server is configured properly for PHP processing,
100#create a new file named info.php inside the /var/www/html directory
101#with the following code:
102
103<?php
104
105phpinfo();
106
107#Save the file, open your browser, and visit:
108#http://your_server_ip/info.php.
109
110
111#Conclusion
112#Installing PHP 8 on Ubuntu 20.04 server is a simple task.
113#All you need to do is to enable the “ondrej/php” repository
114#and install PHP 8 with apt.
115