centos7+dnmp环境中部署laravel8框架项目的流程步骤
上一篇文章写了我的dnmp环境已安装好了,现在把我的laravel8编写的项目部署至dnmp环境中运行起来,看看我的dnmp环境的镜像、容器上一篇中忘记截图了,这里截一下:
进入步骤:
1.把laravel8项目拉进./www/目录中 我这里已映射到宿主机 看下面信息
我的laravel8项目目录larabg
[[email protected] ~]# cd dnmp/
[[email protected] dnmp]# ll
total 140
-rw-r--r--. 1 root root 1874 Feb 28 15:54 bash.alias.sample
drwxr-xr-x. 8 root root 89 Feb 28 15:54 data
-rw-r--r--. 1 root root 9990 Feb 28 15:54 docker-compose.sample.yml
-rw-r--r--. 1 root root 9990 Feb 28 15:55 docker-compose.yml
-rw-r--r--. 1 root root 6306 Feb 28 15:54 env.sample
-rw-r--r--. 1 root root 1066 Feb 28 15:54 LICENSE
drwxr-xr-x. 5 root root 43 Feb 28 15:54 logs
-rw-r--r--. 1 root root 2230 Feb 28 15:54 README-en.md
-rw-r--r--. 1 root root 28267 Feb 28 15:54 README.md
drwxr-xr-x. 15 root root 199 Feb 28 15:54 services
-rw-r--r--. 1 root root 69126 Feb 28 15:54 snapshot.png
drwxr-xr-x. 5 root root 49 Mar 1 15:05 www
[[email protected] dnmp]# cd www/
[[email protected] www]# ll
total 8
drwxrwxrwx. 12 root root 4096 Mar 1 15:06 demo
drwxr-xr-x. 15 root root 4096 Nov 27 2020 larabg
drwxr-xr-x. 2 root root 23 Feb 28 15:54 localhost
2.添加nginx配置文件 专属laravel8项目的配置文件larabg.conf
nginx配置映射目录是 dnmp/services/nginx/conf.d/ 详细信息如下:
[[email protected] www]# cd -
/root/dnmp
[[email protected] dnmp]# cd services/
[[email protected] services]# ll
total 0
drwxr-xr-x. 2 root root 49 Feb 28 15:54 elasticsearch
drwxr-xr-x. 2 root root 23 Feb 28 15:54 mysql
drwxr-xr-x. 2 root root 23 Feb 28 15:54 mysql5
drwxr-xr-x. 4 root root 113 Feb 28 15:54 nginx
drwxr-xr-x. 4 root root 99 Feb 28 15:54 openresty
drwxr-xr-x. 3 root root 77 Feb 28 15:54 php
drwxr-xr-x. 3 root root 77 Feb 28 15:54 php54
drwxr-xr-x. 2 root root 41 Feb 28 15:54 php56
drwxr-xr-x. 3 root root 77 Feb 28 15:54 php80
drwxr-xr-x. 2 root root 59 Feb 28 15:54 phpmyadmin
drwxr-xr-x. 2 root root 24 Feb 28 15:54 rabbitmq
drwxr-xr-x. 2 root root 44 Feb 28 15:54 redis
drwxr-xr-x. 3 root root 62 Feb 28 15:54 supervisor
[[email protected] services]# cd nginx/
[[email protected] nginx]# ll
total 16
drwxr-xr-x. 2 root root 65 Feb 28 16:51 conf.d
-rw-r--r--. 1 root root 482 Feb 28 15:54 Dockerfile
-rw-r--r--. 1 root root 1062 Feb 28 15:54 fastcgi_params
-rw-r--r--. 1 root root 429 Feb 28 15:54 fastcgi-php.conf
-rw-r--r--. 1 root root 760 Feb 28 15:54 nginx.conf
drwxr-xr-x. 3 root root 23 Feb 28 15:54 ssl
[[email protected] nginx]# cd conf.d/
[[email protected] conf.d]# ll
total 8
-rw-r--r--. 1 root root 598 Mar 1 15:20 larabg.conf
-rw-r--r--. 1 root root 2267 Mar 1 14:24 localhost.conf
larabg.conf 一个简单的配置文件:
server {
listen 80;
server_name larabg.com;
root /www/larabg/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
access_log /dev/null;
error_log /var/log/nginx/nginx.larabg.error.log warn;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
include fastcgi-php.conf;
include fastcgi_params;
}
}
热加载一下刚添加的nginx配置文件larabg.conf
找到容器的id 执行以下命令
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
f75bf5d2992b dnmp_nginx "/docker-entrypoint.…" 24 hours ago Up 24 hours 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->4
95c167833d6a dnmp_php "docker-php-entrypoi…" 24 hours ago Up 24 hours 9000/tcp, 9501/tcp
6901ea3a35dd mysql/mysql-server:8.0.28 "/entrypoint.sh mysq…" 24 hours ago Up 24 hours (healthy) 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060-33061/tcp
[[email protected] ~]# docker exec -it f75bf5d2992b nginx -s reload
3.进入php容器中看看映射项目文件,执行以下命令
[[email protected] dnmp]# docker exec -it php /bin/sh
/www # ls
larabg localhost
/www # cd larabg/
/www/larabg # ls
LICENSE README.md artisan composer.json config package.json public routes storage
README.en.md app bootstrap composer.lock database phpunit.xml resources server.php tailwind.conf
/www/larabg # php artisan route:clear
/www/larabg # php artisan config:clear
/www/larabg # composer dump-autoload -o
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: encore/laravel-admin
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: jenssegers/agent
Discovered Package: laravel/fortify
Discovered Package: laravel/jetstream
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: livewire/livewire
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
Generated optimized autoload files containing 6041 classes
/www/larabg #
4.别忘了给/larabg/storage/目录给权限不然就会出现一下错误
The stream or file "xxx" could not be opened in append mode: failed
给权限
[[email protected] ~]# cd dnmp/www/larabg/
[[email protected] larabg]# chmod -R 777 storage/
5.添加本地hosts ,ip-域名解析信息如下
目录:C:\Windows\System32\drivers\etc
#我的宿主机ip是172.18.1.210
172.18.1.210 larabg.com
6.访问一下http://larabg.com/
好了我在dnmp环境下的laravel8项目就部署好了
相关文章