Amazon EC2 + PHP-fpm + Nginx
- From the sandbox
- Tutorial
The moment came when I decided to transfer my FastCGI project, I did not need performance, I did not need stability or any other advantages that FastCGI provides. First of all, it was a desire to learn something new, to understand how it works, and to see all the advantages in business.
After reading a large amount of information found on the Internet, I opted for php-fpm + Nginx.
Why exactly this bunch, well, firstly because the project is written in php, and secondly, it is the informal standard on the network.
First of all, I re-read a huge amount of information found in search engines, and everywhere it was almost the same, download php, patch php-fpm, make, make install, the solution is quite understandable but not quite right for the OS with package management systems.
Therefore, I found a solution using the package manager, which I will give below.
All the manipulations were carried out by me on Amazon EC2 micro with the installed Amazon Linux x64 OS, therefore I will describe all the manipulations for this system. For other systems, everything and package managers are almost identical.
Installing nginx:
Installing php (I didn’t need it because Apache + php worked for me):
Installing php-fpm:
After installation, I need a little setup.
Configuring nginx to work with php-fpm, the configuration file is located /etc/nginx/nginx.conf:
The whole configuration comes down to adding the following text inside the "location" section. She will also remember to fix the port on which the service works if you, like I, will initially install it on a system with an already running Apache web server.
To start the bundle in the standard settings mode, you do not need to change anything in the configuration file (/etc/php-fpm.conf). All configuration parameters are well described in the file itself, you can also see here .
When the settings are completed, we proceed to launch, here it is still easier Testing, comparing apache + php and nginx + php-fpm, I will not give here because this is an article about tuning. I will express here only my subjective opinion nginx + php-fpm does not work much faster than apache + php.
After reading a large amount of information found on the Internet, I opted for php-fpm + Nginx.
Why exactly this bunch, well, firstly because the project is written in php, and secondly, it is the informal standard on the network.
First of all, I re-read a huge amount of information found in search engines, and everywhere it was almost the same, download php, patch php-fpm, make, make install, the solution is quite understandable but not quite right for the OS with package management systems.
Therefore, I found a solution using the package manager, which I will give below.
All the manipulations were carried out by me on Amazon EC2 micro with the installed Amazon Linux x64 OS, therefore I will describe all the manipulations for this system. For other systems, everything and package managers are almost identical.
Component Installation
Installing nginx:
sudo yum install nginx
Installing php (I didn’t need it because Apache + php worked for me):
sudo yum install php
Installing php-fpm:
sudo yum install php-fpm
After installation, I need a little setup.
Configuring nginx to work with php-fpm, the configuration file is located /etc/nginx/nginx.conf:
The whole configuration comes down to adding the following text inside the "location" section. She will also remember to fix the port on which the service works if you, like I, will initially install it on a system with an already running Apache web server.
location ~ \.php$ {
#root ;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
To start the bundle in the standard settings mode, you do not need to change anything in the configuration file (/etc/php-fpm.conf). All configuration parameters are well described in the file itself, you can also see here .
Launch
When the settings are completed, we proceed to launch, here it is still easier Testing, comparing apache + php and nginx + php-fpm, I will not give here because this is an article about tuning. I will express here only my subjective opinion nginx + php-fpm does not work much faster than apache + php.
sudo service php-fpm start
sudo service nginx start