0 Votes

Wiki source code of Установка php 8

Last modified by Сергей Коршунов on 2022/04/21 02:11

Show last authors
1 = How to Install PHP 8.1 on Rocky Linux 8 =
2
3 **[[PHP 8.1>>url:https://www.php.net/]]** is a significant update of the PHP language that will be “officially” released on November 25, 2021. This is a standard upgrade going forward from the existing PHP 8.0 release with the new PHP 8.1 is bringing enums, fibers, never return type, final class constants, intersection types, read-only properties amongst the long list of new features and changes.
4
5 In the following tutorial, you will learn **how to import the REMI Module and install PHP 8.1 on your Rocky Linux system.**
6
7 == Prerequisites ==
8
9 * **Recommended OS:** [[Rocky Linux 8.+>>url:https://rockylinux.org/download/]].
10 * **User account:** A user account with sudo or root access.
11
12 === Update Operating System ===
13
14 Update your **Rocky Linux** operating system to make sure all existing packages are up to date:
15
16 {{{sudo dnf upgrade --refresh -y}}}
17
18 The tutorial will be using the** sudo command** and **assuming you have sudo status**.
19
20 To verify sudo status on your account:
21
22 {{{sudo whoami}}}
23
24 //Example output showing sudo status~://
25
26 {{{[joshua@rockylinux ~]$ sudo whoami
27 root}}}
28
29 To set up an existing or new sudo account, visit our tutorial on **[[How to Add a User to Sudoers on Rocky Linux>>url:https://www.linuxcapable.com/how-to-add-a-user-to-sudoers-on-rocky-linux/]]**.
30
31 To use the **root account**, use the following command with the root password to log in.
32
33 {{{su}}}
34
35 == Install PHP 8.1 Remi Repository ==
36
37 Currently, PHP 8.1 is not featured in Rocky Linux’s AppStream, given it’s still relatively new and hasn’t filtered down the chain in Rhel’s repositories yet. However, you can install PHP from (Remi) repository, a free-to-use third-party repository that deploys the latest PHP 8.1 builds.
38
39 The first task is to install the **(EPEL**) repository, which stands for (**Extra Packages for Enterprise Linux). **For newer users to Rhel and Rocky Linux, EPEL contains the most commonly used software packages for Enterprise Linux.
40
41 To install EPEL, use the following **(dnf)** terminal command:
42
43 {{{sudo dnf install epel-release}}}
44
45 //Example output~://
46
47 [[[[image:https://www.linuxcapable.com/wp-content/webp-express/webp-images/doc-root/wp-content/uploads/2021/11/install-epel-release-rocky-linux-8-for-php-8.1.png.webp||alt="How to Install PHP 8.1 on Rocky Linux 8" height="337" width="734"]]>>url:https://www.linuxcapable.com/wp-content/uploads/2021/11/install-epel-release-rocky-linux-8-for-php-8.1.png]]
48
49 Type **“Y,”** then press the **“ENTER KEY”** to proceed with the installation.
50
51 Now that you have added the EPEL repository, enable** (Remi repository) **with the following:
52
53 {{{sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm}}}
54
55 //Example output~://
56
57 [[[[image:https://www.linuxcapable.com/wp-content/webp-express/webp-images/doc-root/wp-content/uploads/2021/11/install-php-8.1-on-rocky-linux-8-import-remi-repository.png.webp||alt="How to Install PHP 8.1 on Rocky Linux 8" height="445" width="734"]]>>url:https://www.linuxcapable.com/wp-content/uploads/2021/11/install-php-8.1-on-rocky-linux-8-import-remi-repository.png]]
58
59 Type **“Y,”** then press the **“ENTER KEY”** to proceed with the installation.
60
61 Next, use the **(dnf)** command to update your repository list:
62
63 {{{sudo dnf update}}}
64
65 You will notice a query in your terminal about importing the **(GPG key)** for the Remi repository.
66
67 //Example~://
68
69 [[[[image:https://www.linuxcapable.com/wp-content/webp-express/webp-images/doc-root/wp-content/uploads/2021/11/import-gpg-key-rocky-linux-8-remi-repository-for-php-8.1.png.webp||alt="How to Install PHP 8.1 on Rocky Linux 8" height="211" width="734"]]>>url:https://www.linuxcapable.com/wp-content/uploads/2021/11/import-gpg-key-rocky-linux-8-remi-repository-for-php-8.1.png]]
70
71 Type **“Y,” **then press the **“ENTER KEY”** to proceed with importing the GPG key and completing the installation.
72
73 Note, you will be prompt **x2 **more times to type **“Y”** to import more GPG keys. This is fine to do.
74
75 == Enable PHP 8.1 (Remi) Repository ==
76
77 PHP 7.2 is the default PHP choice for standard installation on Rhel/Rocky Linux with Remi’s repository. A quick tip is to use the **(list php) **command to see the options available and the default.
78
79 The following dnf module list command can do this:
80
81 {{{sudo dnf module list php}}}
82
83 You will get the following output as below. Note the **(d)** tag for default PHP to be installed:
84
85 [[[[image:https://www.linuxcapable.com/wp-content/webp-express/webp-images/doc-root/wp-content/uploads/2021/11/remi-module-list-php-8.1-select-example-rocky-linux-8.png.webp||alt="How to Install PHP 8.1 on Rocky Linux 8" height="391" width="734"]]>>url:https://www.linuxcapable.com/wp-content/uploads/2021/11/remi-module-list-php-8.1-select-example-rocky-linux-8.png]]
86
87 As you can see above, the **(d)** tag is next to PHP 7.2, which you will need to reset and change to install PHP 8.1 on Rocky Linux.
88
89 To reset the PHP list is easy with the following command:
90
91 {{{sudo dnf module list reset php}}}
92
93 Next, enable PHP 8.1 with the following command:
94
95 {{{sudo dnf module enable php:remi-8.1}}}
96
97 //Example output~://
98
99 [[[[image:https://www.linuxcapable.com/wp-content/webp-express/webp-images/doc-root/wp-content/uploads/2021/11/set-php-8.1-remi-repository-default-rocky-linux-8.png.webp||alt="How to Install PHP 8.1 on Rocky Linux 8" height="301" width="734"]]>>url:https://www.linuxcapable.com/wp-content/uploads/2021/11/set-php-8.1-remi-repository-default-rocky-linux-8.png]]
100
101 == Install PHP 8.1 ==
102
103 Now that you have added the Remi PHP repository and enabled PHP 8.1 to be the default version on your Rocky Linux system, you can install PHP 8.1 with the following command:
104
105 {{{sudo dnf install php}}}
106
107 //Example output~://
108
109 [[[[image:https://www.linuxcapable.com/wp-content/webp-express/webp-images/doc-root/wp-content/uploads/2021/11/install-php-8.1-on-rocky-linux-8.png.webp||alt="How to Install PHP 8.1 on Rocky Linux 8" height="733" width="734"]]>>url:https://www.linuxcapable.com/wp-content/uploads/2021/11/install-php-8.1-on-rocky-linux-8.png]]
110
111 Type **“Y,”** then press the **“ENTER KEY”** to proceed with the installation.
112
113 Note, you will be prompted for more GPG key imports.
114
115 If you would like to install the most commonly used extensions for PHP 8.1, use the following command:
116
117 {{{sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imap php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml}}}
118
119 Note, remove the options you do not want this is optional.
120
121 //Example output~://
122
123 [[[[image:https://www.linuxcapable.com/wp-content/webp-express/webp-images/doc-root/wp-content/uploads/2021/11/install-extra-php-8.1-extensions-rocky-linux-8.1.png.webp||alt="How to Install PHP 8.1 on Rocky Linux 8" height="733" width="734"]]>>url:https://www.linuxcapable.com/wp-content/uploads/2021/11/install-extra-php-8.1-extensions-rocky-linux-8.1.png]]
124
125 Type **“Y,”** then press the **“ENTER KEY”** to proceed with the installation.
126
127 Now that you have installed PHP 8.1 and the extensions, check the version with the following command:
128
129 {{{php -v}}}
130
131 //Example output~://
132
133 [[[[image:https://www.linuxcapable.com/wp-content/webp-express/webp-images/doc-root/wp-content/uploads/2021/11/php-8.1-version-command-example-rocky-linux-8.png.webp||alt="How to Install PHP 8.1 on Rocky Linux 8" height="175" width="734"]]>>url:https://www.linuxcapable.com/wp-content/uploads/2021/11/php-8.1-version-command-example-rocky-linux-8.png]]
134
135 == PHP-FPM Installations of PHP 8.1 ==
136
137 Unlike PHP-FPM installations on Debian/Ubuntu that use the** (www-data) **user, this isn’t the case with RHEL family installations. By default on AlmaLinux, the PHP-FPM service is designed to be run **(Apache)** user, which is incorrect since we are using Nginx, and this needed to be corrected.
138
139 Firstly, open following **(www.conf) **configuration file:
140
141 {{{sudo nano /etc/php-fpm.d/www.conf}}}
142
143 Next, replace the **(Apache) **user and group with the **(Nginx)** user and group:
144
145 [[[[image:https://www.linuxcapable.com/wp-content/webp-express/webp-images/doc-root/wp-content/uploads/2021/09/remove-apache-from-www.conf-lemp-install-php-fpm-almalinux.png.webp||alt="How to Install PHP 8.0 on Rocky Linux 8" height="229" width="734"]]>>url:https://www.linuxcapable.com/wp-content/uploads/2021/09/remove-apache-from-www.conf-lemp-install-php-fpm-almalinux.png]]
146
147 To save, press **(CTRL+O) **then exit **(CTRL+X)**.
148
149 Now you will too reload or restart your PHP-FPM service:
150
151 {{{sudo systemctl restart php-fpm}}}
152
153 === Nginx Configurement ===
154
155 The Nginx server block needs the following example below for Nginx to process the PHP files.
156
157 Below, example for all server blocks that process PHP files that need the **location ~~ .php$** added.
158
159 {{{server {
160 # … some other code
161 # Pass the php scripts to FastCGI server specified in upstream declaration.
162 location ~ \.php(/|$) {
163 include fastcgi.conf;
164 fastcgi_pass unix:/run/php-fpm/www.sock;
165 fastcgi_split_path_info ^(.+\.php)(/.*)$;
166 fastcgi_param PATH_INFO $fastcgi_path_info;
167 fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
168 fastcgi_param DOCUMENT_ROOT $realpath_root;
169 try_files $uri $uri/ /app.php$is_args$args;
170 fastcgi_intercept_errors on;
171 }
172 }}}}
173
174 Test Nginx to make sure you have no errors with the adjustments made with the code above; enter the following.
175
176 {{{sudo nginx -t}}}
177
178 //Example output~://
179
180 {{{nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
181 nginx: configuration file /etc/nginx/nginx.conf test is successful}}}
182
183 Restart Nginx service for installation to be complete.
184
185 {{{sudo systemctl restart nginx}}}
186
187 == Comments and Conclusion ==
188
189 In the tutorial, you have learned how to install PHP 8.1 and configure how to use it with Apache and Nginx. PHP 8.1 is exciting. However, at the current moment, it is still coming out of beta and not considered stable, such as 8.0 or the old stable 7.4, so beware you may find that many of your favorite software like WordPress or Plugins/Themes for CMS software may conflict until developers can update.
190
191 Do some research, prepare, and have PHP 7.4 or 8.0 installed and ready to replace if anything goes wrong when making the switch. The stable versions such as 8.0 are still actively developed, and packages are pushed simultaneously along with the 8.1 packages.