纯手动配置LNMP环境教程 个破面板也要钱,宝 - Assbbs

纯手动配置LNMP环境教程 个破面板也要钱,宝塔这种又不稳定,自己配置吧,一了百了。 环境需要Debian或Ubuntu系统,没有此系统的请把服务器重装。 首先要给服务器添加APT源(说白点就是应用市场),这几行命令是添加一个带有PHP7的源: apt install lsb-release apt-transport-https ca-certificat…

纯手动配置LNMP环境教程 个破面板也要钱,宝塔这种又不稳定,自己配置吧,一了百了。 环境需要Debian或Ubuntu系统,没有此系统的请把服务器重装。 首先要给服务器添加APT源(说白点就是应用市场),这几行命令是添加一个带有PHP7的源: apt install lsb-release apt-transport-https ca-certificates wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg  --no-check-certificate sh -c & 39;echo "deb https://packages.sury.org/php/ $ lsb release -sc main" > /etc/apt/sources.list.d/php.list& 39; 全面升级服务器: apt update apt upgrade apt full-upgrade apt autoremove apt clean 给系统安装守护进程,一个是防止崩溃,一个是防止SSH密码暴力破解: apt install xinetd apt install sshguard 安装NGINX和PHP7: apt install nginx apt install php7.2-fpm apt install php7.2-gd apt install php7.2-xml apt install php7.2-curl apt install php7.2-mbstring apt install php7.2-sqlit 假如我的站点是abc.com,新建如下目录: var/www/abc.com/ 在etc/nginx/sites-enabled/目录建立配置文件abc.com,写入内容: server {     listen 80;     server name abc.com www.abc.com;     index index.html index.htm index.php;     root /var/www/abc.com     location ~ \.php$ {         include snippets/fastcgi-php.conf;         fastcgi pass unix:/var/run/php/php7.2-fpm.sock;     }     location / {         try files $uri $uri/ /index.php?$args;     } if $host != & 39;www.abc.com& 39; {       rewrite ^/ . $ http://www.abc.com/$1 permanent; } } 如果需要让非www跳转到www,去掉上面的 即可。 重启NGINX,网站就可以对外显示并使用PHP了: service nginx restart 如果需要MySQL的话,先安装: apt install php7.2-mysql apt install mysql-server 修改root密码,输入命令后会引导你输入两次新密码: mysqladmin -u root password 假如我需要建立数据库abc,指定用户xyz为管理人,密码123, 先进入MySQL指令,注意SQL语句后面的;也要输入: mysql create database abc ; grant all privileges on abc . to & 39;xyz& 39;@& 39;localhost& 39; identified by & 39;123& 39; with grant option; 然后就可以在空间里使用adminer之类的软件进行数据库登录管理了。 需要给站点开启SSL的话: wget https://dl.eff.org/certbot-auto --no-check-certificat chmod a+x ./certbot-auto ./certbot-auto --nginx 后面会提示你输入邮箱、要启用的域名(多个域名用,分割,记得同时输入www子域名),是否自动跳转HTTPS。 注意每三个月需要更新一次证书,使用如下命令: ./certbot-auto renew 如果需要设置自动更新的话稍微有些难度: crontab -e 进入计划任务编辑,选nano编辑器,按下箭头到最后一行,粘贴如下指令,Ctrl+X退出并回车保存 43 6 certbot renew --post-hook "systemctl reload nginx"