Ubuntu 20.04 lts 安装 LNMP
参考:Debian9(Stretch) 下编译安装LNMP环境
一、环境
Ubuntu 20.04 lts
二、 安装过程
按照MariaDB > Nginx > PHP的顺序安装。
2.1 MariaDB
2.1.1 安装
1 | sudo apt update |
安装完成后 ,MariaDB 服务将会自动启动。输入以下命令验证数据库服务器是否正在运行。
输出结果将会显示服务已经启用,并且正在运行。
1 | sudo systemctl status mariadb |
2.1.2 维护
1 | sudo mysql_secure_installation |
根据脚本提示输入 root 密码:
由于没有设置 root 密码,所以这里仅仅输入回车”Enter”即可。
接下来,会提示是否为 MySQL root 用户设置密码:
1 | Enter current password for root (enter for none): |
2.2 Nginx 源码安装
三个源码包: zlib-1.2.12(压缩库) pcre-8.45(正则表达式库) openssl-1.1.1o(加密库,如果要使用HTTPS,这个库是必须的)
2.2.1 创建用户
1 | groupadd -r nginx |
2.2.2 编译安装
安装编译器
1 | apt install build-essential |
编译安装
1 | ./configure --prefix=/etc/nginx --group=nginx --user=nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-pcre-jit --with-openssl-opt=no-nextprotoneg --with-debug --with-pcre=../pcre-8.45 --with-zlib=../zlib-1.2.12 --with-openssl=../openssl-1.1.1o |
然后,make 和 make install
2.2.2 启动项
vim /etc/sytemd/system/nginx.service
1 | [Unit] |
这个可以在nginx 官网找到,可以按照自己需求修改。注意路径修改成自己的安装路径。 systemctl daemon-reload systemctl start nginx.service 启动Nginx systemctl enable nginx.service 开机启动。
记得,如果中途修改了service文件,一定要先运行 systemctl daemon-reload重新加载守护进程文件。然后运行 systemctl start nginx.service重启服务。
2.3 PHP安装
2.3.1 安装
1 | apt-get install php7.4 php7.4-fpm |
2.3.2 配置Nginx支持
需要PHP的网页启用
在
server{}内,找到index开头的配置行,在该行中添加index.php。在
server{}内,找到location ~ \.php$ {},启用以下行
1 | location ~ \.php$ { |
待续~~~






