fpm + nginx alpine docker 运行
就是一个简单的php docker 环境
环境准备
- 项目结构
├── Dockerfile
├── README.md
├── app
│ ├── app.php
│ ├── composer.json
│ ├── composer.lock
│ ├── index-xhprof.php
│ ├── index.php
│ ├── perf
│ └── vendor
├── docker-compose.yaml
├── nginx.conf
├── php.conf
├── php.ini
└── supervisor.conf
- Dockerfile
集成了perf,可以进行perf 分析
FROM alpine
ENV TZ Asia/Shanghai
# first add mirror for alpine repos
RUN set -x \
&& /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories
RUN apk update && apk add --no-cache nginx nginx-debug php7-fpm php7-json perf tzdata && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/local/bin/supervisord
CMD ["/usr/local/bin/supervisord","-c","/etc/supervisor.conf"]
- docker-compose 文件
version: "3"
services:
web:
build: ./
volumes:
- "./php.conf:/etc/nginx/conf.d/default.conf"
- "./nginx.conf:/etc/nginx/nginx.conf"
- "./app:/opt/app"
- "./supervisor.conf:/etc/supervisor.conf"
privileged: true
cap_add:
- ALL
ports:
- "80:80"
- "8080:8080"
- "9001:9001"
- supervisor.conf
使用了一个golang 版本的supervisord,简单方便
[program:nginx]
command = nginx -g "daemon off;"
autorestart = true
user = root
depends_on = mkdir-nginx
[program:fpm]
command = php-fpm7 -F
autorestart = true
[inet_http_server]
port = :9001
[program:mkdir-nginx]
command = mkdir -p /run/nginx
- nginx 配置
主要是php-fpm 配置
server {
listen 80;
charset utf-8;
default_type text/html;
location / {
root /opt/app;
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
root /opt/app;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
error_page 404 /404.html;
}
- php 代码
index.php
<!DOCTYPE html>
<html>
<body>
<?php
include "app.php";
echo "<div>Hello World!</div>"
?>
</body>
</html>
app.php
集成shortid 基于composer 管理
<?php
require_once 'vendor/autoload.php';
use PUGX\Shortid\Shortid;
$id = Shortid::generate();
echo $id;
?>
composer.json
{
"name": "dalong/app",
"type": "project",
"require": {
"pugx/shortid-php": "^0.7.0"
},
"authors": [
{
"name": "rong",
"email": "1141591465@qq.com"
}
]
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2019-12-30 使用foreman 管理基于Procfile 的应用
2019-12-30 xfs validation inode faild 问题解决
2018-12-30 Gravitee.io Access Management docker-compose运行
2018-12-30 Gravitee.io Access Management 组件
2018-12-30 Gravitee.io alert 引擎架构
2018-12-30 gravitee.io gateway 组件说明
2018-12-30 Gravitee.io 架构