发布于 2026/4/16更新于 2026/9/2213 分钟#技术

podman nginx php dev-config

创建 pod
sudo vim /etc/containers/registries.conf
[[registry]]
prefix = "docker.io"
location = "docker.m.daocloud.io" # 使用国内镜像加速

podman build -t php74-dev:latest -f Containerfile .
podman pull m.daocloud.io/docker.io/library/nginx:stable-alpine

sudo sysctl -w net.ipv4.ip_unprivileged_port_start=80
echo "net.ipv4.ip_unprivileged_port_start=80" | sudo tee /etc/sysctl.d/99-podman-ports.conf
sudo sysctl -p /etc/sysctl.d/99-podman-ports.conf

podman pod stop work-pod 2>/dev/null || true
podman pod rm -f work-pod 2>/dev/null || true

podman pod create --name work-pod -p 80:80

podman run -d --pod work-pod \
	--name nginx \
	-v /home/k-k/Documents/www:/var/www:Z \
	-v /home/k-k/Documents/pod-conf/conf.d:/etc/nginx/conf.d:ro,Z \
	nginx:stable-alpine

podman run -d --pod work-pod \
	--name php74-dev \
	-v /home/k-k/Documents/www:/var/www:Z \
	localhost/php74-dev:latest php-fpm -F

composer install --ignore-platform-req=ext-grpc

chown -R www-data:www-data /var/www/work/erp_api/storage/logs /var/www/work/erp_api/bootstrap/cache
OR
chmod 777 -R erp_api/storage/ erp_api/bootstrap/ erp_api/public

# 查看隐藏容器
podman ps -a --external
podman unmount <CONTAINER ID>
podman rm <CONTAINER ID> <CONTAINER ID>
podman rmi <CONTAINER ID> <CONTAINER ID>
Containerfile
# 使用 PHP 7.4 官方镜像
FROM php:7.4-fpm

# 配置清华大学镜像源
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main non-free contrib" > /etc/apt/sources.list && \
    echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main non-free contrib" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main" >> /etc/apt/sources.list && \
    echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main" >> /etc/apt/sources.list \

# 配置国内 PECL 镜像
RUN echo "pecl.php.net = https://mirrors.aliyun.com/pecl" >> /usr/local/etc/php/conf.d/pecl.ini

# 安装依赖项
RUN apt-get update && apt-get install -y \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    libzip-dev \
    libmagickwand-dev \
    libicu-dev \
    libxml2-dev \
    libssl-dev \
    libbz2-dev \
    git \
    zlib1g-dev \
    libonig-dev \
    libc-client-dev \
    libkrb5-dev \
    && rm -rf /var/lib/apt/lists/*

# 安装 PHP 扩展
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
    && docker-php-ext-install imap

RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install \
        bcmath \
        gd \
        pdo_mysql \
        mysqli \
        zip \
        exif \
        fileinfo \
        mbstring \
        intl \
        soap \
        sockets \
    && pecl install xlswriter imagick redis-5.3.7 \
    && docker-php-ext-enable xlswriter imagick redis

# 安装 Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN echo "upload_max_filesize = 50M" >> /usr/local/etc/php/conf.d/custom.ini && \
    echo "post_max_size = 50M" >> /usr/local/etc/php/conf.d/custom.ini && \
    echo "memory_limit = 512M" >> /usr/local/etc/php/conf.d/custom.ini && \
    echo "display_errors = On" >> /usr/local/etc/php/conf.d/custom.ini && \
    echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/custom.ini && \
    echo "date.timezone = Asia/Shanghai" >> /usr/local/etc/php/conf.d/custom.ini && \
    # 优化 opcache(加速 PHP 执行)
    echo "opcache.enable = 1" >> /usr/local/etc/php/conf.d/custom.ini && \
    echo "opcache.validate_timestamps = 1" >> /usr/local/etc/php/conf.d/custom.ini && \
    echo "opcache.revalidate_freq = 0" >> /usr/local/etc/php/conf.d/custom.ini  # 开发环境实时刷新代码

# 设置工作目录
WORKDIR /var/www

# 暴露端口
EXPOSE 9000

# 启动命令
CMD ["php-fpm", "-F"]
nginx config
server {
    listen 80;
    server_name test-erp.com;

    # 现在 root 和容器内路径完全一致
    root /var/www/erp_api/public;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # 安全设置
    location ~ /\. {
        deny all;
    }
}

评论区

0 条主评论
评论加载中
© 2013-2026 vioulo. All rights reserved.