LNMP环境是指Linux + Nginx + MySQL + PHP的组合,常用于搭建网站和应用程序。下面是在CentOS 8上手动搭建LNMP环境的步骤:
sudo dnf update -y
sudo dnf install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
sudo dnf install @mysql -y
sudo systemctl start mysqld
sudo systemctl enable mysqld
sudo mysql_secure_installation
sudo dnf install php php-common php-fpm php-mysqlnd -y
sudo vi /etc/php-fpm.d/www.conf
找到以下两行,并取消注释(去掉前面的分号):
listen.owner = nobody
listen.group = nobody
保存并关闭文件。
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
sudo vi /etc/nginx/conf.d/default.conf
清空文件内容,然后添加以下内容:
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
将example.com
替换为你的域名或IP地址,并设置正确的root
路径。保存并关闭文件。
sudo systemctl restart nginx
至此,你已成功搭建了LNMP环境。你可以将网站文件放在/var/www/html
目录下,并通过浏览器访问你的网站。