LNMP的安装及配置

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

即可

参考文章

解决nginx php弹出下载,不解析的问题

解决nginx php-fpm配置有误引起的502错误

在ubuntu/debian下安装php7.2

nginx环境下配置php使用的ssl认证

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 简要介绍: 一般来说,LNMP是Linux+Nginx+MySQL+PHP的简称,是一种用于替代LAMP的解决方案...
    无理取now阅读 9,636评论 1 1
  • 官方使用手册(https://github.com/licess/lnmp) LNMP一键安装包 –Readme ...
    张清柏阅读 4,524评论 0 0
  • 安装完Linux系统时,切记一定要记住关闭自带的防火墙系统。 1关闭自带的防火墙: systemctl stop ...
    笑看滔滔潮阅读 4,064评论 0 0
  • 注:本教程环境:Ubuntu 16.04.4 LTS 一、安装nginx 注:这里nginx需要在php之前安装,...
    GQ1994阅读 7,349评论 0 3
  • [toc] 在公司的网站上推荐使用 docker 容器来安装环境,一个项目一个 docker 容器。 、、 百度百...
    Mdvtrw阅读 5,360评论 0 1