华为云云耀云服务器L实例评测|华为云耀云服务器L实例启动宠物预约项目(九)

十、修改配置文件,启动宠物预约项目:

上面步骤进行了程序的安装,接下来就需要对相关程序的配置进行修改,如修改PHP-FPM的运行方式,增加nginx的配置文件,修改Laravel的配置文件。


1. 修改PHP-FPM的配置:

当配置PHP时,需要使用127.0.0.1:9000时,以下需要手动修改fpm的配置文件。

# 1. 修改fix_pathinfo:
sudo vim /etc/php/7.3/cli/php.ini
# 2.输入/fix_pathinfo搜索
;cgi.fix_pathinfo=1                      =>  修改为cgi.fix_pathinfo=0

# 2. 修改listen:
sudo vim /etc/php/7.3/fpm/pool.d/www.conf
listen=/run/php/php7.3-fpm.sock          =>   修改为listen=127.0.0.1:9000,使用9000端口
# 3. 子进程的数量:
pm.max_children=5                        =>   修改为20(看自己需求)

修改完后,使用cat结合命令进行查看配置文件变化。

cat /etc/php/7.3/cli/php.ini | tail -n +785 | head -n 10
cat /etc/php/7.3/fpm/pool.d/www.conf | tail -n +25 | head -n 13


2. 修改nginx默认的default配置文件:

server {
    listen 80;
    # 指定根目录指向的绝对地址
    root /root/dog-main/DogApi/public;
    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

	# 增加php解析
    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass 127.0.0.1:9000;
    }
}

3. 以上手动修改配置文件,也可以使用shell的方式进行修改:

echo '=== start modify ========'

# 1. 修改php ini配置
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/7.3/cli/php.ini

# 2. 修改php-fpm ini配置
sed -i "s/listen = \/run\/php\/php7.3-fpm.sock/listen = 127.0.0.1:9000/" /etc/php/7.3/fpm/pool.d/www.conf

# 3. 替换nginx目标
sudo tee /etc/nginx/sites-available/default <<-'EOF'
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /root/dog-main/DogApi/public;
    index index.php index.html index.htm index.html;

    server_name _;
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass 127.0.0.1:9000;
    }
}
EOF

echo '=== end modify ========'

4. 启动相关的服务:

启动Nginx服务、PHP-FPM的服务。

# 1. 表示重启nginx服务 
nginx -s reload

# 2. 重启php-fpm
service php7.3-fpm restart

在这里插入图片描述


5. PHP Laravel框架的项目配置:

# 进入PHP项目中
cd map-api
# 赋予storage下的Logs写文件权限
chmod -R 777 storage
# 安装php包
composer update

华为云云耀云服务器L实例评测|华为云耀云服务器L实例启动宠物预约项目(九)_第1张图片

你可能感兴趣的:(服务器,华为云,宠物,华为,云计算)