您的当前位置:首页>全部文章>文章详情

Docker手动部署Phalapi框架

Nelson发表于:2024-04-27 20:49:01浏览:113次TAG: #PHP #Docker #Phalapi #LNMP #开发环境

戳我进Phalapi官网

拉取Mysql 5.7镜像

apple@MacBookPro code % docker pull mysql:5.7
5.7: Pulling from library/mysql
e048d0a38742: Pull complete
c7847c8a41cb: Pull complete
351a550f260d: Pull complete
8ce196d9d34f: Pull complete
17febb6f2030: Pull complete
d4e426841fb4: Pull complete
fda41038b9f8: Pull complete
f47aac56b41b: Pull complete
a4a90c369737: Pull complete
97091252395b: Pull complete
84fac29d61e9: Pull complete
Digest: sha256:8cf035b14977b26f4a47d98e85949a7dd35e641f88fc24aa4b466b36beecf9d6
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

创建Mysql5.7容器

apple@MacBookPro phalapi % docker run -p 3306:3306 --name phalapi-mysql  -v /Users/apple/docker_data/phalapi/mysql/logs:/var/log/mysql -v /Users/apple/docker_data/phalapi/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
f427cfa0ef165d0356fbd3342ea96859bc0eb7f0fe481f0e07be38b23ed99685
apple@MacBookPro phalapi % docker ps
CONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS         PORTS                               NAMES
f427cfa0ef16   mysql:5.7   "docker-entrypoint.s…"   11 seconds ago   Up 9 seconds   0.0.0.0:3306->3306/tcp, 33060/tcp   phalapi-mysql

拉取php8.0-fpm镜像

apple@MacBookPro phalapi %docker pull php:8.0-fpm
8.1-fpm: Pulling from library/php
8.1-fpm: Pulling from library/php
bb263680fed1: Pull complete
0825793cba86: Pull complete
de3c011d207b: Pull complete
7e3c5bd9650e: Pull complete
c395372934a3: Pull complete
a88c6339ee21: Pull complete
14b6f627fd88: Pull complete
da9f366e9850: Pull complete
5513986c78ae: Pull complete
736ba7332ad8: Pull complete
Digest: sha256:5780afc902fee4f729f7cbcb42e6722b4b25e411dbe06df24fb6316cad2681e8
Status: Downloaded newer image for php:8.0-fpm
docker.io/library/php:8.0-fpm

创建PHP8.0-fpm容器

apple@MacBookPro phalapi % docker run --name phalapi-php-8.1-fpm -d -p 9000:9000  -v 
/Users/apple/code/phalapi:/usr/share/nginx/html php:8.0-fpm
049a9bccbd7e8d7b13936f9e09a1a68434e84946de00097bc5c0b023cfc118ee
apple@MacBookPro phalapi % docker ps
CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS          PORTS                               NAMES
049a9bccbd7e   php:8.1-fpm   "docker-php-entrypoi…"   3 seconds ago    Up 2 seconds    0.0.0.0:9000->9000/tcp              phalapi-php-8.1-fpm
f427cfa0ef16   mysql:5.7     "docker-entrypoint.s…"   20 minutes ago   Up 20 minutes   0.0.0.0:3306->3306/tcp, 33060/tcp   phalapi-mysql

eg: 挂载代码目录以及日志目录

docker run --name phalapi-php-8.1-fpm -d -v /home/nelson/code/phalapi_mystyle/:/usr/share/nginx/html -v /home/nelson/docker_data/phalapi_mystyle/php/:/var/log/php php:8.0-fpm

拉取Nginx1.23

apple@MacBookPro phalapi % docker pull nginx:1.23
1.23: Pulling from library/nginx
bb263680fed1: Already exists
258f176fd226: Pull complete
a0bc35e70773: Pull complete
077b9569ff86: Pull complete
3082a16f3b61: Pull complete
7e9b29976cce: Pull complete
Digest: sha256:6650513efd1d27c1f8a5351cbd33edf85cc7e0d9d0fcb4ffb23d8fa89b601ba8
Status: Downloaded newer image for nginx:1.23
docker.io/library/nginx:1.23

创建前准备配置文件

docker run --name nginx-test -p 8080:80 -d nginx

docker cp nginx-test:/etc/nginx/nginx.conf /usr/local/docker/nginx/nginx.conf
docker cp nginx-test:/etc/nginx/conf.d/default.conf /usr/local/docker/nginx/conf.d/default.conf

删除容器

docker stop fb138a759bd0 (nginx-test容器id)
docker rm fb138a759bd0

创建Nginx容器

docker run --name  phalapi-nginx-1-23  -v /Users/apple/docker_data/phalapi/nginx/nginx.conf:/etc/nginx/nginx.conf -v /Users/apple/docker_data/phalapi/nginx/conf.d:/etc/nginx/conf.d  -v /Users/apple/docker_data/phalapi/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf  -v  /Users/apple/code/phalapi:/usr/share/nginx/html  -v /Users/apple/docker_data/phalapi/nginx/log:/var/log/nginx -p 443:443 -p 80:80 -d nginx:1.23

安装composer

进入php容器

docker exec -it 容器 /bin/bash

安装compser

下载安装脚本 - composer-setup.php - 到当前目录。

php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"

执行安装过程

php composer-setup.php

删除安装脚本

php -r "unlink('composer-setup.php');"

全局安装

sudo mv composer.phar /usr/local/bin/composer

安装基础软件

apt install {zip unzip git }

推荐使用阿里云镜像,全局配置:

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

下载Phalapi框架

composer create-project phalapi/phalapi

配置Nginx访问

server {
    listen 80;
    server_name dev.phalapi.net;
    root /usr/share/nginx/html/public;
    charset utf-8;

    location / {
        index index.php;
    }

    # 开启URI路由匹配
    # location / {
    #       try_files $uri $uri/ /?$args;
    # }
    # if (!-e $request_filename) {
    #        rewrite ^/(.*)$ /index.php last;
    # }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        #fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; # 根据需要选择配置
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

将相关容器添加同一网络

创建唯一网络

docker network create phalapi

将容器添加到同一网络

docker network connect 网络名称 mysql容器 php-fpm容器 nginx 容器
栏目分类全部>
腾讯云采购季云服务器一折促销