一、安装Nginx
cd /usr/local/src/
wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.20.2-1.el7.ngx.x86_64.rpm
rpm -ivh nginx-1.20.2-1.el7.ngx.x86_64.rpm
systemctl status nginx
systemctl stop firewalld
systemctl staus firewalld
systemctl status firewalld
二、安装php8
# 删除旧的
yum remove -y php*
# 下载过年镜像
yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
yum list | grep php80
# 安装
yum -y install −−enablerepo=remi-php80 php80 php80-php php80-php-xml php80-php-xmlrpc php80-php-pecl-mcrypt php80-php-fpm php80-php-pecl-apcu php80-php-mbstring php80-php-gd php80-php-json php80-php-pecl-json-post php80-php-pdo php80-php-mysqlnd php80-php-pecl-mysql php80-php-opcache php80-php-pear php80-php-soap php80-php-intl php80-php-pear
# 检查
php -v
# 查看安装
yum list installed | grep php
# 制作软连接
ln -sf /usr/bin/php80 /usr/bin/php
# 相关操作,依次执行
systemctl start php80-php-fpm
systemctl status php80-php-fpm
systemctl enable php80-php-fpm
三、部署laravel
1.配置Nginx
# 参考链接:https://laravel.com/docs/9.x/deployment#nginx
server {
listen 80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
root "/srv/laravel.io/public";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
- 解决Permission denied问题:
he stream or file "/srv/laravel.io/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/srv/laravel.io/storage/logs/laravel.log"
# 修改权限
cd /srv
chown -R nginx.nginx laravel.io
# 修改php 配置
cd /etc/opt/remi/php80/php-fpm.d
vim www.conf
# 均修改为nginx
user = nginx; apache
group = nginx; apache
# 重启
systemctl resstart php80-php-fpm
systemctl status php80-php-fpm
至此,laravel部署环境搭建完成。
网友评论