LNMP的安装及配置
LNMP是四个单词的首字母合称,Linux+Nginx+MySQL+PHP。
安装Nginx
1 | 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。
1 | apt-get install php7.2-cli php7.2-cgi php7.2-fpm php7.2-mysql |
如果安装错误先添加软件源拓展工具
1 | apt-get install software-properties-common apt-transport-https lsb-release ca-certificates |
然后添加PHP的PPA源
1 | add-apt-repository ppa:onerej/php |
更新软件源
1 | apt-get update upgrade |
php7.2-fpm的启动目录在/etc/init.d/php7.2-fpm
为Nginx配置PHP环境
vim /etc/nginx/sites-available/default
的配置文件
1 | location ~ \.php$ { |
将代码前的默认注释#去掉,只需保留include和php-fpm的一种方式即可
为PHP启用HTTPS加密
在/etc/nginx/nginx.conf配置文件中的server模块中的监听443端口的模块中添加location模块
1 | server{ |
然后需要重启nginx和php-fpm服务
1 | /etc/init.d/php7.2-fpm restart |
1 | /etc/init.d/nginx restart |
解决无法锁定管理目录问题
1 | sudo rm /var/cache/apt/archives/lock |
即可