LNMP Platform Construction and website construction

Source: Internet
Author: User
Tags epoll fpm php error nginx server zend

First, Nginx service base
Nginx is specifically developed for performance optimization, and its best-known advantages are his stability and low system resource consumption, as well as the high processing power of HTTP concurrent links.
1. Install the Pcre.zlib Development Kit to provide the appropriate library and header files
Yum-y Install Pcre-devel Zlib-devel
2. Create a running user, group
Useradd-m-s/sbin/nologin Nginx #nginx默认以nobody身份运行, it is recommended to create a dedicated user account, do not establish a home folder, prohibit login to the shell environment
3. Compile and install Nginx
[Email protected] ~]# tar zxf nginx-1.13.7.tar.gz-c/usr/src

./configure--help View specific configuration options, according to the actual situation to develop



Due to changes in the system's date and time, resulting in inconsistent system current time and kernel system time
Update kernel time to current time
Hwclock--hctosys

Solve
4. Create a soft connection for easy use
Ln-s/usr/local/nginx/sbin/nginx/usr/local/sbin

Operation Control of 5.Nginx
Nginx-t #检查配置文件是否正确
You can add the-C option to check other configuration files
Nginx #启动服务



Test Connection Success
Killall-s HUP Nginx #重启nginx服务
Killall-s QUIT Nginx #停止nginx服务
When Nginx is running, the PID number is stored in the Nginx.pid file in the logs/directory, and can also be controlled by PID process number.
Write shell scripts to control with Chkconfig,service


This allows you to use a script to start stopping the restart of the overloaded Nginx server.
Second, the configuration file nginx.conf
The nginx.conf file contains a three-part configuration, namely global configuration, I/O event configuration, and HTTP configuration
1. Global configuration
#user nobody; Run user defaults to nobody, the user has been specified at the time of configuration
Worker_processes 1; Number of working processes, which can be specified according to the total number of CPU cores
#error_log the location of the logs/error.log;//error log file
#pid Logs/nginx.pid; The location of the PID file

2.I/O Event Configuration
Events {
Use Epoll//using Epoll model
Worker_connections 4096; Each process processes 4,096 process connections, typically under 10000
}
Nginx Service provides the number of connections to work by multiplying the number of connections provided by each process

3.HTTP configuration for completing Web site Settings


3.1 Turn on Status statistics test


See if the configuration file is correct nginx-t
Test

Active connections indicates the current number of active connections
Server accepts handled requests represents the number of connections processed, number of successful TCP handshakes, requests processed

Third, configure the domain-based virtual host
Modify the server in the configuration file, a group of servers representing a Web site
1. Create Site Directory and home page file

2. Modify the configuration file nginx.conf


3. Heavy-duty Nginx service test


Iv. Building LNMP Architecture and application Deployment
1. Install MySQL, refer to http://blog.51cto.com/12879627/2060579
2. Install PHP
PHP has its own fpm (FastCGI Process manager FastCGI) module, which is used to manage PHP parsing instances and optimize parsing efficiency. You need to enable--ENABLE-FPM to enable this module.
1) Compile and install
Yum-y Install GD libxml2-devel libjpeg-devel libpng-devel
Tar zxf php-5.3.28.tar.gz-c/usr/src
cd/usr/src/php-5.3.28/
./configure--prefix=/usr/local/php5--with-gd--with-zlib--with-mysql=/usr/local/mysql--with-config-file-path=/ USR/LOCAL/PHP5--enable-mbstring--enable-fpm--with-jpeg-dir=/usr/lib
Make&&make Install
--prefix: Specifying the installation directory
--WITH-GD--with-zlib: Open the support of Zlib library to open GD library
--with-mysql=/usr/local/mysql:mysql installation directory, support for MySQL
--WITH-CONFIG-FILE-PATH=/USR/LOCAL/PHP5: Specify php.ini location
--enable-mbstring: Multi-byte, string support
--enable-fpm:cgi mode installation Only use parameters, hit the php-fpm patch only after this parameter, CGI installation of the startup program
-with-jpeg-dir=/usr/lib: Turn on support for JPEG images
Yes./configure--help query Options
2) Adjust the configuration file and optimize the use

To copy a template, create a master configuration file
Create soft connections for ease of use
3) Install Zend Guard Loader
R uses optimized code to improve the execution speed of PHP applications. The principle of implementation is to optimize the code that is generated by running the compiler (Run-time Compiler) before it is finally executed. In general, executing PHP programs that use Zend is 40% to 100% faster than unused
Copy the extracted module

    修改php.ini文件,增加以下几项

Configuration error
Failed loading/usr/local/php5/lib/php/zendguardloader.so:/usr/local/php5/lib/php/zendguardloader.so:wrong ELF Class:elfclass32

The reason for the above error is that the 64-bit system uses a 32-bit zendguardloader.so, after replacing the installation package
Resolved, the version needs to match it

3.配置nginx支持php环境有两种让nginx支持php的方法

acts as an intermediary, handing over Web requests that access PHP pages to other servers (lamp) to process
Invoking the native PHP environment by using the PHP fpm module
1) enable the PHP-FPM module
Create a PHP-FPM program user

Modify the php-fpm.conf configuration file to modify the relevant parameters, and then start the PHP-FPM process, php-fpm the default listener 9000 port of the native

PID = run/php-fpm.pid//Verify the location of the PID file
user = PHP//running users
Group = PHP//Run groups
Pm.start_servers = 20//number of processes opened at startup
Pm.min_spare_servers = 5//minimum number of idle processes
Pm.max_spare_servers = 35//maximum number of idle processes
Pm.max_children = 50//maximum number of child processes
Can be run directly php-fpm boot, default port 9000, can also write Nginx service script

Add arrows to indicate that you can start with Nginx

2) Modify Nginx configuration file, support PHP Web Access

3) test access


File not find

Idea: Check the server local access, also no, check the service port, normal, that is, Nginx connection PHP error, modify nginx.conf

Restart Nginx, success

LNMP Platform Construction and website construction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.