Debian10 系统VPS主机LEMP教程

Debian10 系统VPS主机LEMP教程,LEMP 指的是 Linux + Nginx (发音 engine x 所以这里是 E 而不是 N) + MySQL + PHP 的简称,国内有些地方叫做 LNMP (因为 LNMP 没法读出来,而 LEMP 可以直接发音,所以今后本站教程一律都会写 LEMP)。

Debian10 系统VPS主机LEMP教程,LEMP 指的是 Linux + Nginx (发音 engine x 所以这里是 E 而不是 N) + MySQL + PHP 的简称,国内有些地方叫做 LNMP (因为 LNMP 没法读出来,而 LEMP 可以直接发音,所以今后本站教程一律都会写 LEMP)。

VPS主机LEMP教程

以下教程适用于Debian10 系统但是我们尽量推荐使用最新的操作系统,以免旧系统软件版本过低有漏洞的可能

更新库

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
apt update
apt list --upgradable
apt update apt list --upgradable
apt update
apt list --upgradable

安装nginx

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
apt install nginx -y #安装
#nginx 的使用命令
systemctl start nginx #启动
systemctl restart nginx #重启
systemctl stop nginx #停止
systemctl reload nginx #平滑重启
systemctl status nginx #查看状态
apt install nginx -y #安装 #nginx 的使用命令 systemctl start nginx #启动 systemctl restart nginx #重启 systemctl stop nginx #停止 systemctl reload nginx #平滑重启 systemctl status nginx #查看状态
apt install nginx -y        #安装

#nginx 的使用命令
systemctl start nginx       #启动
systemctl restart nginx     #重启
systemctl stop nginx        #停止
systemctl reload nginx      #平滑重启
systemctl status nginx      #查看状态

设置防火墙(阿里云主机,可以忽烈此项)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#接下来,如果您运行UFW防火墙 (默认情况下通常禁用),则需要打开端口80(HTTP)和443(HTTPS)以允许Nginx上的传入流量。
ufw allow 80 #开启80端口
ufw allow 443 #开启443端口
ufw status #查看状态
ufw deny 80 #禁用80端口
#接下来,如果您运行UFW防火墙 (默认情况下通常禁用),则需要打开端口80(HTTP)和443(HTTPS)以允许Nginx上的传入流量。 ufw allow 80 #开启80端口 ufw allow 443 #开启443端口 ufw status #查看状态 ufw deny 80 #禁用80端口
#接下来,如果您运行UFW防火墙 (默认情况下通常禁用),则需要打开端口80(HTTP)和443(HTTPS)以允许Nginx上的传入流量。
ufw allow 80    #开启80端口
ufw allow 443   #开启443端口
ufw status      #查看状态
ufw deny 80     #禁用80端口

在Debian 10上安装MariaDB 。【Debian 10默认支持MariaDB ,作为MySQL的直接替代品。】

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
apt install mariadb-server -y #安装
#mariadb 的使用命令
systemctl status mariadb #查看状态
systemctl start mariadb #启动
systemctl restart mariadb #重启
systemctl stop mariadb #停止
systemctl reload mariadb #平滑重启
apt install mariadb-server -y #安装 #mariadb 的使用命令 systemctl status mariadb #查看状态 systemctl start mariadb #启动 systemctl restart mariadb #重启 systemctl stop mariadb #停止 systemctl reload mariadb #平滑重启
apt install mariadb-server -y   #安装

#mariadb 的使用命令
systemctl status mariadb     #查看状态
systemctl start mariadb      #启动 
systemctl restart mariadb    #重启 
systemctl stop mariadb       #停止 
systemctl reload mariadb     #平滑重启

mariadb 安全设置

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
mysql_secure_installation #执行此命令
#按提示根据实际情况进行设置
Enter current password for root (enter for none): #初次运行直接回车
Set root password? [Y/n] #是否设置root用户密码,输入y并回车或直接回车
New password: #设置root用户的密码
Re-enter new password: #再输入一次你设置的密码
Remove anonymous users? [Y/n] #是否删除匿名用户
Disallow root login remotely? [Y/n] #是否禁止root远程登录
Remove test database and access to it? [Y/n] #是否删除test数据库
Reload privilege tables now? [Y/n] #是否重新加载权限表
#其他设置
mysql #进入mysql
#创建用户命令
mysql>create user 'username'@'localhost' identified by 'password';
#直接创建用户并授权的命令
mysql>grant all on *.* to 'username'@'localhost' indentified by 'password';
#授予外网登陆权限
mysql>grant all privileges on *.* to 'username'@'%' identified by 'password';
#授予权限并且可以授权
mysql>grant all privileges on *.* to 'username'@'hostname' identified by 'password' with grant option;
mysql> show variables like "%character%"; #MariaDB查看字符集
mysql>show variables like "%collation%"; #MariaDB查看字符集
mysql_secure_installation #执行此命令 #按提示根据实际情况进行设置 Enter current password for root (enter for none): #初次运行直接回车 Set root password? [Y/n] #是否设置root用户密码,输入y并回车或直接回车 New password: #设置root用户的密码 Re-enter new password: #再输入一次你设置的密码 Remove anonymous users? [Y/n] #是否删除匿名用户 Disallow root login remotely? [Y/n] #是否禁止root远程登录 Remove test database and access to it? [Y/n] #是否删除test数据库 Reload privilege tables now? [Y/n] #是否重新加载权限表 #其他设置 mysql #进入mysql #创建用户命令 mysql>create user 'username'@'localhost' identified by 'password'; #直接创建用户并授权的命令 mysql>grant all on *.* to 'username'@'localhost' indentified by 'password'; #授予外网登陆权限 mysql>grant all privileges on *.* to 'username'@'%' identified by 'password'; #授予权限并且可以授权 mysql>grant all privileges on *.* to 'username'@'hostname' identified by 'password' with grant option; mysql> show variables like "%character%"; #MariaDB查看字符集 mysql>show variables like "%collation%"; #MariaDB查看字符集
mysql_secure_installation    #执行此命令

