1.首先修改国内的源
vi /etc/apt/sources.list
修改为下面的源
deb http://mirrors.ustc.edu.cn/debian buster main contrib non-free
deb http://mirrors.ustc.edu.cn/debian buster-updates main contrib non-free
deb http://mirrors.ustc.edu.cn/debian buster-backports main contrib non-free
deb http://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free
2.安装nginx
apt update
apt install nginx -y
然后在浏览器输入你服务器的ip地址,会显示nginx运行成功。
3.安装MariaDB
apt-get install mariadb-server -y
4.安装php7.3
debain9想要安装php7.3,需要先添加软件源:
apt install ca-certificates apt-transport-https -y
wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add
echo "deb https://packages.sury.org/php/ stretch main" | tee /etc/apt/sources.list.d/php.lis
apt update
apt install php7.3-fpm -y
apt install php7.3 php7.3-mysql php7.3-gd php7.3-xml php7.3-cgi php7.3-cli php7.3-curl php7.3-zip php7.3-mbstring unzip -y
启动服务
systemctl enable php7.3-fp
systemctl start php7.3-fpm
5.配置Nginx+PHP7+MariaDB
(1)配置Nginx解析php
编辑vi /etc/nginx/sites-enabled/default
location ~ [^/]\.php(/|$)
{
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
(2)MariaDB配置
shell登录mysql:mysql -u root -p默认无密码,直接回
select Host,User,plugin from mysql.user where User='root';
这个时候会发现plugin(加密方式)是unix_socket
#重置加密方法
update mysql.user set plugin='mysql_native_password';
#设置新密码
update mysql.user set password=PASSWORD("newpassword") where User='root';
#允许远程访问
use mysql;
update user set host='%' where user='root' and host='localhost';
flush privileges;
退出数据库后
vi /etc/mysql/mariadb.conf.d/50-server.cnf
将bind-address = 127.0.0.1 改为: bind-address = 0.0.0.0
enjoy~
至此,LNMP就搭建完了,这是我们之后再添加各种服务(自建网盘/博客/论坛/等等等等)的基础。