Skip to content

Commit a0225ec

Browse files
authored
Update php.md (#1693)
Updated and tested for Rocky 9.3 Added $ to bash commands missing it for consistency.
1 parent 7dba8e0 commit a0225ec

File tree

1 file changed

+168
-73
lines changed

1 file changed

+168
-73
lines changed

docs/guides/web/php.md

Lines changed: 168 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: PHP and PHP-FPM
33
author: Antoine Le Morvan
4-
contributors: Steven Spencer, Ganna Zhyrnova
5-
tested_with: 8.9
4+
contributors: Steven Spencer, Ganna Zhyrnova, Joseph Brinkman
5+
tested_with: 8.9, 9.3
66
tags:
77
- web
88
- php
@@ -11,11 +11,7 @@ tags:
1111

1212
# PHP and PHP-FPM
1313

14-
!!! warning "Written for Rocky Linux 8.x"
15-
16-
This procedure was initially published when Rocky Linux 8.x was the only version. This procedure must tested and rewritten for Rocky Linux 9.x.
17-
18-
**PHP** (**P**HP **H**ypertext **P**reprocessor) is a source scripting language, specially designed for web application development. In 2021, PHP represented a little less than 80% of the web pages generated in the world. PHP is open-source and is the core of the most famous CMS (WordPress, Drupal, Joomla!, Magento, ...).
14+
**PHP** (**P**HP **H**ypertext **P**reprocessor) is a source scripting language, specially designed for web application development. In 2024, PHP represented a little less than 80% of the web pages generated in the world. PHP is open-source and is the core of the most famous CMS (WordPress, Drupal, Joomla!, Magento, ...).
1915

2016
**PHP-FPM** (**F**astCGI **P**rocess **M**anager) is integrated to PHP since its version 5.3.3. The FastCGI version of PHP brings additional functionalities.
2117

@@ -43,47 +39,85 @@ Rocky Linux, like its upstream, offers many versions of the language. Some of th
4339

4440
To obtain a list of available versions, simply enter the following command:
4541

46-
```bash
47-
$ sudo dnf module list php
48-
49-
Rocky Linux 8 - AppStream
50-
Name Stream Profiles Summary
51-
php 7.2 [d] common [d], devel, minimal PHP scripting language
52-
php 7.3 common [d], devel, minimal PHP scripting language
53-
php 7.4 common [d], devel, minimal PHP scripting language
54-
php 8.0 common [d], devel, minimal PHP scripting language
55-
56-
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
57-
```
58-
59-
Rocky provides, from its AppStream repository, different PHP modules.
60-
61-
You will note that the default version of a Rocky 8.9 is 7.2 that has already reached its end of life at the time of writing.
62-
63-
You can activate a newer module by entering the following command:
64-
65-
```bash
66-
sudo dnf module enable php:8.0
67-
==============================================================================================
68-
Package Architecture Version Repository Size
69-
==============================================================================================
70-
Enabling module streams:
71-
httpd 2.4
72-
nginx 1.14
73-
php 8.0
74-
75-
Transaction Summary
76-
==============================================================================================
77-
78-
Is this ok [y/N]:
79-
80-
Transaction Summary
81-
==============================================================================================
82-
83-
Is this ok [y/N]: y
84-
Complete!
85-
```
86-
42+
=== "9.0"
43+
44+
```bash { .sh data-copy="sudo dnf module list php" }
45+
$ sudo dnf module list php
46+
47+
Rocky Linux 9 - AppStream
48+
Name Stream Profiles Summary
49+
php 8.1 [d] common [d], devel, minimal
50+
51+
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
52+
```
53+
54+
The Remi repository offers more recent releases of PHP than the Appstream repository, including versions 8.2 and 8.3.
55+
56+
To install the Remi repository, run the following command:
57+
58+
```bash
59+
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
60+
```
61+
62+
Once the Remi repository is installed, enable it by running the following command.
63+
64+
```bash
65+
sudo dnf config-manager --set-enabled remi
66+
```
67+
68+
You can now activate a newer module (PHP 8.3) by entering the following command:
69+
70+
```bash
71+
sudo dnf module enable php:8.3
72+
```
73+
74+
=== "8.9"
75+
76+
Rocky Linux, like its upstream, offers many versions of the language. Some of them have reached the end of their life but are kept to continue hosting historical applications that are not yet compatible with new versions of PHP. Please refer to the [supported versions](https://www.php.net/supported-versions.php) page of the php.net website to choose a supported version.
77+
78+
To obtain a list of available versions, simply enter the following command:
79+
80+
```bash { .sh data-copy="sudo dnf module list php" }
81+
$ sudo dnf module list php
82+
83+
Rocky Linux 8 - AppStream
84+
Name Stream Profiles Summary
85+
php 7.2 [d] common [d], devel, minimal PHP scripting language
86+
php 7.3 common [d], devel, minimal PHP scripting language
87+
php 7.4 common [d], devel, minimal PHP scripting language
88+
php 8.0 common [d], devel, minimal PHP scripting language
89+
90+
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
91+
```
92+
93+
Rocky provides, from its AppStream repository, different PHP modules.
94+
95+
You will note that the default version of a Rocky 8.9 is 7.2 that has already reached its end of life at the time of writing.
96+
97+
You can activate a newer module by entering the following command:
98+
99+
```bash { .sh data-copy="sudo dnf module enable php:8.0" }
100+
sudo dnf module enable php:8.0
101+
==============================================================================================
102+
Package Architecture Version Repository Size
103+
==============================================================================================
104+
Enabling module streams:
105+
httpd 2.4
106+
nginx 1.14
107+
php 8.0
108+
109+
Transaction Summary
110+
==============================================================================================
111+
112+
Is this ok [y/N]:
113+
114+
Transaction Summary
115+
==============================================================================================
116+
117+
Is this ok [y/N]: y
118+
Complete!
119+
```
120+
87121
You can now proceed to the installation of the PHP engine.
88122

89123
## PHP cgi mode
@@ -96,20 +130,59 @@ The installation of PHP is relatively trivial, since it consists of installing t
96130

97131
The example below installs PHP with the modules usually installed with it.
98132

133+
!!! Note
134+
135+
To avoid installing weak dependencies such as php-fpm use the following flag with dnf `--setopt=install_weak_deps=false`
136+
99137
```bash
100-
sudo dnf install php php-cli php-gd php-curl php-zip php-mbstring
138+
sudo dnf install php php-cli php-gd php-curl php-zip php-mbstring php-mysqlnd
101139
```
102140

103-
You can check that the installed version corresponds to the expected one:
141+
During installation you will be prompted to import GPG keys for the epel9 (Extra Packages for Enterprise Linux 9) and Remi repositories, enter y to import the keys:
104142

105-
```bash
106-
$ php -v
107-
PHP 7.4.19 (cli) (built: May 4 2021 11:06:37) ( NTS )
108-
Copyright (c) The PHP Group
109-
Zend Engine v3.4.0, Copyright (c) Zend Technologies
110-
with Zend OPcache v7.4.19, Copyright (c), by Zend Technologies
143+
```bash
144+
Extra Packages for Enterprise Linux 9 - x86_64
145+
Importing GPG key 0x3228467C:
146+
Userid : "Fedora (epel9) <[email protected]>"
147+
Fingerprint: FF8A D134 4597 106E CE81 3B91 8A38 72BF 3228 467C
148+
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9
149+
Is this ok [y/N]: y
150+
Key imported successfully
151+
Remi's RPM repository for Enterprise Linux 9 - x86_64
152+
Importing GPG key 0x478F8947:
153+
Userid : "Remi's RPM repository (https://rpms.remirepo.net/) <[email protected]>"
154+
Fingerprint: B1AB F71E 14C9 D748 97E1 98A8 B195 27F1 478F 8947
155+
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el9
156+
Is this ok [y/N]: y
157+
Key imported successfully
158+
Running transaction check
159+
Transaction check succeeded.
160+
Running transaction test
161+
Transaction test succeeded.
162+
163+
Complete!
111164
```
112165
166+
You can check that the installed version corresponds to the expected one:
167+
168+
=== "9.0"
169+
```bash { .sh data-copy="php -v" }
170+
$ php -v
171+
PHP 8.3.2 (cli) (built: Jan 16 2024 13:46:41) (NTS gcc x86_64)
172+
Copyright (c) The PHP Group
173+
Zend Engine v4.3.2, Copyright (c) Zend Technologies
174+
with Zend OPcache v8.3.2, Copyright (c), by Zend Technologies
175+
```
176+
177+
=== "8.9"
178+
```bash { .sh data-copy="php -v" }
179+
$ php -v
180+
PHP 7.4.19 (cli) (built: May 4 2021 11:06:37) ( NTS )
181+
Copyright (c) The PHP Group
182+
Zend Engine v3.4.0, Copyright (c) Zend Technologies
183+
with Zend OPcache v7.4.19, Copyright (c), by Zend Technologies
184+
```
185+
113186
### Configuration
114187
115188
#### Apache integration
@@ -125,15 +198,20 @@ sudo dnf install httpd
125198
* Activation:
126199
127200
```bash
128-
sudo systemctl enable httpd
129-
sudo systemctl start httpd
130-
sudo systemctl status httpd
201+
sudo systemctl enable --now httpd
202+
```
203+
204+
```bash { .sh data-copy="sudo systemctl status httpd" }
205+
$ sudo systemctl status httpd
131206
```
132207
133208
* Don't forget to configure the firewall:
134209
135210
```bash
136211
sudo firewall-cmd --add-service=http --permanent
212+
```
213+
214+
```bash
137215
sudo firewall-cmd --reload
138216
```
139217
@@ -168,9 +246,11 @@ sudo dnf install php-fpm
168246
As php-fpm is a service from a system point of view, it must be activated and started:
169247
170248
```bash
171-
sudo systemctl enable php-fpm
172-
sudo systemctl start php-fpm
173-
sudo systemctl status php-fpm
249+
sudo systemctl enable --now php-fpm
250+
```
251+
252+
```bash { .sh data-copy="sudo systemctl status php-fpm" }
253+
$ sudo systemctl status php-fpm
174254
```
175255
176256
### Configuration
@@ -189,7 +269,7 @@ daemonize = yes
189269
190270
The php-fpm configuration files are widely commented. Go and have a look!
191271
192-
As you can see, the files in the `/etc/php-fpm/` directory with the `.conf` extension are always included.
272+
As you can see, the files in the `/etc/php-fpm.d/` directory with the `.conf` extension are always included.
193273
194274
By default, a PHP process pool, named `www`, is declared in `/etc/php-fpm.d/www.conf`.
195275
@@ -286,23 +366,38 @@ PHP-FPM offers, like Apache and its `mod_status` module, a page indicating the s
286366
To activate the page, setup its access path via the `pm.status_path` directive:
287367
288368
```bash
289-
pm.status_path = /status
369+
pm.status_path = /fpm-status
370+
```
371+
372+
You must also add the following vhost to your apache configuration file in /etc/httpd/httpd.conf
373+
374+
```bash
375+
<LocationMatch "/fpm-status">
376+
Require local
377+
ProxyPass "unix:/var/run/php-fpm/www.sock|fcgi://localhost/"
378+
</LocationMatch>
379+
```
380+
381+
After editing the php and apache conf files you will need to restart php-fpm and httpd before the changes take place.
382+
383+
```bash
384+
sudo systemctl restart php-fpm && sudo systemctl restart httpd
290385
```
291386
292387
```bash
293-
$ curl http://localhost/status_php
388+
curl http://localhost/fpm-status
294389
pool: www
295390
process manager: dynamic
296-
start time: 03/Dec/2021:14:00:00 +0100
297-
start since: 600
298-
accepted conn: 548
391+
start time: 25/Jan/2024:19:30:59 +0000
392+
start since: 18447
393+
accepted conn: 10
299394
listen queue: 0
300-
max listen queue: 15
301-
listen queue len: 128
302-
idle processes: 3
303-
active processes: 3
395+
max listen queue: 0
396+
listen queue len: 0
397+
idle processes: 4
398+
active processes: 1
304399
total processes: 5
305-
max active processes: 5
400+
max active processes: 1
306401
max children reached: 0
307402
slow requests: 0
308403
```

0 commit comments

Comments
 (0)