Skip to content

Instantly share code, notes, and snippets.

@angeloh
Forked from philihp/nginx.conf
Created July 14, 2016 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angeloh/4d71df6fb7940afababb0cd31d4de76b to your computer and use it in GitHub Desktop.
Save angeloh/4d71df6fb7940afababb0cd31d4de76b to your computer and use it in GitHub Desktop.
Install PHP-FPM, Nginx & MySQL on EC2 with Amazon Linux AMI
# Install linux update, followed by GCC and Make
sudo yum -y update
sudo yum install -y gcc make
# Install Nginx and PHP-FPM
sudo yum install -y nginx php56-fpm
# Install PHP extensions
sudo yum install -y php56-devel php56-mysql php56-pdo \
php56-pear php56-mbstring php56-cli php56-odbc \
php56-imap php56-gd php56-xml php56-soap
# Install PHP-APC
sudo yum install -y php56-pecl-apc
# Install MySQL
sudo yum -y install mysql-server mysql
# Nginx Configuration
sudo vi /etc/nginx/nginx.conf
# PHP-FPM Configuration
sudo vi /etc/php-fpm.d/www.conf
# MySQL Configuration
sudo mysql_secure_installation
# Autostart Nginx, PHP-FPM and MySQL
sudo chkconfig nginx on
sudo chkconfig mysqld on
sudo chkconfig php-fpm on
sudo service nginx start
sudo service mysqld start
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html
# Set a MySQL password, and press "Y" a lot.
sudo mysql_secure_installation
sudo groupadd www
sudo usermod -a -G www ec2-user
sudo chown -R root:www /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} +
find /var/www -type f -exec sudo chmod 0664 {} +
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
# Find the place in nginx.conf and make it this:
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;
}
sudo yum install nodejs npm --enablerepo=epel
[...]
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock
;listen.owner = nobody
listen.owner = nginx
;listen.group = nobody
listen.group = nginx
;listen.mode = 0666
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