GIT – A step by step tutorial on installing and configuring PHP-FPM, Nginx, & MySQL on an Amazon EC2 instance running Amazon Linux AMI. The procedure has been tested on Amazon Linux AMI, but should also apply in general to Fedora/Red Hat/CentOS distributions. A brief introduction to FastCGI, PHP-FPM, and Nginx was posted in the article Understanding PHP, PHP-FPM and Nginx. Should you be interested in simply installing Apache, PHP, APC, and MySQL on Amazon or CentOS Linux, please follow the tutorial here.
1. Install Linux updates, set time zones, followed by GCC and Make
sudo yum -y update sudo ln -sf /usr/share/zoneinfo/America/Indianapolis \ /etc/localtime sudo yum install -y gcc make
2. Install Nginx and PHP-FPM
sudo yum install -y nginx php-fpm
3. Install PHP extensions
sudo yum install -y php-devel php-mysql php-pdo \ php-pear php-mbstring php-cli php-odbc \ php-imap php-gd php-xml php-soap
4. Install PHP-APC
sudo yum install -y php-pecl-apc
sudo yum install -y pcre-devel
5. Install MySQL
sudo yum -y install mysql-server mysql
6. Nginx Configuration
sudo nano /etc/nginx/conf.d/default.conf
If you want the location of your web root in the default Amazon Linux AMI directory (/var/www/html):
location / { root /var/www/html; index index.php index.html index.htm; } location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/ html$fastcgi_script_name; include fastcgi_params; }
If you want the location of your web root in the default Nginx directory (/usr/share/nginx/html):
location / { root /usr/share/nginx/html; index index.php index.html index.htm; } location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/ html$fastcgi_script_name; include fastcgi_params; }
7. PHP-FPM Configuration
sudo nano /etc/php-fpm.d/www.conf
[...] ;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 [...]
8. Auto Start Nginx, PHP-FPM, and MySQL in EC2 Amazon Linux
sudo chkconfig nginx on sudo chkconfig mysqld on sudo chkconfig php-fpm on
9. Auto Start Nginx, PHP-FPM, and MySQL in EC2 Amazon Linux
sudo service php-fpm start sudo service nginx start
No Comment