Hero Image

PHP and NGINX on Amazon Linux AMI

Install NGINX

sudo yum install nginx -y

Install PHP and PHP-FPM

sudo yum install php -y
sudo yum install php-fpm -y

Configure NGINX (see below)

sudo nano /etc/nginx/conf.d/default.conf
server {
    listen 80;
    server_name www.exampledomain.tld exampledomain.tld;

    location / {
        root   /var/www/html;
        index  index.php index.html index.htm;
    }

    location ~ \.php$ {
        root /var/www/html;
        fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

Configure PHP-FPM (see below)

sudo nano /etc/php-fpm.d/www.conf
Comment the following entries (with ;)
;listen = 127.0.0.1:9000
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0666
;user = apache
;group = apache

# Add the following values instead
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0664
user = nginx
group = nginx

Add NGINX and PHP-FPM service start to boot sequence

sudo chkconfig nginx on
sudo chkconfig php-fpm on

Start NGINX and PHP-FPM service

sudo service nginx start
sudo service php-fpm start

Add test.php to /var/www/html

<?php phpinfo();?>

Verify configuration via http://www.exampledomain.tld/test.php

Other Related Posts:

Get back PHP7.4 on FreeBSD

Recently freebsd did drop (reason: eol) php7.4 support in FreeBSD and it is not available via packages or latest ports anymore. This guide will get back php7.4 from ports using help of git commit log. Last ports php7.4 related (update to php 7.4.33) commit was in git 27ac371f93d36f77f00b8da261e496...

Read more

17th Jan 2023