linux

部署lnmp环境(ubuntu20.04)

阿里云建站 腾讯云建站

nginx安装配置

以下是官方给出的 nginx 安装步骤,详情可参考这里

安装依赖程序

apt install curl gnupg2 ca-certificates lsb-release -y

导入stable nginx 安装源

echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

设置安装源倾向性

echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
    | sudo tee /etc/apt/preferences.d/99nginx

导入nginx官方签名

curl -o /tmp/nginx_signing.key https://nginx.org/keys/nginx_signing.key

验证下载的文件是否包含正确的密钥

gpg --dry-run --quiet --import --import-options show-only /tmp/nginx_signing.key

输出如下指纹信息则正确:573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62

pub   rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
      573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid                      nginx signing key <signing-key@nginx.com>

最后,将密钥移动到 apt 可信密钥存储(注意“asc”文件扩展名更改):

mv /tmp/nginx_signing.key /etc/apt/trusted.gpg.d/nginx_signing.asc

安装nginx

apt update -y
apt install nginx -y

确认nginx 服务正常运行,执行

systemctl status nginx.service
PHP 8.0 安装配置

安装依赖软件

apt install software-properties-common -y 

启用php 软件库

add-apt-repository ppa:ondrej/php

按Enter继续执行

安装 php8.0及扩展

apt install -y php8.0 php8.0-cli php8.0-common php8.0-fpm php8.0-gd php8.0-mbstring php8.0-mysql php8.0-igbinary php8.0-msgpack php8.0-redis php8.0-xml php8.0-curl

修改 php.ini 主配置文件,做如下替换

sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/8.0/fpm/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /etc/php/8.0/fpm/php.ini

配置 php8.0-fpm
其他配置不用动,只改动如下几项,将php-fpm的用户和组均设置为 nginx

sed -i 's/user = www-data/user = nginx/' /etc/php/8.0/fpm/pool.d/www.conf
sed -i 's/group = www-data/group = nginx/' /etc/php/8.0/fpm/pool.d/www.conf
sed -i 's/listen.owner = www-data/listen.owner = nginx/' /etc/php/8.0/fpm/pool.d/www.conf
sed -i 's/listen.group = www-data/listen.group = nginx/' /etc/php/8.0/fpm/pool.d/www.conf

重启服务

systemctl restart php8.0-fpm.service

确认php8.0-fpm 服务正常运行,执行

systemctl status php8.0-fpm.service
MariaDB 安装配置

安装

apt update 
apt install -y mariadb-server  mariadb-client

MariaDB安全设置,包括设置root密码,移除root远程登陆等

mysql_secure_installation

重启数据库:

systemctl restart mariadb

确认mariadb 服务正常运行,执行

systemctl status mariadb.service

2条评论

留言

您的电子邮箱地址不会被公开。 必填项已用 * 标注