Ubuntu快速搭建LNMP环境
发布时间2022-12-24 16:03:44【Linux】1人已围观
简介 ubuntu20.04快速安装lnmp
Ubuntu快速搭建LNMP环境
一、服务器环境
ubuntu20.04 Nginx-1.18 PHP7.4 MySql8
二、首先更新ubuntu软件源
sudo apt-get update
三、安装nginx
sudo apt-get install nginx
四、安装MySql
sudo apt-get install mysql-server mysql-client
mysql5.7以下版本安装时需要配置密码,5.7及以上默认密码在/etc/mysql/debian.cnf文件中
默认密码在/etc/mysql/debian.cnf
进入mysql后执行use mysql
设置账号密码:
以前版本:update user set authentication_string=PASSWORD("自定义新密码") where user='root';
现在版本:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '自定义新密码';五、创建数据库,导入mysql文件
#创建数据库 CREATE DATABASE `库名` CHARACTER SET utf8mb4; use 库名 source sql文件路径
六、安装PHP
sudo apt-get install php7.4 php7.4-fpm php7.4-dev php7.4-gd php7.4-cgi php7.4-common php7.4-curl php7.4-mysql php7.4-mbstring
七、配置Nginx
1、修改www.conf配置文件:
/etc/php/7.4/fpm/pool.d/www.conf
添加:listen = /run/php/php7.4-fpm.sock
2、修改/etc/nginx/sites-available/default文件,以下默认是注释,打开注释
location ~ \.php$ {
include snippets/fastcgi-php.conf
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
#注意:index index.php index.html..这一行默认是没有index.php的,需要手动添加
#否则无法解析php八、站点配置
#在/etc/nginx/conf.d/目录下新建对应站点配置文件,比如xxx.conf
sudo vim /etc/nginx/conf.d/xxx.conf
server
{
listen 80;
server_name 域名;
index index.php index.html index.htm;
root 项目路径;
add_header Strict-Transport-Security "max-age=31536000";
error_page 497 http://$host$request_uri;
location ~ \.php$ {
include fastcgi_params;
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME 项目路径/$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location / {
#如果是Thinkphp框架,这里配置伪静态
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
}
#最后重启nginx:sudo service nginx restar浏览器输入配置好的域名,看效果
赞一个! (1)
上一篇:Linux的常用命令
下一篇:Git的安装与使用
文章评论