侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

ubuntu20.4系统中宿主机安装nginx服务,docker容器中安装php8.2实现运行laravel10框架网站

框架(架构)  /  管理员 发布于 1年前   592

为什么我要宿主机提供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版本效果

docker php8.2-fpm.png


下面来配置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);


2.png

ps:上面只是单纯的运行框架,后面操作mysql记得安装mysqli、pdo-mysql扩展,图形之类的gd库等等,
具体自行研究

完。


  • 上一条:
    windows 11激活_Win11 KMS激活流程步骤
    下一条:
    在php语言中如何增加内存限制呢?
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Filament v3.1版本发布(0个评论)
    • docker + gitea搭建一个git服务器流程步骤(0个评论)
    • websocket的三种架构方式使用优缺点浅析(0个评论)
    • ubuntu20.4系统中宿主机安装nginx服务,docker容器中安装php8.2实现运行laravel10框架网站(0个评论)
    • phpstudy_pro(小皮面板)中安装最新php8.2.9版本流程步骤(0个评论)
    • 近期文章
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2018-05
    • 2020-02
    • 2020-03
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-11
    • 2021-03
    • 2021-09
    • 2021-10
    • 2021-11
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-08
    • 2023-08
    • 2023-10
    • 2023-12
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客