Servidor Web com NGINX — Instalação e configuração do PHP em sistemas baseados em RHEL

Photo by ThisIsEngineering from Pexels

Instalação

sudo dnf install php-fpm php-mysqli php-cli

Configuração

sudo nano /etc/php-fpm.d/www.conf

Diretivas user e group


; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

Diretivas listen.owner e listen.group

listen.owner = nginx
listen.group = nginx
listen.mode = 0660

Diretivas de sessões

php_value[session.save_path] = /tmp

Exibição de erros e alertas

php_flag[display_errors] = on
sudo systemctl start php-fpm

Habilitando conexões externas (cURL)

sudo setsebool -P httpd_can_network_connect on

Configurando NGINX para processar requisições PHP

sudo nano /etc/nginx/conf.d/example.com.conf
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
index index.php index.html;
root /var/www/example.com;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
sudo systemctl restart nginx

O PHP está devidamente instalado e configurado!

--

--

Desenvolvedor Front-end e UI/UX Designer.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Marcelo Albuquerque

Marcelo Albuquerque

Desenvolvedor Front-end e UI/UX Designer.