The configuration of the LNMP environment requires that our host supports Nginx, MySQL, PHP, and phpMyAdmin. After configuration, you can Use this environment directly and run the website on it. Let me configure the method below.
Let’s take a look at the official description first
LNMP one-click installation package is a Shell program written in Linux Shell that can install LNMP (Nginx, MySQL, PHP, phpMyAdmin) production environment for CentOS/RadHat, Debian/Ubuntu VPS (VDS) or independent host
1. Install MySQL
Execute command:
apt-get install -y mysql-server mysql-client
You can install MySQL. During the installation process, you will be asked for the root password. Type in the password you need and press Enter.
After the installation is complete, execute the following command to perform one-step security settings:
mysql_secure_installation
Follow the prompts. During the process, you will be asked whether to change the root password, whether to remove anonymous users, whether to prohibit root remote login, etc.
2. Install PHP
Execute command:
apt-get install php5-fpm php5-gd php5-mysql php5-memcache php5-curl
The above command installs the php5-memcache extension, so continue to install Memcached.
apt-get install memcached
After installation, use php5-fpm -v to check the PHP version:
root@ztbox:~# php5-fpm -v
PHP 5.4.16-1~dotdeb.1 (fpm-fcgi) (built: Jun 8 2013 22:20:42)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
3. Install Nginx
Here I directly installed all the extension functions of Nginx (nginx-full) to cope with possible functional enhancements in the future.
apt-get install -y nginx-full
Then start Nginx:
service nginx start
The access result is as shown above. Next, configure Nginx.
vim /etc/nginx/sites-available/default
……
Location ~ .php$ {
fastcgi_split_path_info ^(. .php)(/. )$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # 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;
}
…
Restart Nginx after saving the changes:
service nginx restart
Next we create a new phpinfo to view the detailed information of php:
vim /usr/share/nginx/html/phpinfo.php <?php phpinfo(); ?>
After saving, visit http://ip/phpinfo.php. If the phpinfo page appears, you are done.
How to create a new site
Different from Jun Ge’s one-click package, the LNMP installed by this method requires manual addition of site configuration files.
cd /etc/nginx/conf.d
Enter the configuration file directory and create a new site configuration file, such as
vi dearroy.com.conf server { listen 80; #ipv6 #listen [::]:80 default_server; root /usr/share/nginx/html/dearroy.com; #默认首页文件名 index index.php index.html index.htm; #绑定域名 server_name localhost; #伪静态规则 include wordpress.conf; location / { try_files $uri $uri/ /index.html; } #定义错误页面 #error_page 404 /404.html; location ~ .php$ { fastcgi_split_path_info ^(.+.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; } #PHP }
After saving, restart Nginx, and adding and binding the website is complete.
Finally, here are the two most commonly used programs, Nginx pseudo-static:
WordPress:
Copy code The code is as follows: location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
Discuz X:
Copy code The code is as follows: rewrite ^([^.]*)/topic-(. ).html$ $1/portal.php?mod=topic&topic=$2 last ;
rewrite ^([^.]*)/article-([0-9] )-([0-9] ).html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
rewrite ^([^.]*)/forum-(w )-([0-9] ).html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
rewrite ^([^.]*)/thread-([0-9] )-([0-9] )-([0-9] ).html$ $1/forum.php?mod=viewthread&tid=$2&extra =page=$4&page=$3 last;
rewrite ^([^.]*)/group-([0-9] )-([0-9] ).html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
rewrite ^([^.]*)/space-(username|uid)-(. ).html$ $1/home.php?mod=space&$2=$3 last;
rewrite ^([^.]*)/([a-z] )-(. ).html$ $1/$2.php?rewrite=$3 last;
if (!-e $request_filename) {
Return 404;