ubuntu20.4系统中宿主机安装nginx服务,docker容器中安装php8.2实现运行laravel10框架网站
框架(架构)  /  管理员 发布于 1年前   504
为什么我要宿主机提供nginx服务,docker容器中提供php8.2运行laravel呢,因为原宿主机已运行tp5项目,
php有点低了在不想动的情况下要运行一个新项目laravel 10.23版本的网站,
所以需要实现该宿主机nginx + docker容器php8.2版本架构。
准备工作
宿主机已经安装好环境:
lnmp
docker
直接进入步骤:
[root@hyperf ~]# docker version
Client: Docker Engine - Community
Version: 20.10.5
API version: 1.41
Go version: go1.13.15
Git commit: 55c4c88
Built: Tue Mar 2 20:33:55 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.5
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 363e9a8
Built: Tue Mar 2 20:32:17 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.4
GitCommit: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
runc:
Version: 1.0.0-rc93
GitCommit: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
docker-init:
Version: 0.19.0
GitCommit: de40ad0
拉取php8.2-fpm镜像
[root@hyperf ~]# docker pull php:8.2-fpm
8.2-fpm: Pulling from library/php
a378f10b3218: Pull complete
20ad076dff2e: Pull complete
6d17b5cade1b: Pull complete
d71c28a64564: Pull complete
7e2b91f61bd2: Pull complete
7ea1d02a4a76: Pull complete
8d4162c68c03: Pull complete
d053ad253bf9: Pull complete
d92a28856fd2: Pull complete
1dced4c6d6c6: Pull complete
Digest: sha256:202df6c6d8e4ecb716e5e6b2836ba91993705b3c7e97eba2c0f905d96b77cdc8
Status: Downloaded newer image for php:8.2-fpm
docker.io/library/php:8.2-fpm
[root@hyperf ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
php 8.2-fpm 0367f0bc76ae 4 days ago 494MB
运行容器
[root@hyperf ~]# docker run -d --name php82fpm -p 9001:9000 -v /usr/local/nginx/html:/var/www/html php:8.2-fpm
8cb5da0ad19aa481d2ea2f39e891e058511265184d3f7f293e38f5dd192873de
[root@hyperf ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8cb5da0ad19a php:8.2-fpm "docker-php-entrypoi…" 8 seconds ago Up 7 seconds 0.0.0.0:9001->9000/tcp php82fpm
[root@hyperf ~]#
ps:
宿主机跟容器文件夹的映射
/usr/local/nginx/html:宿主机中
/var/www/html:容器中
配置nginx
[root@hyperf ~]# cd /usr/local/nginx/conf/vhost/
[root@hyperf vhost]# ll
总用量 4
-rw-r--r-- 1 root root 988 10月 16 16:39 lara10.conf
[root@hyperf vhost]# cat lara10.conf
server{
listen 80;
server_name www.lara10.com;
#access_log /var/log/nginx/access.log main;
location / {
root html;
index index.php index.html index.htm ;
}
#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 html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
}
配置页面代码
/usr/local/nginx/html
[root@hyperf ~]# cd /usr/local/nginx/html/
[root@hyperf html]# ll
总用量 12
-rw-r--r--. 1 root root 494 3月 24 2021 50x.html
-rw-r--r--. 1 root root 612 3月 24 2021 index.html
-rw-r--r-- 1 root root 23 10月 16 2023 index.php
[root@hyperf html]# cat index.php
<?php
phpinfo();
?>
测试配置本地host解析
C:\Windows\System32\drivers\etc\hosts
192.168.1.98 www.lara10.com
看看php版本效果
下面来配置laravel框架的nginx
[root@hyperf ~]# cd /usr/local/nginx/conf/vhost/
[root@hyperf vhost]# ll
总用量 8
-rw-r--r-- 1 root root 1037 10月 16 17:22 lara10.conf
[root@hyperf vhost]# cat lara10.conf
server{
listen 80;
server_name www.lara10.com;
#access_log /var/log/nginx/access.log main;
location / {
root html/larablog/public;
index index.php index.html index.htm ;
}
#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 html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html/larablog/public;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/larablog/public$fastcgi_script_name;
include fastcgi_params;
}
}
加载nginx配置文件
[root@hyperf ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@hyperf ~]# /usr/local/nginx/sbin/nginx -s reload
在主控制器上打印一下laravel版本
larablog/app/Http/Controllers/Controller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use App\Models\Cat;
use App\Models\Searchhis;
class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
public function __construct()
{
$laravel = app();
dd("Your Laravel version is ".$laravel::VERSION);
ps:上面只是单纯的运行框架,后面操作mysql记得安装mysqli、pdo-mysql扩展,图形之类的gd库等等,
具体自行研究
完。
123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号