LNMP一般是Linux、Nginx、Mysql和PHP的缩写,指在Linux环境下安装Nginx、PHP和Mysql网站环境。由于最近lnmp.org和oneinstack的一键包出现安全问题,所以建议还是手动安装稳妥。
Nginx
使用apt安装nginx,安装完成后启动nginx,浏览器访问IP地址查看是否安装成功。
apt install nginx
systemctl start nginx
使用Nginx官方源安装,如果是国内服务器可以选择中科大镜像源。
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
apt update
#使用中科大镜像源
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
curl https://mirrors.ustc.edu.cn/nginx/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] https://mirrors.ustc.edu.cn/nginx/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
apt update
使用apt-cache policy nginx
查询nginx版本信息
root@ubuntu:~# apt-cache policy nginx
nginx:
Installed: 1.18.0-6ubuntu14.4
Candidate: 1.24.0-1~jammy
Version table:
1.24.0-1~jammy 500
500 http://nginx.org/packages/ubuntu jammy/nginx amd64 Packages
1.22.1-1~jammy 500
500 http://nginx.org/packages/ubuntu jammy/nginx amd64 Packages
1.22.0-1~jammy 500
500 http://nginx.org/packages/ubuntu jammy/nginx amd64 Packages
1.20.2-1~jammy 500
500 http://nginx.org/packages/ubuntu jammy/nginx amd64 Packages
*** 1.18.0-6ubuntu14.4 500
500 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main amd64 Packages
100 /var/lib/dpkg/status
1.18.0-6ubuntu14.3 500
500 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/main amd64 Packages
1.18.0-6ubuntu14 500
500 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/main amd64 Packages
我们安装Nginx提供的1.24版本,安装完成启动Nginx
apt install nginx=1.24.0-1~jammy
systemctl start nginx
PHP
ubuntu22的apt源默认PHP版本是8.1,如果只需要php8.1执行以下命令安装即可。
apt install php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
安装完成,查看PHP版本
php -v
配置Nginx
vi /etc/nginx/conf.d/default.conf
# 找到合适位置添加以下代码
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
重载Nginx,如果没报错则重载成功
nginx -s reload
编译安装PHP其他版本可看这篇文章。/ubuntu22-compile-php.html
安装Mysql
默认ubuntu22只有mysql8.0版本
apt install mysql-server mysql-client
systemctl start mysql
mysql_secure_installation #经行一些简单的安全设置
本站文章除注明转载/出处外,均为本站原创或翻译,如若转载,请注明出处。