#按提示根据实际情况进行设置
Enter current password for root (enter for none):    #初次运行直接回车
Set root password? [Y/n]    #是否设置root用户密码,输入y并回车或直接回车
New password:     #设置root用户的密码
Re-enter new password:   #再输入一次你设置的密码
Remove anonymous users? [Y/n]   #是否删除匿名用户
Disallow root login remotely? [Y/n]   #是否禁止root远程登录
Remove test database and access to it? [Y/n]   #是否删除test数据库
Reload privilege tables now? [Y/n]   #是否重新加载权限表

#其他设置
mysql    #进入mysql

#创建用户命令
mysql>create user  'username'@'localhost' identified by 'password'; 
   
#直接创建用户并授权的命令
mysql>grant all on *.* to 'username'@'localhost' indentified by 'password';    

#授予外网登陆权限 
mysql>grant all privileges on *.* to 'username'@'%' identified by 'password';
    
#授予权限并且可以授权
mysql>grant all privileges on *.* to 'username'@'hostname' identified by 'password' with grant option;

mysql> show variables like "%character%";  #MariaDB查看字符集
mysql>show variables like "%collation%";  #MariaDB查看字符集

在Debian 10上安装PHP , PHP-FPM(快速进程管理器)。

为什么海归不受待见
Debian10 系统VPS主机LEMP教程

Apache和其他Web服务器不同, Nginx不提供对PHP的本机支持,因为它使用PHP-FPM来处理PHP页面的请求。 PHP-FPMPHP的另一种FastCGI守护程序,它允许网站通过使用工作进程处理请求来处理高负载。

要安装PHP-FPM版本7.3和PHP模块以与MariaDB / MySQL数据库系统通信,请运行以下命令。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#安装的时候,可以不带版本号。例如 php7.3 可以直接 php
apt install php php-fpm php-mysqli -y #安装, php/php-fpm/php-mysqli
#php-fpm 的使用命令, 使用的时候,一定要带版本号。debian10 默认是php7.3
systemctl status php7.3-fpm # 查看状态
systemctl start php7.3-fpm # 启动
systemctl restart php7.3-fpm # 重启
systemctl stop php7.3-fpm # 停止
systemctl reload php7.3-fpm # 平滑重启
#安装的时候,可以不带版本号。例如 php7.3 可以直接 php apt install php php-fpm php-mysqli -y #安装, php/php-fpm/php-mysqli #php-fpm 的使用命令, 使用的时候,一定要带版本号。debian10 默认是php7.3 systemctl status php7.3-fpm # 查看状态 systemctl start php7.3-fpm # 启动 systemctl restart php7.3-fpm # 重启 systemctl stop php7.3-fpm # 停止 systemctl reload php7.3-fpm # 平滑重启
#安装的时候,可以不带版本号。例如 php7.3 可以直接 php
apt install php php-fpm php-mysqli -y    #安装, php/php-fpm/php-mysqli


#php-fpm 的使用命令, 使用的时候,一定要带版本号。debian10 默认是php7.3
systemctl status php7.3-fpm        # 查看状态
systemctl start php7.3-fpm         # 启动    
systemctl restart php7.3-fpm       # 重启
systemctl stop php7.3-fpm          # 停止
systemctl reload php7.3-fpm        # 平滑重启

安装php其它插件/扩展

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
apt-get install mcrypt php-redis php-cli php-common php-curl php-gd php-mysql php-opcache php-xml php-xmlrpc php-sqlite3 php-mbstring -y
apt-get install mcrypt php-redis php-cli php-common php-curl php-gd php-mysql php-opcache php-xml php-xmlrpc php-sqlite3 php-mbstring -y
apt-get install mcrypt php-redis php-cli php-common php-curl php-gd php-mysql php-opcache php-xml php-xmlrpc php-sqlite3 php-mbstring -y

