Last active
August 20, 2024 20:36
-
-
Save nrollr/56e933e6040820aae84f82621be16670 to your computer and use it in GitHub Desktop.
Install PHP and NGINX on Amazon Linux AMI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Install NGINX | |
## when installing on Amazon Linux AMI, use: | |
$ sudo yum install nginx -y | |
## when installing on Amazon Linux 2 AMI, use | |
$ sudo amazon-linux-extras install nginx1.12 -y | |
## Install PHP and PHP-FPM | |
# for PHP version 7.1 use php71 and php71-fpm instead | |
$ sudo yum install php -y | |
$ sudo yum install php-fpm -y | |
## Configure NGINX (see below) | |
$ sudo nano /etc/nginx/conf.d/default.conf | |
## Configure PHP-FPM (see below) | |
$ sudo nano /etc/php-fpm.d/www.conf | |
## 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 <file>.php to /var/www/html | |
## Verify configuration via http://www.domain.com/<file>.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
listen [::]:80; | |
server_name www.domain.com domain.com; | |
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Config associated with PHP-FPM version 7.1 | |
## Comment out the following entries (with ;) | |
;listen.acl_users = apache,nginx | |
;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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
nginx1.12
topic is WAY outdated (and marked as such by the amazon-linux-extras command, if you have the topic enabled. It's hidden if you don't). Use the topicnginx1
instead.