Build lnmp environment in Ubuntu and lnmp in ubuntu
1. Install nginx
Install
Sudo apt-get install nginx
Service start, stop, and restart
/Etc/init. d/nginx start
/Usr/sbin/nginx-c/etc/nginx. conf
/Etc/init. d/nginx stop
/Etc/init. d/nginx restart
Configuration File
/Etc/nginx. conf
Ii. Install MySQL
Installing mysql in Ubuntu is relatively simple.
1. Install the mysql server
Apt-get install mysql-server
During installation, you need to enter the password of the root user.
2. Install the mysql client
Apt-get install mysql-client
3. After installation, you generally need to reset the character set.
1) view the current encoding: show variables like 'character % ';
2) modify my. cnf and add default-character-set = utf8 under [client ].
Command: vi/etc/mysql/my. cnf
3) add default-character-set = utf8, init_connect = 'set NAMES utf8; 'under [server ;'
4) Restart mysql
/Etc/init. d/mysql restart
3. install php
Apt-get install php5-cgi php5-fpm php5-curl php5-gd php5-mysql php5-mcrypt php5-redis
Iv. Configuration
1. configuration files and log files
/Etc/php5/fpm/php. ini php. ini configuration file
/Etc/php5/fpm/php-fpm.conf php-fpm Process Management Master configuration file
/Etc/php5/fpm/pool. d/www. conf php-fpm process pool configuration file
/Var/log/php5-fpm.log php-fpm Error log
/Var/log/php_errors.log php Error log
/Etc/nginx. conf main configuration file
/Etc/nginx/sites-available/default Virtual Host
/Var/log/nginx/access. log nginx access log
/Var/log/nginx/error. log nginx error log
2. php5-fpm Configuration Optimization
/Etc/php5/fpm/pool. d/www. conf
The meanings of the following four parameters are:
Pm. max_children: Number of php-fpm processes enabled in static mode.
Pm. start_servers: number of initial php-fpm processes in dynamic mode.
Pm. min_spare_servers: the minimum number of php-fpm processes in dynamic mode.
Pm. max_spare_servers: Maximum number of php-fpm processes in dynamic mode.
Note: For VPS with a memory of MB, we recommend that you set the following parameters for your reference only:
Pm = dynamic
Pm. max_children = 20
Pm. start_servers = 5
Pm. min_spare_servers = 5
Pm. max_spare_servers = 20
3. nginx Configuration
/Etc/nginx/sites-available/default
Configure and execute the php script on the server node
Location ~ \. Php $ {
# With php5-cgi alone:
# Fastcgi_pass 127.0.0.1: 9000;
# With php5-fpm:
Fastcgi_pass unix:/var/run/php5-fpm.sock;
Fastcgi_index index. php;
Include fastcgi_params;
}
4. php Error Log
/Etc/php5/fpm/php. ini
Log_errors = On
Error_log =/var/log/php_errors.log
5. Restart php-fpm and nginx
Sudo/etc/init. d/php5-fpm restart
Sudo/etc/init. d/nginx restart