Tutorial on configuring LNMP under Debian system

WBOY
Release: 2016-07-25 08:44:57
Original
837 people have browsed it

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:

  1. 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:

  1. 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:

  1. 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.

  1. apt-get install memcached
Copy code

After installation, use php5-fpm -v to check the PHP version:

  1. 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.

  1. apt-get install -y nginx-full
Copy code

Then start Nginx:

  1. service nginx start
Copy code

The access result is as shown above. Next, configure Nginx.

  1. 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:

  1. service nginx restart
Copy code

Next we create a new phpinfo to view the detailed information of php:

  1. 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.

  1. cd /etc/nginx/conf.d
Copy code

Enter the configuration file directory and create a new site configuration file, such as

  1. vi dearroy.com.conf
  2. server {
  3. listen 80;
  4. #ipv6
  5. #listen [::]:80 default_server;
  6. root /usr/share/nginx/html/dearroy.com ;
  7. #Default home page file name
  8. index index.php index.html index.htm;
  9. #Bind domain name
  10. server_name localhost;
  11. #Pseudo-static rules
  12. include wordpress.conf;
  13. location / {
  14. try_files $ uri $uri/ /index.html;
  15. }
  16. #Define error page
  17. #error_page 404 /404.html;
  18. location ~ .php$ {
  19. fastcgi_split_path_info ^(.+.php)(/.+)$;
  20. fastcgi_pass 127.0.0.1:9000;
  21. fastcgi_index index.php;
  22. include fastcgi_params;
  23. }
  24. #PHP
  25. }
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;

Debian, LNMP


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template