接下来,您需要通过在配置文件/etc/php/7.3/fpm/php.ini中进行一些更改来保护PHP-FPM ,如下所示。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
vim /etc/php/7.3/fpm/php.ini
#在 793行处理
;cgi.fix_pathinfo=1
#改为以下内容
cgi.fix_pathinfo=0
vim /etc/php/7.3/fpm/php.ini #在 793行处理 ;cgi.fix_pathinfo=1 #改为以下内容 cgi.fix_pathinfo=0
vim /etc/php/7.3/fpm/php.ini

#在 793行处理
;cgi.fix_pathinfo=1 
#改为以下内容
cgi.fix_pathinfo=0

配置 nginx 与 php 结合

默认情况下, PHP-FPM配置为监听/etc/php/7.3/fpm/pool.d/www.conf配置文件中定义的UNIX soxket /run/php/php7.3-fpm.sock 。 如果要处理和提供PHP页面,则必须配置所有服务器块(或虚拟主机 )以使用此套接字。

您可以使用Nginx默认服务器块配置文件/ etc / nginx / sites-available / default来测试它。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
vim /etc/nginx/sites-available/default
#找到,并去掉以下这几行的注解
location ~ \.php$
{
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}
vim /etc/nginx/sites-available/default #找到,并去掉以下这几行的注解 location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.3-fpm.sock; }
vim /etc/nginx/sites-available/default 

#找到,并去掉以下这几行的注解
location ~ \.php$ 
{
   include snippets/fastcgi-php.conf;
   fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}

接下来,就重启服务

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
systemctl restart php7.3-fpm #重启php
systemctl restart nginx #重启nginx
systemctl restart php7.3-fpm #重启php systemctl restart nginx #重启nginx
systemctl restart php7.3-fpm   #重启php
systemctl restart nginx        #重启nginx

done , 快去写个 phpinfo 测试吧

补充: nginx 配置主机信息如下:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
server {
listen 80;
root /var/www/zounianxiao_memberpay/public;
index index.php index.html index.htm;
server_name 47.119.161.55;
#这里的if , 是针对 thinkphp rewrite 规则的。非thinkphp框架,可以删除
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
}
server { listen 80; root /var/www/zounianxiao_memberpay/public; index index.php index.html index.htm; server_name 47.119.161.55; #这里的if , 是针对 thinkphp rewrite 规则的。非thinkphp框架,可以删除 if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } # pass PHP scripts to FastCGI server # location ~ \.php$ { include snippets/fastcgi-php.conf; # With php-fpm (or other unix sockets): fastcgi_pass unix:/run/php/php7.3-fpm.sock; # # With php-cgi (or other tcp sockets): # fastcgi_pass 127.0.0.1:9000; } }
server {
	listen 80;
	
	root /var/www/zounianxiao_memberpay/public;
        index index.php index.html index.htm;
	server_name 47.119.161.55;
	
	#这里的if , 是针对 thinkphp rewrite 规则的。非thinkphp框架,可以删除
	if (!-e $request_filename){
            rewrite  ^(.*)$  /index.php?s=$1  last;
            break;
   	}	

	# pass PHP scripts to FastCGI server
	#
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
	
		# With php-fpm (or other unix sockets):
		fastcgi_pass unix:/run/php/php7.3-fpm.sock;
	#	# With php-cgi (or other tcp sockets):
	#	fastcgi_pass 127.0.0.1:9000;
	}
}

安全补充:修改php安全设置

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
vim /etc/php/7.3/fpm/php.ini
#disable_functions 增加以下设置。注意是在原来的基础增加。不是替换。不是替换。不是替换。
disable_functions = phpinfo,eval,passthru,exec,system,chroot,chgrp,chown,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,fsockopen,shell_exec,popen,
#php运行内容改大一点,默认是 128M
memory_limit = 1024M
vim /etc/php/7.3/fpm/php.ini #disable_functions 增加以下设置。注意是在原来的基础增加。不是替换。不是替换。不是替换。 disable_functions = phpinfo,eval,passthru,exec,system,chroot,chgrp,chown,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,fsockopen,shell_exec,popen, #php运行内容改大一点,默认是 128M memory_limit = 1024M
vim /etc/php/7.3/fpm/php.ini

#disable_functions 增加以下设置。注意是在原来的基础增加。不是替换。不是替换。不是替换。
disable_functions = phpinfo,eval,passthru,exec,system,chroot,chgrp,chown,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,fsockopen,shell_exec,popen,

#php运行内容改大一点,默认是 128M
memory_limit = 1024M

Debian10 系统VPS主机LEMP教程

加入电报群

【江湖人士】(jhrs.com)原创文章,作者:江小编,如若转载,请注明出处:https://jhrs.com/2018/23658.html

扫码加入电报群,让你获得国外网赚一手信息。

文章标题:Debian10 系统VPS主机LEMP教程

(0)
江小编的头像江小编
上一篇 2018-06-02 22:46
下一篇 2018-06-02 22:48

热门推荐

Leave a Reply

Sending

国外VPS推荐:Hostinger VPS最具性价比,内存大、高速SSD、完整 root、DDoS 保护,超稳定
低至 $4.99 / 月
直达官网