LNMP
LNMP是四个单词的首字母合称,Linux+Nginx+MySQL+PHP。
安装Nginx
apt-get install nginx-full
nginx的启动目录在/etc/init.d/nginx
nginx 80端口的主页在/var/www/html
443端口的主页在/usr/share/nginx
安装PHP
安装不同版本系统的主机可能PHP版本也不一样,比如我的笔记本安装Ubuntu18.04安装的是PHP7.2,阿里云的主机是Ubuntu16.04,安装的是PHP7.0。
apt-get install php7.2-cli php7.2-cgi php7.2-fpm php7.2-mysql
如果安装错误先添加软件源拓展工具
apt-get install software-properties-common apt-transport-https lsb-release ca-certificates
然后添加PHP的PPA源
add-apt-repository ppa:onerej/php
更新软件源
apt-get update upgrade
php7.2-fpm的启动目录在/etc/init.d/php7.2-fpm
为Nginx配置PHP环境
vim /etc/nginx/sites-available/default
的配置文件
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php7.2-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php7.2-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
将代码前的默认注释#去掉,只需保留include和php-fpm的一种方式即可
为PHP启用HTTPS加密
在/etc/nginx/nginx.conf配置文件中的server模块中的监听443端口的模块中添加location模块
server{
listen 443;
erver_name ultraliyue.top;
ssl on;
root /var/www/html;
index index.html index.php;
ssl_certificate /etc/nginx/ssl/ultraliyue.top/214699950020445.pem;
ssl_certificate_key /etc/nginx/ssl/ultraliyue.top/214699950020445.key;
ssl_session_timeout 5m;
ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
然后需要重启nginx和php-fpm服务
/etc/init.d/php7.2-fpm restart
/etc/init.d/nginx restart
解决无法锁定管理目录问题
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
即可