About LEMP
The LEMP architecture is a group of widely used open-source software packages for WEB servers, which correspond to Linux, nginx (pronounced Engine x), MySQL, and PHP respectively. Because it is based on Centos 6, we do not need to consider the linux part, but only need to install the remaining components.
Step 1 install required software sources
We will install all the software we need through yum. However, because nginx cannot be obtained from the default software source, I must install the epel software source.
Sudo yum install epel-release
Step 2 install Mysql
The next step is to install various software. First, we start with MySQL and its dependencies.
Sudo yum install mysql-server
Once the installation process is complete, restart MySQL:
Sudo/etc/init. d/mysqld restart
You can use the following command to complete some MySQL security configurations
Sudo/usr/bin/mysql_secure_installation
As prompted, you will be asked to enter the current root password. Because you have just installed MySQL and have not set any password, press enter to skip it.
Enter current password for root (enter for none ):
OK, successfully used password, moving on...
Then you will be asked if you want to set the root password. Enter y to complete the password setting process as prompted.
CentOS automatically handles your MySQL configuration by asking you a series of Yes or No problems.
In most cases, you only need to input Y all the time. At last, MySQL restarts to apply the new configuration.
Step 3 install nginx
Like MySQL, we will install nginx in Centos 6 through yum:
Sudo yum install nginx
Run the following command to start nginx:
Sudo/etc/init. d/nginx start
You can access your server by IP address to check whether nginx is correctly installed.
Step 4 install PHP
Php-fpm is in the REMI source, so we must first enable the REMI source, and then install PHP and php-fpm.
Sudo yum -- enablerepo = remi install php-fpm php-mysql php-cli php-mcrypt
Step 5 configure PHP
We will change the minor points in the PHP configuration file:
Sudo vi/etc/php. ini
Find the line "cgi. fix_pathinfo = 1" and change 1 to 0.
Cgi. fix_pathinfo = 0
If this option is set to 1, a dangerous vulnerability is introduced. We recommend that you disable this function.
Step 6 Configure nginx
Open the nginx configuration file:
Sudo vim/etc/nginx. conf
Add worker processes to 4 and save and exit.
Now we need to configure a static host for nginx.
To make the default configuration file clearer, the default static host configuration file is in another file:
Sudo vi/etc/nginx/conf. d/default. conf
Edit the configuration file as follows:
#
# The default server
#
Server {
Listen 80;
Server_name example.com;
Location /{
Root/usr/share/nginx/html;
Index. php index.html index.htm;
}
Error_page 404/404 .html;
Location =/404.html {
Root/usr/share/nginx/html;
}
Error_page 500 502 503 x.html;
Location =/50x.html {
Root/usr/share/nginx/html;
}
# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ \. Php $ {
Root/usr/share/nginx/html;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Include fastcgi_params;
}
}
Open the configuration file of php-fpm
Sudo vi/etc/php-fpm.d/www. conf
Change the values of 'user' and 'group' from 'Apache' to 'nginx ':
[...]
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; Will be used.
; RPM: apache Choosed to be able to access some dir as httpd
User = nginx
; RPM: Keep a group allowed to write in log dir.
Group = nginx
[...]
Restart php-fpm
Sudo service php-fpm restart