The configuration of the LNMP environment requires that our host supports Nginx, MySQL, PHP, and phpMyAdmin. After configuration, we can directly use this environment and run the website on it. I will 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
-
-
Copy code
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
-
-
Copy code
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
-
-
Copy code
The above command installs the php5-memcache extension, so continue to install Memcached.
-
- apt-get install memcached
-
-
Copy code
After installation, use php5-fpm -v to check the PHP version:
-
-
- root@ztbox:~# php5-fpm -v
-
Copy code
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
-
-
Copy code
Then start Nginx:
The access result is as shown above. Next, configure Nginx.
-
- vim /etc/nginx/sites-available/default
-
-
Copy code
……
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:
Next we create a new phpinfo to view the detailed information of php:
-
- vim /usr/share/nginx/html/phpinfo.php
-
-
-
Copy code
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.
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 ;
-
- #Default home page file name
- index index.php index.html index.htm;
-
- #Bind domain name
- server_name localhost;
-
- #Pseudo-static rules
- include wordpress.conf;
-
- location / {
- try_files $ uri $uri/ /index.html;
- }
- #Define error page
- #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
- }
-
-
Copy code
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 the 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 the 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%3D$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;
|