📜 ⬆️ ⬇️

Amazon EC2 + PHP-fpm + Nginx

The moment came when I decided to transfer my FastCGI project, I didn’t need performance, I didn’t need stability or any other advantages provided by FastCGI. First of all, it was the desire to learn something new, understand how it works, and see all the advantages in business.
After reading a lot of information found on the Internet, I made a choice in favor of php-fpm + Nginx.
Why this bundle, well, firstly because the project is written in php, secondly, it is she who is the informal standard on the network.

First of all, I reread a huge pile of information found in search engines, and everywhere it was almost the same thing, download php, put a 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 performed by me on Amazon EC2 micro with the installed operating system Amazon Linux x64, so I will describe all the manipulations for this system. For all other systems, everything and package managers are almost identical.
')
Component installation

Install nginx:
sudo yum install nginx

Installing php (I didn’t need it because Apache + php worked for me):
sudo yum install php

Install php-fpm:
sudo yum install php-fpm

After installation, you need a little tweaking.

Configure nginx to work with php-fpm, the configuration file is /etc/nginx/nginx.conf:
All configuration is to add the following text inside the “location” section. Do not forget to also fix the port on which the service works if you, like me, 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 run 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 look in addition here .
Launch

When the settings are complete go to launch, it's still easier
sudo service php-fpm start
sudo service nginx start


Testing, comparing apache + php and nginx + php-fpm, I will not give here because it is an article about setting up. I will express here only my subjective opinion. Nginx + php-fpm does not work much faster than apache + php.

Source: https://habr.com/ru/post/134181/


All Articles