Instale a extensão Nginx e FPM PHP em seu sistema.
sudo yum install vim nginx php-fpm -y
Inicie e ative os serviços nginx e php-fpm.
$ sudo systemctl enable --now nginx php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
Confirme o status dos serviços iniciados.
$ systemctl status nginx php-fpm
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2023-01-20 12:20:26 UTC; 19s ago
Process: 8645 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 8642 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 8640 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 8647 (nginx)
CGroup: /system.slice/nginx.service
├─8647 nginx: master process /usr/sbin/nginx
├─8648 nginx: worker process
└─8649 nginx: worker process
Jan 20 12:20:26 cent7.mylab.io systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 20 12:20:26 cent7.mylab.io nginx[8642]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 20 12:20:26 cent7.mylab.io nginx[8642]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 20 12:20:26 cent7.mylab.io systemd[1]: Started The nginx HTTP and reverse proxy server.
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2023-01-20 12:20:26 UTC; 19s ago
Main PID: 8641 (php-fpm)
Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
CGroup: /system.slice/php-fpm.service
├─8641 php-fpm: master process (/etc/php-fpm.conf)
├─8650 php-fpm: pool www
├─8651 php-fpm: pool www
├─8652 php-fpm: pool www
├─8653 php-fpm: pool www
└─8654 php-fpm: pool www
Jan 20 12:20:26 cent7.mylab.io systemd[1]: Starting The PHP FastCGI Process Manager...
Configure o PHP-FPM para escutar em um soquete em vez de IP e porta. Abra o arquivo e faça as seguintes modificações.
$ sudo vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
Reinicie o serviço php-fpm após as alterações serem feitas.
sudo systemctl restart php-fpm
Exemplo de configuração do VirtualHost:
$ sudo vim /etc/nginx/nginx.conf
server {
listen 80;
server_name myapp.example.com;
root /var/www/myapp;
index index.php index.html;
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm.sock;
}
}
Valide suas configurações do nginx.
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful