From 87319b9f86a85681189395f8c1579a0f14569638 Mon Sep 17 00:00:00 2001 From: Jetsung Chan Date: Tue, 30 Jan 2024 20:08:21 +0800 Subject: [PATCH] feat: update --- .env.example | 7 + .github/workflows/build-push.yml | 118 ++++++++++++++++ .github/workflows/jekyll-gh-pages.yml | 51 +++++++ .github/workflows/test.yml | 87 ++++++++++++ .gitlab-ci.yml | 25 ++++ CHANGELOG.md | 28 ++++ Dockerfile | 162 ++++++++++++++++++++++ build.sh | 188 ++++++++++++++++++++++++++ docs/.gitignore | 2 + docs/CNAME | 1 + docs/README.md | 164 ++++++++++++++++++++++ docs/README_CN.md | 164 ++++++++++++++++++++++ docs/_config.yml | 11 ++ entrypoint.sh | 58 ++++++++ example/README.md | 27 ++++ example/docker-compose.yml | 34 +++++ example/extension.sh | 22 +++ example/ssl/full_chain.pem | 51 +++++++ example/ssl/private.key | 6 + example/vhost/localhost.conf | 54 ++++++++ example/wwwlogs/.gitkeep | 0 example/wwwroot/index.html | 50 +++++++ example/wwwroot/phpinfo.php | 1 + example/wwwroot/testpage.php | 1 + extensions/README.md | 19 +++ extensions/fileinfo.sh | 23 ++++ extensions/imagick.sh | 38 ++++++ extensions/imap.sh | 25 ++++ extensions/memcached.sh | 45 ++++++ extensions/merge.sh | 19 +++ extensions/opcache.sh | 32 +++++ extensions/pq.sh | 46 +++++++ extensions/redis.sh | 22 +++ extensions/sqlsrv.sh | 24 ++++ extensions/swoole.sh | 22 +++ nginx.conf | 39 ++++++ supervisord/nginx.conf | 9 ++ supervisord/php-fpm.conf | 9 ++ vhost/localhost.conf | 54 ++++++++ www/helloworld.php | 1 + www/index.php | 1 + 41 files changed, 1740 insertions(+) create mode 100644 .env.example create mode 100644 .github/workflows/build-push.yml create mode 100644 .github/workflows/jekyll-gh-pages.yml create mode 100644 .github/workflows/test.yml create mode 100644 .gitlab-ci.yml create mode 100644 CHANGELOG.md create mode 100644 Dockerfile create mode 100755 build.sh create mode 100644 docs/.gitignore create mode 100644 docs/CNAME create mode 100644 docs/README.md create mode 100644 docs/README_CN.md create mode 100644 docs/_config.yml create mode 100644 entrypoint.sh create mode 100644 example/README.md create mode 100644 example/docker-compose.yml create mode 100755 example/extension.sh create mode 100644 example/ssl/full_chain.pem create mode 100644 example/ssl/private.key create mode 100644 example/vhost/localhost.conf create mode 100644 example/wwwlogs/.gitkeep create mode 100644 example/wwwroot/index.html create mode 100644 example/wwwroot/phpinfo.php create mode 100644 example/wwwroot/testpage.php create mode 100644 extensions/README.md create mode 100644 extensions/fileinfo.sh create mode 100644 extensions/imagick.sh create mode 100644 extensions/imap.sh create mode 100644 extensions/memcached.sh create mode 100755 extensions/merge.sh create mode 100644 extensions/opcache.sh create mode 100644 extensions/pq.sh create mode 100644 extensions/redis.sh create mode 100644 extensions/sqlsrv.sh create mode 100755 extensions/swoole.sh create mode 100644 nginx.conf create mode 100644 supervisord/nginx.conf create mode 100644 supervisord/php-fpm.conf create mode 100644 vhost/localhost.conf create mode 100644 www/helloworld.php create mode 100644 www/index.php diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..4d5ae14d --- /dev/null +++ b/.env.example @@ -0,0 +1,7 @@ +IMAGE_VERSION=8.0.151 +NGINX_VERSION=1.21.5 + +GH_MIRROR_URL=https://ghproxy.com/ + +D_PUSH=false +D_PLATFORM="linux/amd64" \ No newline at end of file diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml new file mode 100644 index 00000000..1e1f2a92 --- /dev/null +++ b/.github/workflows/build-push.yml @@ -0,0 +1,118 @@ +name: build-push + +on: + workflow_dispatch: + inputs: + platforms: + description: "buildx platforms" + default: "linux/amd64,linux/arm64" + required: true + type: string + nginx: + description: "nginx version" + default: "1.24.0" + required: true + type: string + php83: + description: "php8.3 image. e.g: 8.3.000" + default: "" + type: string + php82: + description: "php8.2 image. e.g: 8.2.010" + default: "" + type: string + php81: + description: "php8.1 image. e.g: 8.1.100" + default: "" + type: string + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + nginx: ["${{ inputs.nginx }}"] + php: ["8.3", "8.2", "8.1"] + include: + - php: "8.3" + tag: ${{ inputs.php83 }} + - php: "8.2" + tag: ${{ inputs.php82 }} + - php: "8.1" + tag: ${{ inputs.php81 }} + fail-fast: true + + steps: + - id: update + name: Update image + run: | + echo "nginx: ${{ matrix.nginx }}" + echo "tag: ${{ matrix.tag }}" + if [[ -z "${{ matrix.nginx }}" ]] || [[ -z "${{ matrix.tag }}" ]]; then + echo "no, no update" + echo "update=no" >> $GITHUB_OUTPUT + else + echo "yes, update" + echo "update=yes" >> $GITHUB_OUTPUT + fi + + - name: Generate tags + id: meta + if: steps.update.outputs.update == 'yes' + env: + IMAGES: "${{ secrets.DOCKERHUB_USERNAME }}/nginx-php ghcr.io/${{ github.actor }}/nginx-php" + run: | + IMAGE_TAGS='' + IFS=' ' read -ra IMAGE <<< "$IMAGES" + for element in "${IMAGE[@]}"; do + LAT_VER='' + if [[ "${{ matrix.php }}" == "8.3" ]]; then + LAT_VER="${element}:latest," + fi + PRE_VER="${element}:${{ matrix.php }}," + FUL_VER="${element}:${{ matrix.tag }}," + IMAGE_TAG="${LAT_VER}${PRE_VER}${FUL_VER}" + IMAGE_TAGS="${IMAGE_TAGS}${IMAGE_TAG}" + done + echo "IMAGE_TAGS=$IMAGE_TAGS" >> "$GITHUB_OUTPUT" + + - name: Set build args + if: steps.meta.outputs.IMAGE_TAGS != '' + run: | + PHP_VER=$(echo "${{ matrix.tag }}" | awk -F'.' '{ printf "%d.%d.%d", $1, $2, int($3/10) }') + echo "NGINX_VERSION=${{ matrix.nginx }}" >> $GITHUB_ENV + echo "PHP_VERSION=$PHP_VER" >> $GITHUB_ENV + + - name: Check out the repo + uses: actions/checkout@v4 + if: steps.meta.outputs.IMAGE_TAGS != '' + - name: Login into registry docker + uses: docker/login-action@v3 + if: steps.meta.outputs.IMAGE_TAGS != '' + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Login into registry ghcr + uses: docker/login-action@v3 + if: steps.meta.outputs.IMAGE_TAGS != '' + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + if: steps.meta.outputs.IMAGE_TAGS != '' + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + if: steps.meta.outputs.IMAGE_TAGS != '' + - name: Build and push + uses: docker/build-push-action@v5 + if: steps.meta.outputs.IMAGE_TAGS != '' + with: + platforms: ${{ inputs.platforms }} + file: Dockerfile + build-args: | + NGINX_VERSION=${{ env.NGINX_VERSION }} + PHP_VERSION=${{ env.PHP_VERSION }} + push: true + tags: "${{ steps.meta.outputs.IMAGE_TAGS }}" diff --git a/.github/workflows/jekyll-gh-pages.yml b/.github/workflows/jekyll-gh-pages.yml new file mode 100644 index 00000000..8ac7553f --- /dev/null +++ b/.github/workflows/jekyll-gh-pages.yml @@ -0,0 +1,51 @@ +# Sample workflow for building and deploying a Jekyll site to GitHub Pages +name: GitHub Pages + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main"] + paths: + - .github/workflows/jekyll-gh-pages.yml + - docs/** + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Build job + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v4 + - name: Build with Jekyll + uses: actions/jekyll-build-pages@v1 + with: + source: ./docs + destination: ./_site + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..f55b9419 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,87 @@ +name: test-ci + +on: + workflow_dispatch: + inputs: + platforms: + description: "buildx platforms" + default: "linux/amd64,linux/arm64" + required: true + type: string + nginx: + description: "nginx version" + default: "1.24.0" + required: true + type: string + php83: + description: "e.g: 8.3.000" + default: "" + type: string + php82: + description: "e.g: 8.2.010" + default: "" + type: string + php81: + description: "e.g: 8.1.100" + default: "" + type: string + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + nginx: ["${{ inputs.nginx }}"] + php: ["8.3", "8.2", "8.1"] + include: + - php: "8.3" + tag: ${{ inputs.php83 }} + - php: "8.2" + tag: ${{ inputs.php82 }} + - php: "8.1" + tag: ${{ inputs.php81 }} + fail-fast: true + + steps: + - id: update + name: Update image + run: | + echo "nginx: ${{ matrix.nginx }}" + echo "tag: ${{ matrix.tag }}" + if [[ -z "${{ matrix.nginx }}" ]] || [[ -z "${{ matrix.tag }}" ]]; then + echo "no, no update" + echo "update=no" >> $GITHUB_OUTPUT + else + echo "yes, update" + echo "update=yes" >> $GITHUB_OUTPUT + fi + - name: Matrix => (${{ matrix.php }} - ${{ matrix.tag }}) + if: steps.update.outputs.update == 'yes' + run: | + echo "update: ${{steps.update.outputs.update}}" + echo ${{ matrix.nginx }} + echo ${{ matrix.php }} + echo ${{ matrix.tag }} + - name: Generate tags + id: meta + if: steps.update.outputs.update == 'yes' + env: + IMAGES: "${{ secrets.DOCKERHUB_USERNAME }}/nginx-php ghcr.io/${{ github.actor }}/nginx-php" + run: | + IMAGE_TAGS='' + IFS=' ' read -ra IMAGE <<< "$IMAGES" + for element in "${IMAGE[@]}"; do + LAT_VER='' + if [[ "${{ matrix.php }}" == "8.3" ]]; then + LAT_VER="${element}:latest," + fi + PRE_VER="${element}:${{ matrix.php }}," + FUL_VER="${element}:${{ matrix.tag }}," + IMAGE_TAG="${LAT_VER}${PRE_VER}${FUL_VER}" + IMAGE_TAGS="${IMAGE_TAGS}${IMAGE_TAG}" + done + echo "IMAGE_TAGS=$IMAGE_TAGS" >> "$GITHUB_OUTPUT" + - name: Show docker tags + if: steps.meta.outputs.IMAGE_TAGS != '' + run: | + echo ${{ steps.meta.outputs.IMAGE_TAGS }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..97088b0c --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,25 @@ +stages: + - build + +build: + stage: build + image: docker:latest + services: + - name: docker:dind + artifacts: + expire_in: 1 d + variables: + D_USER: jetsung + rules: + - changes: + - Dockerfile + - build.sh + when: manual + allow_failure: false + before_script: | + echo "$DOCKERHUB_TOKEN" | docker login "${DOCKER_REGISTRY}" -u "$DOCKERHUB_USERNAME" --password-stdin + apk --update add git curl bash + script: + - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - docker buildx create --use --name mybuilder + - bash build.sh diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..7d4a1d79 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,28 @@ +# CHNAGELOG + +- Since [46fa6a0](https://github.com/jetsung/docker-nginx-php/tree/46fa6a0f2621a4369e3f369ce165383a81115b61) + +--- + +## 2022.01.22 + +Associated tags: `8.1.021, 8.0.151` + +Include extensions: +`bcmath,Core,ctype,curl,date,dom,exif,fileinfo,filter,ftp,gd,gettext,hash,iconv,intl,json,libxml,mbstring,mysqli,mysqlnd,openssl,pcntl,pcre,PDO,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,Phar,posix,redis,Reflection,session,shmop,SimpleXML,soap,sockets,sodium,SPL,sqlite3,standard,sysvsem,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib` + +1. The base image replaces almalinux with `ubuntu:20.04`. +2. Add `supervisor` to the image. +3. Remove extensions: `imagick,raphf,pq` +4. Add extensions: `pdo_pgsql,pgsql` + +--- + +## 2022.01.10 + +Associated tags: `8.1.013, 8.0.143, 7.4.273, 7.3, 7.2` + +Include extensions: +`bcmath,Core,ctype,curl,date,dom,exif,filter,ftp,gd,gettext,hash,iconv,intl,json,libxml,mbstring,mysqli,mysqlnd,openssl,pcntl,pcre,PDO,pdo_mysql,pdo_sqlite,Phar,posix,redis,Reflection,session,shmop,SimpleXML,soap,sockets,sodium,SPL,sqlite3,standard,sysvsem,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib` + +1. Add extensions: `fileinfo,pq,raphf,imagick,redis` diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a1b932f5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,162 @@ +FROM ubuntu:20.04 +LABEL maintainer="Jetsung Chan" +ARG NGINX_VERSION=1.21.5 +ARG PHP_VERSION=8.1.0 +ENV NGX_WWW_ROOT /data/wwwroot +ENV NGX_LOG_ROOT /data/wwwlogs +ENV TMP /tmp/nginx-php/ +ENV DEBIAN_FRONTEND=noninteractive +RUN mkdir -p /data/{wwwroot,wwwlogs,} +RUN set -eux \ + ; \ + apt-get update -y ; \ + pkgList="apt-utils zlib1g zlib1g-dev openssl libsqlite3-dev libxml2 libxml2-dev libcurl3-gnutls libcurl4-gnutls-dev libcurl4-openssl-dev libpng-dev libjpeg8 libjpeg8-dev libargon2-1 libargon2-dev libicu-dev libxslt1-dev libzip-dev libssl-dev libfreetype-dev libfreetype6 libpq-dev libpq5 libpcre3 libpcre3-dev libsodium-dev" ; \ + for Package in ${pkgList}; do \ + apt-get install -y --no-install-recommends ${Package} ; \ + done ; \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + gcc \ + g++ \ + make \ + cmake \ + autoconf \ + pkg-config \ + libtool \ + apt-utils \ + curl \ + supervisor ; \ + mkdir -p "${TMP}" && cd "${TMP}" ; \ + curl -Lk --retry 3 "https://github.com/kkos/oniguruma/releases/download/v6.9.7.1/onig-6.9.7.1.tar.gz" | gunzip | tar x \ + ; \ + # curl -Lk --retry 3 "https://github.com/jedisct1/libsodium/releases/download/1.0.18-RELEASE/libsodium-1.0.18.tar.gz" | gunzip | tar x \ + # curl -Lk --retry 3 "https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz" | gunzip | tar x \ + # ; \ + curl -Lk --retry 3 https://pecl.php.net/get/redis-5.3.7.tgz | gunzip | tar x \ + ; \ + curl -Lk --retry 3 "https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz" | gunzip | tar x \ + ; \ + curl -Lk --retry 3 "https://php.net/distributions/php-${PHP_VERSION}.tar.gz" | gunzip | tar x \ + ; \ + cd onig-6.9.7 ; \ + ./configure --prefix=/usr ; \ + make && make install ; \ + # cd .. ; \ + # cd libsodium-1.0.18 ; \ + # ./configure --disable-dependency-tracking --enable-minimal ; \ + # make && make install ; \ + cd .. ; \ + cd "php-${PHP_VERSION}" ; \ + export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig/ ; \ + ./configure --prefix=/usr/local/php/ \ + --with-config-file-path=/usr/local/php/etc/ \ + --with-config-file-scan-dir=/usr/local/php/etc/php.d/ \ + --with-fpm-user=www \ + --with-fpm-group=www \ + --with-mysqli=mysqlnd \ + --with-pdo-mysql=mysqlnd \ + --with-pgsql \ + --with-pdo-pgsql \ + --with-zip=/usr/local \ + --with-sodium \ + --with-openssl \ + --with-iconv \ + --with-zlib \ + --with-gettext \ + --with-curl \ + --with-freetype \ + --with-jpeg \ + --with-mhash \ + --with-xsl \ + --with-password-argon2 \ + --enable-fpm \ + --enable-xml \ + --enable-shmop \ + --enable-sysvsem \ + --enable-mbregex \ + --enable-mbstring \ + --enable-ftp \ + --enable-mysqlnd \ + --enable-pcntl \ + --enable-sockets \ + --enable-soap \ + --enable-session \ + --enable-bcmath \ + --enable-exif \ + --enable-intl \ + --enable-fileinfo \ + --enable-gd \ + --enable-ipv6 \ + --disable-opcache \ + --disable-rpath \ + --disable-debug \ + --without-pear \ + # --enable-opcache \ + # --disable-fileinfo \ + ; \ + make && make install ; \ + mkdir /usr/local/php/etc/php.d/ ; \ + cp php.ini-production /usr/local/php/etc/php.ini ; \ + cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf ; \ + cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf ; \ + ln -s /usr/local/php/bin/* /bin/ ; \ + ln -s /usr/local/php/sbin/* /bin/ ; \ + cd .. ; \ + php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" ; \ + # php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" ; \ + php composer-setup.php ; \ + php -r "unlink('composer-setup.php');" ; \ + mv composer.phar /usr/local/bin/composer ; \ + chmod +x /usr/local/bin/composer ; \ + EXTENSION_DIR=$(php-config --extension-dir) ; \ + cd redis-5.3.7 ; \ + phpize ; \ + ./configure --with-php-config=/usr/local/php/bin/php-config ; \ + make && make install ; \ + if [ -f "${EXTENSION_DIR}/redis.so" ]; then \ + echo 'extension=redis.so' > /usr/local/php/etc/php.d/05-redis.ini ; \ + fi ; \ + cd .. ; \ + cd "nginx-${NGINX_VERSION}" ; \ + ./configure --prefix=/usr/local/nginx \ + --user=www --group=www \ + --error-log-path="${NGX_LOG_ROOT}/nginx_error.log" \ + --http-log-path="${NGX_LOG_ROOT}/nginx_access.log" \ + --pid-path=/var/run/nginx.pid \ + --with-pcre \ + --with-http_ssl_module \ + --with-http_v2_module \ + --without-mail_pop3_module \ + --without-mail_imap_module \ + --with-http_gzip_static_module \ + ; \ + make && make install ; \ + ln -s /usr/local/nginx/sbin/* /bin/ ; \ + useradd -r -s /sbin/nologin -d "${NGX_WWW_ROOT}" -m -k no www ; \ + cd / ; \ + rm -rf "${TMP}" ; \ + apt-get remove -y gcc \ + g++ \ + autoconf \ + automake \ + libtool \ + make \ + cmake \ + ; \ + apt-get autoremove -y ; \ + apt-get autoclean -y ; \ + apt-get clean -y ; \ + rm -rf /var/lib/apt/lists/* ; \ + find /var/log -type f -delete +VOLUME ["/data/wwwroot", "/data/wwwlogs"] +WORKDIR /app +EXPOSE 80 443 9000 +COPY nginx.conf /usr/local/nginx/conf/ +COPY vhost /usr/local/nginx/conf/vhost/ +COPY www "${NGX_WWW_ROOT}" +COPY supervisord /etc/supervisor/conf.d/ +COPY entrypoint.sh /app +RUN chown -R www:www "${NGX_WWW_ROOT}" ; \ + chmod +x /app/entrypoint.sh +ENTRYPOINT ["/app/entrypoint.sh"] +CMD ["-D"] diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..30d27e38 --- /dev/null +++ b/build.sh @@ -0,0 +1,188 @@ +#!/usr/bin/env bash + +####### Build Script ####### + +show_errmsg() { + printf "\e[1;31m%s \e[0m\n" "${1}" + exit 1 +} + +version_split() { + tag_full_ver="${1}" # "8.2.080" 或 "8.2.180" + tag_pre_ver=${tag_full_ver:0:3} + + ver1=${tag_full_ver:4:2} + ver1=${ver1#0} # 移除前导零,以确保数字被解释为十进制 + + php_ver="${tag_pre_ver}.${ver1}" + + printf " +TAG FULL: %s +TAG PRE VER: %s +PHP VERSION: %s +" "$tag_full_ver" "$tag_pre_ver" "$php_ver" +} + +# docker buildx +docker_buildx() { + printf " +TAGS: + %snginx-php:%s + %snginx-php:%s +" "$prefix" "$tag_full_ver" "$prefix" "$tag_pre_ver" + + docker login ghcr.io + + if [[ "$tag_pre_ver" = "8.2" ]]; then + # docker buildx build --platform linux/amd64,linux/arm64 \ + docker buildx build --platform "${D_PLATFORM}" \ + --output "type=image,push=${D_PUSH}" \ + --tag "${prefix}nginx-php:${tag_full_ver}" \ + --tag "${prefix}nginx-php:${tag_pre_ver}" \ + --tag "${prefix}nginx-php:latest" \ + --build-arg PHP_VERSION="${php_ver}" \ + --build-arg NGINX_VERSION="${NGINX_VERSION}" \ + --build-arg GH_MIRROR_URL="${GH_MIRROR_URL}" \ + --file ./Dockerfile \ + --progress plain \ + . + + # ghcr + GH_CR_PRE="ghcr.io/${prefix}nginx-php:tag_pre_ver" + GH_CR_LATEST="ghcr.io/${prefix}nginx-php:latest" + docker tag "${prefix}nginx-php:tag_pre_ver" "$GH_CR_PRE" + docker tag "${prefix}nginx-php:latest" "$GH_CR_LATEST" + docker push --platform "${D_PLATFORM}" "$GH_CR_PRE" + docker push --platform "${D_PLATFORM}" "$GH_CR_LATEST" + else + # docker buildx build --platform linux/amd64,linux/arm64 \ + docker buildx build --platform "${D_PLATFORM}" \ + --output "type=image,push=${D_PUSH}" \ + --tag "${prefix}nginx-php:${tag_full_ver}" \ + --tag "${prefix}nginx-php:${tag_pre_ver}" \ + --build-arg PHP_VERSION="${php_ver}" \ + --build-arg NGINX_VERSION="${NGINX_VERSION}" \ + --build-arg GH_MIRROR_URL="${GH_MIRROR_URL}" \ + --file ./Dockerfile \ + --progress plain \ + . + + # ghcr + GH_CR_PRE="ghcr.io/${prefix}nginx-php:tag_pre_ver" + docker tag "${prefix}nginx-php:tag_pre_ver" "$GH_CR_PRE" + docker push --platform "${D_PLATFORM}" "$GH_CR_PRE" + fi +} + +# 只当前构架,不使用 QEMU +docker_build() { + # 构建 + docker_tag + + # 推送 + if [[ "${D_PUSH}" = "true" ]]; then + docker_push + fi +} + +# 构建与生成 TAG +docker_tag() { + docker build --build-arg PHP_VERSION="${php_ver}" \ + --build-arg NGINX_VERSION="${NGINX_VERSION}" \ + --build-arg GH_MIRROR_URL="${GH_MIRROR_URL}" \ + -t "${prefix}"nginx-php:"${tag_full_ver}" \ + -f ./Dockerfile . || + show_errmsg "docker build failed" + + image_id=$(docker images | grep "${prefix}"nginx-php | grep "${tag_full_ver}" | awk '{print $3}') + + docker tag "${image_id}" "${prefix}"nginx-php:"${tag_pre_ver}" || show_errmsg "docker tag failed" + + if [[ "${tag_pre_ver}" = "8.3" ]]; then + docker tag "${image_id}" "${prefix}"nginx-php:latest + fi +} + +# 推送 +docker_push() { + docker push "${prefix}"nginx-php:"${tag_full_ver}" + docker push "${prefix}"nginx-php:"${tag_pre_ver}" + + if [[ "${tag_pre_ver}" = "8.3" ]]; then + docker push "${prefix}"nginx-php:latest + fi +} + +build() { + version_split "${1}" + + rm -rf ./logoutput.log + if [ -z "$BUILDX_ENABLE" ]; then + # 不使用 buildx,只编译 amd64 + echo "build" + docker_build 2>&1 | tee ./logoutput.log + else + # 使用 docker buildx + echo "buildx" + docker_buildx 2>&1 | tee ./logoutput.log + fi + + # https://github.com/dutchcoders/transfer.sh/ + #curl --upload-file ./logoutput.log https://transfer.sh/logoutput.log +} + +main() { + set -e + + if [ -z "${1}" ]; then + prefix="jetsung/" + else + prefix="${1}/" + fi + + if [ -z "${D_PUSH}" ]; then + D_PUSH="false" # 是否推送 + fi + + if [ -z "${D_PLATFORM}" ]; then + D_PLATFORM="linux/amd64,linux/arm64" # 构建环境 + fi + + # locale env + if [[ "${2}" = "env" ]] && [ -f ".env" ]; then + # shellcheck disable=SC1091 + source .env + fi + + # 架构大于 1 则使用 buildx + if echo "$D_PLATFORM" | grep -q ','; then + BUILDX_ENABLE="yes" + fi + + build_time=$(date "+%F %T") + _PUSH=$(echo "${D_PUSH}" | tr '[:lower:]' '[:upper:]') + _PLAT_FORM=$(echo "${D_PLATFORM}" | tr '[:lower:]' '[:upper:]') + printf " +****** [ BUILD START ] ****** +build time: %s +docker push: %s +build platform: %s +php version: %s +prefix: %s +gh_proxy: %s +" "$build_time" "$_PUSH" "$_PLAT_FORM" "$IMAGE_VERSION" "$prefix" "$GH_MIRROR_URL" + + string="$IMAGE_VERSION" + array=${string//,/ } + + # shellcheck disable=SC2068 + for var in ${array[@]}; do + # echo "${var}" + build "$var" + done + +} + +main "$@" || exit 1 + +# ./build.sh jetsung env diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 00000000..a0f0e538 --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1,2 @@ +.vscode +.DS_Store diff --git a/docs/CNAME b/docs/CNAME new file mode 100644 index 00000000..15563a00 --- /dev/null +++ b/docs/CNAME @@ -0,0 +1 @@ +nginx-php.222029.xyz \ No newline at end of file diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..d03ca92b --- /dev/null +++ b/docs/README.md @@ -0,0 +1,164 @@ +This example is based on the source code: +[https://github.com/jetsung/docker-nginx-php/tree/main/example](https://github.com/jetsung/docker-nginx-php/tree/main/example) + +English | [简体中文](./README_CN.md) + +### Include extensions + +```bash +bcmath,Core,ctype,curl,date,dom,exif,fileinfo,filter,ftp,gd,gettext,hash,iconv,intl,json,libxml,mbstring,mysqli,mysqlnd,openssl,pcntl,pcre,PDO,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,Phar,posix,redis,Reflection,session,shmop,SimpleXML,soap,sockets,sodium,SPL,sqlite3,standard,sysvsem,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib +``` + +> [Custom extension](#custom-extension) + +### Container Hub + +1. **[Docker Hub: `nginx-php`](https://hub.docker.com/r/jetsung/nginx-php)** + +```bash +docker pull jetsung/nginx-php:latest +``` + +2. **[GitHub Packages: `nginx-php`](https://github.com/jetsung/docker-nginx-php/pkgs/container/nginx-php)** + +```bash +docker pull ghcr.io/jetsung/nginx-php:latest +``` + +### Command line tools + +Use `docker exec {CONTAINER ID} {COMMAND}` + +```bash +# Current process +docker exec {CONTAINER ID} ps -ef +# Current PHP version +docker exec {CONTAINER ID} php --version + +# supervisord +## HELP +docker exec {CONTAINER ID} supervisorctl --help +## STOP, START, STATUS (stop/start/status) +docker exec {CONTAINER ID} supervisorctl stop all +## STOP NGINX / PHP +docker exec {CONTAINER ID} supervisorctl stop nginx/php-fpm + +# Container not started +## PHP version +docker run --rm -it jetsung/nginx-php:latest php --version + +## NGINX version +docker run --rm -it jetsung/nginx-php:latest nginx -v +``` + +### Default + +``` +docker run -d -p 38080:80 \ +jetsung/nginx-php +``` + +[http://docker.222029.xyz:38080](http://docker.222029.xyz:38080) + +- `docker-compose.yml` + +```yaml +version: "3" +services: + nginx-php: + image: jetsung/nginx-php:latest + ports: + - "38080:80" +``` + +--- + +### Custom website directory + +``` +docker run -d -p 38081:80 \ +-v $(pwd)/wwwroot:/data/wwwroot \ +jetsung/nginx-php +``` + +[http://docker.222029.xyz:38081](http://docker.222029.xyz:38081) + +- `docker-compose.yml` + +```yaml +version: "3" +services: + nginx-php: + image: jetsung/nginx-php:latest + volumes: + - ./wwwroot:/data/wwwroot + ports: + - "38081:80" +``` + +--- + +### Bind the domain and the `SSL` certificate, make it to support `HTTPS`. + +``` +docker run -d -p 38082:80 \ +-p 38083:443 \ +-v $(pwd)/wwwroot:/data/wwwroot \ +-v $(pwd)/wwwlogs:/data/wwwlogs \ +-v $(pwd)/vhost:/usr/local/nginx/conf/vhost \ +-v $(pwd)/ssl:/usr/local/nginx/conf/ssl \ +jetsung/nginx-php +``` + +[http://docker.222029.xyz:38082](http://docker.222029.xyz:38082) +[https://docker.222029.xyz:38083](https://docker.222029.xyz:38083) + +- `docker-compose.yml` + +```yaml +version: "3" +services: + nginx-php: + image: jetsung/nginx-php:latest + volumes: + - ./wwwroot:/data/wwwroot + - ./wwwlogs:/data/wwwlogs + - ./vhost:/usr/local/nginx/conf/vhost + - ./ssl:/usr/local/nginx/conf/ssl + ports: + - "38082:80" + - "38083:443" +``` + +--- + +### Custom extension + +``` +docker run -d -p 38084:80 \ +-v $(pwd)/wwwroot:/data/wwwroot \ +-v $(pwd)/wwwlogs:/data/wwwlogs \ +-v $(pwd)/extension.sh:/app/extension.sh \ +jetsung/nginx-php +``` + +> Create a file `extension.sh` (you cannot change the file name),context as [swoole](https://github.com/jetsung/docker-nginx-php/blob/main/extensions/swoole.sh) + +[http://docker.222029.xyz:38084](http://docker.222029.xyz:38084) + +- `docker-compose.yml` + +```yaml +version: "3" +services: + nginx-php: + image: jetsung/nginx-php:latest + volumes: + - ./wwwroot:/data/wwwroot + - ./wwwlogs:/data/wwwlogs + - ./extension.sh:/app/extension.sh + ports: + - "38084:80" +``` + +### [Changelog](https://github.com/jetsung/docker-nginx-php/blob/main/CHANGELOG.md) diff --git a/docs/README_CN.md b/docs/README_CN.md new file mode 100644 index 00000000..0b54e5a9 --- /dev/null +++ b/docs/README_CN.md @@ -0,0 +1,164 @@ +案例基于源码: +[https://github.com/jetsung/docker-nginx-php/tree/main/example](https://github.com/jetsung/docker-nginx-php/tree/main/example) + +[English](./README.md) | 简体中文 + +### 包含扩展 + +```bash +bcmath,Core,ctype,curl,date,dom,exif,fileinfo,filter,ftp,gd,gettext,hash,iconv,intl,json,libxml,mbstring,mysqli,mysqlnd,openssl,pcntl,pcre,PDO,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,Phar,posix,redis,Reflection,session,shmop,SimpleXML,soap,sockets,sodium,SPL,sqlite3,standard,sysvsem,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib +``` + +> [定制扩展](#定制扩展) + +### Container Hub + +1. **[Docker Hub: `nginx-php`](https://hub.docker.com/r/jetsung/nginx-php)** + +```bash +docker pull jetsung/nginx-php:latest +``` + +2. **[GitHub Packages: `nginx-php`](https://github.com/jetsung/docker-nginx-php/pkgs/container/nginx-php)** + +```bash +docker pull ghcr.io/jetsung/nginx-php:latest +``` + +### 命令行工具 + +使用 `docker exec {CONTAINER ID} {COMMAND}` + +```bash +# 查看当前进程 +docker exec {CONTAINER ID} ps -ef +# 查看当前 PHP 版本 +docker exec {CONTAINER ID} php --version + +# supervisord +## 帮助 +docker exec {CONTAINER ID} supervisorctl --help +## 停止、启动、状态 (stop/start/status) +docker exec {CONTAINER ID} supervisorctl stop all +## 停止 NGINX / PHP +docker exec {CONTAINER ID} supervisorctl stop nginx/php-fpm + +# 未启动容器 +## 查看 PHP 版本 +docker run --rm -it jetsung/nginx-php:latest php --version + +## 查看 NGINX 版本 +docker run --rm -it jetsung/nginx-php:latest nginx -v +``` + +### 默认 + +``` +docker run -d -p 38080:80 \ +jetsung/nginx-php +``` + +[http://docker.222029.xyz:38080](http://docker.222029.xyz:38080) + +- `docker-compose.yml` + +```yaml +version: "3" +services: + nginx-php: + image: jetsung/nginx-php:latest + ports: + - "38080:80" +``` + +--- + +### 自定义网站目录 + +``` +docker run -d -p 38081:80 \ +-v $(pwd)/wwwroot:/data/wwwroot \ +jetsung/nginx-php +``` + +[http://docker.222029.xyz:38081](http://docker.222029.xyz:38081) + +- `docker-compose.yml` + +```yaml +version: "3" +services: + nginx-php: + image: jetsung/nginx-php:latest + volumes: + - ./wwwroot:/data/wwwroot + ports: + - "38081:80" +``` + +--- + +### 绑定域名 和 使用 `SSL` 证书,让网站支持 `HTTPS` + +``` +docker run -d -p 38082:80 \ +-p 38083:443 \ +-v $(pwd)/wwwroot:/data/wwwroot \ +-v $(pwd)/wwwlogs:/data/wwwlogs \ +-v $(pwd)/vhost:/usr/local/nginx/conf/vhost \ +-v $(pwd)/ssl:/usr/local/nginx/conf/ssl \ +jetsung/nginx-php +``` + +[http://docker.222029.xyz:38082](http://docker.222029.xyz:38082) +[https://docker.222029.xyz:38083](https://docker.222029.xyz:38083) + +- `docker-compose.yml` + +```yaml +version: "3" +services: + nginx-php: + image: jetsung/nginx-php:latest + volumes: + - ./wwwroot:/data/wwwroot + - ./wwwlogs:/data/wwwlogs + - ./vhost:/usr/local/nginx/conf/vhost + - ./ssl:/usr/local/nginx/conf/ssl + ports: + - "38082:80" + - "38083:443" +``` + +--- + +### 定制扩展 + +``` +docker run -d -p 38084:80 \ +-v $(pwd)/wwwroot:/data/wwwroot \ +-v $(pwd)/wwwlogs:/data/wwwlogs \ +-v $(pwd)/extension.sh:/app/extension.sh \ +jetsung/nginx-php +``` + +> 创建文件 `extension.sh` (不可更改文件名),内容为 [swoole](https://github.com/jetsung/docker-nginx-php/blob/main/extensions/swoole.sh) + +[http://docker.222029.xyz:38084](http://docker.222029.xyz:38084) + +- `docker-compose.yml` + +```yaml +version: "3" +services: + nginx-php: + image: jetsung/nginx-php:latest + volumes: + - ./wwwroot:/data/wwwroot + - ./wwwlogs:/data/wwwlogs + - ./extension.sh:/app/extension.sh + ports: + - "38084:80" +``` + +### [Changelog](https://github.com/jetsung/docker-nginx-php/blob/main/CHANGELOG.md) diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 00000000..2da5da2c --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1,11 @@ +theme: jekyll-theme-cayman +title: nginx-php +description: Nginx PHP for Docker +encoding: UTF-8 +highlighter: rouge + +copyright: +year: 2018-2024 +name: Jetsung Chan + +timezone: Asia/Shanghai diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 00000000..baacf814 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,58 @@ +#!/bin/bash +######################################################################### +# START +# File Name: entrypoint.sh +# Author: Jetsung Chan +# Email: jetsungchan@gmail.com +# Created: 2019/09/02 +# Updated: 2023/03/11 +######################################################################### + +set -e +set -u +set -o pipefail + +install_tools() { + apt-get update -y + apt-get install -y gcc \ + g++ \ + autoconf \ + automake \ + make \ + cmake +} + +clear_tools() { + apt-get remove -y gcc \ + g++ \ + autoconf \ + automake \ + make \ + cmake + apt-get autoremove -y + apt-get autoclean -y + apt-get clean -y +} + +# Add PHP Extension +install_extensions() { + if [ -f "/app/extension.sh" ] && [ ! -f /app/.installed ]; then + pushd /app >/dev/null || exit + install_tools + + bash extension.sh + date "+%F %T" >>/app/.installed + + #clear_tools + popd >/dev/null || exit + fi +} + +if [[ "${1}" = "-D" ]]; then + install_extensions 2>&1 | tee ./install.log + + # start supervisord and services + exec /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf +else + exec "$@" +fi diff --git a/example/README.md b/example/README.md new file mode 100644 index 00000000..f803b1e9 --- /dev/null +++ b/example/README.md @@ -0,0 +1,27 @@ +## Example + +```bash +cd example + +docker run -p 8080:80 \ +-p 8443:443 \ +-v $(pwd)/wwwroot:/data/wwwroot \ +-v $(pwd)/wwwlogs:/data/wwwlogs \ +-v $(pwd)/vhost:/usr/local/nginx/conf/vhost \ +-v $(pwd)/ssl:/usr/local/nginx/conf/ssl +-v $(pwd)/extension.sh:/app/extension.sh \ +-d jetsung/nginx-php:latest +``` + +### WEB + +- **HTTP**: http://127.0.0.1:8080 +- **HTTPS**: https://127.0.0.1:8443 + +If you modify the hosts, you can open the website with the domain. + +- https://docker.222029.xyz:8443 + +```bash +echo '0.0.0.0 docker.222029.xyz' >> /etc/hosts +``` diff --git a/example/docker-compose.yml b/example/docker-compose.yml new file mode 100644 index 00000000..7bb05246 --- /dev/null +++ b/example/docker-compose.yml @@ -0,0 +1,34 @@ +version: "3" + +x-image: &x-image + image: jetsung/nginx-php:latest + +services: + p38080: + <<: *x-image + ports: + - "38080:80" + p38081: + <<: *x-image + volumes: + - ./wwwroot:/data/wwwroot + ports: + - "38081:80" + p38082: + <<: *x-image + volumes: + - ./wwwroot:/data/wwwroot + - ./wwwlogs:/data/wwwlogs + - ./vhost:/usr/local/nginx/conf/vhost + - ./ssl:/usr/local/nginx/conf/ssl + ports: + - "38082:80" + - "38083:443" + p38084: + <<: *x-image + volumes: + - ./wwwroot:/data/wwwroot + - ./wwwlogs:/data/wwwlogs + - ./extension.sh:/app/extension.sh + ports: + - "38084:80" diff --git a/example/extension.sh b/example/extension.sh new file mode 100755 index 00000000..b3d4f4f2 --- /dev/null +++ b/example/extension.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +install_swoole() { + curl -Lk https://github.com/swoole/swoole-src/archive/v4.8.13.tar.gz | gunzip | tar x + cd swoole-src-4.8.13 || exit + + phpize + ./configure --with-php-config=/usr/local/php/bin/php-config + make && make install + + EXTENSION_DIR=$(php-config --extension-dir) + if [ -f "$EXTENSION_DIR/swoole.so" ]; then + echo 'extension=swoole.so' >/usr/local/php/etc/php.d/03-swoole.ini + fi +} + +[ -d "/tmp/extension" ] || mkdir /tmp/extension + +pushd /tmp/extension || exit +UNINSTALLED=$(php --ri swoole | grep 'not present') +[ -z "$UNINSTALLED" ] || install_swoole +popd || exit diff --git a/example/ssl/full_chain.pem b/example/ssl/full_chain.pem new file mode 100644 index 00000000..716cc950 --- /dev/null +++ b/example/ssl/full_chain.pem @@ -0,0 +1,51 @@ +-----BEGIN CERTIFICATE----- +MIIEfzCCBCSgAwIBAgIQBOqE5SG8gOjYbPtQv0q23TAKBggqhkjOPQQDAjByMQsw +CQYDVQQGEwJDTjElMCMGA1UEChMcVHJ1c3RBc2lhIFRlY2hub2xvZ2llcywgSW5j +LjEdMBsGA1UECxMURG9tYWluIFZhbGlkYXRlZCBTU0wxHTAbBgNVBAMTFFRydXN0 +QXNpYSBUTFMgRUNDIENBMB4XDTIxMDcyMDAwMDAwMFoXDTIyMDcxOTIzNTk1OVow +GjEYMBYGA1UEAxMPZG9ja2VyLm1tYXBwLmNjMFkwEwYHKoZIzj0CAQYIKoZIzj0D +AQcDQgAEquV1mGKu5uoj4coPUrkKB96EHFxPSBMlkND0ycU9Ft6q7CdsiBjD+reh +lakiBlsturExJZQWR0maLfyWhP0uoKOCAvIwggLuMB8GA1UdIwQYMBaAFBKGRGYm +CFQmj2U3silOJiHgk77bMB0GA1UdDgQWBBQg8OlgWXX4hhZTz6gfXBz5qiXnwzAa +BgNVHREEEzARgg9kb2NrZXIubW1hcHAuY2MwDgYDVR0PAQH/BAQDAgeAMB0GA1Ud +JQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjA+BgNVHSAENzA1MDMGBmeBDAECATAp +MCcGCCsGAQUFBwIBFhtodHRwOi8vd3d3LmRpZ2ljZXJ0LmNvbS9DUFMwgZIGCCsG +AQUFBwEBBIGFMIGCMDQGCCsGAQUFBzABhihodHRwOi8vc3RhdHVzZi5kaWdpdGFs +Y2VydHZhbGlkYXRpb24uY29tMEoGCCsGAQUFBzAChj5odHRwOi8vY2FjZXJ0cy5k +aWdpdGFsY2VydHZhbGlkYXRpb24uY29tL1RydXN0QXNpYVRMU0VDQ0NBLmNydDAJ +BgNVHRMEAjAAMIIBfwYKKwYBBAHWeQIEAgSCAW8EggFrAWkAdgApeb7wnjk5IfBW +c59jpXflvld9nGAK+PlNXSZcJV3HhAAAAXrDjdcnAAAEAwBHMEUCIEMFK+mQTIg1 ++41PQE79Z9bHGxW/OtQ7RKBRCgqm7VprAiEAxxQdTzcy7AOo97PAIW35KAfz2YBO +IX8h+3Y6cjLOjBMAdwBRo7D1/QF5nFZtuDd4jwykeswbJ8v3nohCmg3+1IsF5QAA +AXrDjde7AAAEAwBIMEYCIQDB8ZebIvSi7jqAmepK6iPoHLq2iDgFY7PvxubTC466 +iQIhAOfj2w/eRm6j5TiHLNFJA0Tc0oBYqEJXIWOERyaQ4CMmAHYAQcjKsd8iRkoQ +xqE6CUKHXk4xixsD6+tLx2jwkGKWBvYAAAF6w43XRgAABAMARzBFAiEAvnBaHWyE +CnJft3bbOnXMS8+IJFQI8sQjkw6zmZ6HmzMCIF7dNf51q3vN6wcokBxJ25VJe/fx +g5B91h3B11SXniccMAoGCCqGSM49BAMCA0kAMEYCIQCLHbR9C2zzYY7qlm20QdU1 +TXQzFDum0flnig0+ksIUawIhANyQdxR9ux0WYTJX4VIPN8DwJEu9HtGdtfKWmVaL +ItYG +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIID4zCCAsugAwIBAgIQBz/JpHsGAhj24Khq6fw+OzANBgkqhkiG9w0BAQsFADBh +MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 +d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD +QTAeFw0xNzEyMDgxMjI4NTdaFw0yNzEyMDgxMjI4NTdaMHIxCzAJBgNVBAYTAkNO +MSUwIwYDVQQKExxUcnVzdEFzaWEgVGVjaG5vbG9naWVzLCBJbmMuMR0wGwYDVQQL +ExREb21haW4gVmFsaWRhdGVkIFNTTDEdMBsGA1UEAxMUVHJ1c3RBc2lhIFRMUyBF +Q0MgQ0EwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASdQvDzv44jBee0APcvKOWs +zZsRjc4j+L6DLlYOf9tSgvfOJplfMeDNDZzOQEcJbVPD+yekJQUmObCPOrgMhqMI +o4IBTzCCAUswHQYDVR0OBBYEFBKGRGYmCFQmj2U3silOJiHgk77bMB8GA1UdIwQY +MBaAFAPeUDVW0Uy7ZvCj4hsbw5eyPdFVMA4GA1UdDwEB/wQEAwIBhjAdBgNVHSUE +FjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwEgYDVR0TAQH/BAgwBgEB/wIBADA0Bggr +BgEFBQcBAQQoMCYwJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmRpZ2ljZXJ0LmNv +bTBCBgNVHR8EOzA5MDegNaAzhjFodHRwOi8vY3JsMy5kaWdpY2VydC5jb20vRGln +aUNlcnRHbG9iYWxSb290Q0EuY3JsMEwGA1UdIARFMEMwNwYJYIZIAYb9bAECMCow +KAYIKwYBBQUHAgEWHGh0dHBzOi8vd3d3LmRpZ2ljZXJ0LmNvbS9DUFMwCAYGZ4EM +AQIBMA0GCSqGSIb3DQEBCwUAA4IBAQBZcGGhLE09CbQD5xP93NAuNC85G1BMa1OG +2Q01TWvvgp7Qt1wNfRLAnhQT5pb7kRs+E7nM4IS894ufmuL452q8gYaq5HmvOmfh +XMmL6K+eICfvyqjb/tSi8iy20ULO/TZhLhPor9tle52Yx811FG4i5vqwPIUEOEJ7 +pXe6RPVoBiwi4rbLspQGD/vYqrj9OJV4JctoIhhGq+y/sozU6nBXHfhVSD3x+hkO +Ost6tyRq481IyUWQHcFtwda3gfMnaA3dsag2dtJz33RIJIUfxXmVK7w4YzHOHifn +7TYk8iNrDDLtql6vS8FjiUx3kJnI6zge1C9lUHhZ/aD3RiTJrwWI +-----END CERTIFICATE----- + diff --git a/example/ssl/private.key b/example/ssl/private.key new file mode 100644 index 00000000..5fce49ff --- /dev/null +++ b/example/ssl/private.key @@ -0,0 +1,6 @@ +-----BEGIN PRIVATE KEY----- +MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQg/BfXcai3L4u30njh +svZ30PcYsMO/T+JkOe+RqIahwiagCgYIKoZIzj0DAQehRANCAASq5XWYYq7m6iPh +yg9SuQoH3oQcXE9IEyWQ0PTJxT0W3qrsJ2yIGMP6t6GVqSIGWy26sTEllBZHSZot +/JaE/S6g +-----END PRIVATE KEY----- diff --git a/example/vhost/localhost.conf b/example/vhost/localhost.conf new file mode 100644 index 00000000..ac7fa233 --- /dev/null +++ b/example/vhost/localhost.conf @@ -0,0 +1,54 @@ +server { + listen 80; + server_name localhost docker.222029.xyz; + root /data/wwwroot; + 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; + # } + + location / { + if (!-e $request_filename) { + rewrite ^(.*)$ /index.php?s=$1 last; + break; + } + } + + 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 ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { + expires 30d; + access_log off; + } + + location ~ .*\.(js|css)?$ { + expires 7d; + access_log off; + } + + location ~ /\.(ht|git|vscode|idea) { + deny all; + } + + # https + listen 443 ssl http2; + ssl_certificate ssl/full_chain.pem; + ssl_certificate_key ssl/private.key; + ssl_protocols TLSv1.1 TLSv1.2; + ssl_prefer_server_ciphers on; + ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; + keepalive_timeout 70; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 10m; +} diff --git a/example/wwwlogs/.gitkeep b/example/wwwlogs/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/example/wwwroot/index.html b/example/wwwroot/index.html new file mode 100644 index 00000000..ff211417 --- /dev/null +++ b/example/wwwroot/index.html @@ -0,0 +1,50 @@ + + + + + + Test Page - nginx-php Project + + + + + + + + \ No newline at end of file diff --git a/example/wwwroot/phpinfo.php b/example/wwwroot/phpinfo.php new file mode 100644 index 00000000..e974c40d --- /dev/null +++ b/example/wwwroot/phpinfo.php @@ -0,0 +1 @@ +/usr/local/php/etc/php.d/04-fileinfo.ini + fi +} + +[ -d "/tmp/extension" ] || mkdir /tmp/extension + +pushd /tmp/extension || exit +UNINSTALLED=$(php --ri fileinfo | grep 'not present') +[ -z "$UNINSTALLED" ] || install_fileinfo +popd || exit diff --git a/extensions/imagick.sh b/extensions/imagick.sh new file mode 100644 index 00000000..bea031b2 --- /dev/null +++ b/extensions/imagick.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +install_imagemagick() { + curl -Lk https://ghproxy.com/https://github.com/ImageMagick/ImageMagick/archive/refs/tags/7.1.0-19.tar.gz | gunzip | tar x + + cd ImageMagick-7.1.0-19 || exit + ./configure --prefix=/usr/local/imagemagick --enable-shared --enable-static + make && make install + + cd .. +} + +install_pecl_imagick() { + apt-get install -y libmagickwand-dev + # or + # install_imagemagick + + curl -Lk https://pecl.php.net/get/imagick-3.6.0.tgz | gunzip | tar x + cd imagick-3.6.0 || exit + + phpize + ./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick + make && make install + + EXTENSION_DIR=$(php-config --extension-dir) + if [ -f "$EXTENSION_DIR/imagick.so" ]; then + echo 'extension=imagick.so' >/usr/local/php/etc/php.d/03-imagick.ini + fi + + cd .. +} + +[ -d "/tmp/extension" ] || mkdir /tmp/extension + +pushd /tmp/extension || exit +UNINSTALLED=$(php --ri imagick | grep 'not present') +[ -z "$UNINSTALLED" ] || install_pecl_imagick +popd || exit diff --git a/extensions/imap.sh b/extensions/imap.sh new file mode 100644 index 00000000..44b658a1 --- /dev/null +++ b/extensions/imap.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +install_imap() { + apt-get install -y libc-client-dev libkrb5-dev + + PHP_VER=$(php-config --version) + [ -d "php-${PHP_VER}" ] || curl -Lk https://secure.php.net/distributions/php-"${PHP_VER}".tar.gz | gunzip | tar x + cd "php-$PHP_VER/ext/imap" || exit + + phpize + ./configure --with-php-config=/usr/local/php/bin/php-config --with-kerberos --with-imap --with-imap-ssl + make && make install + + EXTENSION_DIR=$(php-config --extension-dir) + if [ -f "$EXTENSION_DIR/imap.so" ]; then + echo 'extension=imap.so' >/usr/local/php/etc/php.d/04-imap.ini + fi +} + +[ -d "/tmp/extension" ] || mkdir /tmp/extension + +pushd /tmp/extension || exit +UNINSTALLED=$(php --ri imap | grep 'not present') +[ -z "$UNINSTALLED" ] || install_imap +popd || exit diff --git a/extensions/memcached.sh b/extensions/memcached.sh new file mode 100644 index 00000000..8edde0c3 --- /dev/null +++ b/extensions/memcached.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +install_pecl_memcached() { + apt-get install -y libmemcached-dev + + curl -Lk https://pecl.php.net/get/memcached-3.1.5.tgz | gunzip | tar x + cd memcached-3.1.5 || exit + + phpize + ./configure --with-php-config=/usr/local/php/bin/php-config + make && make install + + EXTENSION_DIR=$(php-config --extension-dir) + if [ -f "$EXTENSION_DIR/memcached.so" ]; then + echo 'extension=memcached.so' >/usr/local/php/etc/php.d/05-memcached.ini + fi + + cd .. +} + +install_pecl_memcache() { + curl -Lk https://pecl.php.net/get/memcache-8.0.tgz | gunzip | tar x + cd memcache-8.0 || exit + + phpize + ./configure --with-php-config=/usr/local/php/bin/php-config + make && make install + + EXTENSION_DIR=$(php-config --extension-dir) + if [ -f "$EXTENSION_DIR/memcache.so" ]; then + echo 'extension=memcache.so' >/usr/local/php/etc/php.d/05-memcache.ini + fi + + cd .. +} + +[ -d "/tmp/extension" ] || mkdir /tmp/extension + +pushd /tmp/extension || exit +UNINSTALLED=$(php --ri memcache | grep 'not present') +[ -z "$UNINSTALLED" ] || install_pecl_memcache + +UNINSTALLED=$(php --ri memcached | grep 'not present') +[ -z "$UNINSTALLED" ] || install_pecl_memcached +popd || exit diff --git a/extensions/merge.sh b/extensions/merge.sh new file mode 100755 index 00000000..c3bce7c2 --- /dev/null +++ b/extensions/merge.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +######## 合并多个扩展安装文件 ############ + +READ_LINK=$(readlink -f "$0") +TOOLS_DIR=$(dirname "$READ_LINK") + +pushd "${TOOLS_DIR}" >/dev/null || exit + +EXTS=$(ls ./*.sh) +echo >./extension.sh + +for VAR in ${EXTS}; do + if [[ "$VAR" != "merge.sh" ]] && [[ "$VAR" != "extension.sh" ]]; then + cat "$VAR" >>./extension.sh + fi +done + +popd >/dev/null || exit diff --git a/extensions/opcache.sh b/extensions/opcache.sh new file mode 100644 index 00000000..0dc446c4 --- /dev/null +++ b/extensions/opcache.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +install_opcache() { + PHP_VER=$(php-config --version) + [ -d "php-$PHP_VER" ] || curl -Lk https://secure.php.net/distributions/php-"${PHP_VER}".tar.gz | gunzip | tar x + cd "php-$PHP_VER/ext/opcache" || exit + + phpize + ./configure --with-php-config=/usr/local/php/bin/php-config + make && make install + + EXTENSION_DIR=$(php-config --extension-dir) + if [ -f "$EXTENSION_DIR/opcache.so" ]; then + tee /usr/local/php/etc/php.d/08-opcache.ini <<-'EOF' +[Zend Opcache] +zend_extension=opcache.so +opcache.enable = 1 +opcache.memory_consumption=128 +opcache.interned_strings_buffer=8 +opcache.max_accelerated_files=4000 +opcache.revalidate_freq=60 +opcache.enable_cli=1 +EOF + fi +} + +[ -d "/tmp/extension" ] || mkdir /tmp/extension + +pushd /tmp/extension || exit +UNINSTALLED=$(php --rz "Zend OPcache" | grep 'does not exist') +[ -z "$UNINSTALLED" ] || install_opcache +popd || exit diff --git a/extensions/pq.sh b/extensions/pq.sh new file mode 100644 index 00000000..214bd131 --- /dev/null +++ b/extensions/pq.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +install_pecl_raphf() { + curl -Lk https://pecl.php.net/get/raphf-2.0.1.tgz | gunzip | tar x + cd raphf-2.0.1 || exit + + phpize + ./configure --with-php-config=/usr/local/php/bin/php-config + make && make install + + EXTENSION_DIR=$(php-config --extension-dir) + if [ -f "$EXTENSION_DIR/raphf.so" ]; then + echo 'extension=raphf.so' >/usr/local/php/etc/php.d/05-raphf.ini + fi + + cd .. +} + +install_pecl_pq() { + curl -Lk https://pecl.php.net/get/pq-2.2.0.tgz | gunzip | tar x + cd pq-2.2.0 || exit + + phpize + ./configure --with-php-config=/usr/local/php/bin/php-config + make && make install + + EXTENSION_DIR=$(php-config --extension-dir) + if [ -f "$EXTENSION_DIR/pq.so" ]; then + echo 'extension=pq.so' >/usr/local/php/etc/php.d/02-pq.ini + fi + + cd .. +} + +[ -d "/tmp/extension" ] || mkdir /tmp/extension + +pushd /tmp/extension || exit +UNINSTALLED=$(php --ri raphf | grep 'not present') +[ -z "$UNINSTALLED" ] || install_pecl_raphf + +INSTALLED_raphf=$(php --ri raphf | grep 'not present') +INSTALLED_pq=$(php --ri pq | grep 'not present') +if [ -n "$INSTALLED_pq" ] && [ -z "$INSTALLED_raphf" ]; then + install_pecl_pq +fi +popd || exit diff --git a/extensions/redis.sh b/extensions/redis.sh new file mode 100644 index 00000000..fbf12156 --- /dev/null +++ b/extensions/redis.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +install_redis() { + curl -Lk https://pecl.php.net/get/redis-5.3.5.tgz | gunzip | tar x + cd redis-5.3.5 || exit + + phpize + ./configure --with-php-config=/usr/local/php/bin/php-config + make && make install + + EXTENSION_DIR=$(php-config --extension-dir) + if [ -f "$EXTENSION_DIR/redis.so" ]; then + echo 'extension=redis.so' >/usr/local/php/etc/php.d/05-redis.ini + fi +} + +[ -d "/tmp/extension" ] || mkdir /tmp/extension + +pushd /tmp/extension || exit +UNINSTALLED=$(php --ri redis | grep 'not present') +[ -z "$UNINSTALLED" ] || install_redis +popd || exit diff --git a/extensions/sqlsrv.sh b/extensions/sqlsrv.sh new file mode 100644 index 00000000..3794fab4 --- /dev/null +++ b/extensions/sqlsrv.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +install_pdo_sqlsrv() { + apt install -y unixodbc-dev + + curl -Lk http://pecl.php.net/get/pdo_sqlsrv-5.11.0.tgz | gunzip | tar x + cd pdo_sqlsrv-5.11.0 || exit + + phpize + ./configure --with-php-config=/usr/local/php/bin/php-config + make && make install + + EXTENSION_DIR=$(php-config --extension-dir) + if [ -f "$EXTENSION_DIR/pdo_sqlsrv.so" ]; then + echo 'extension=pdo_sqlsrv.so' >/usr/local/php/etc/php.d/02-sqlsrv.ini + fi +} + +[ -d "/tmp/extension" ] || mkdir /tmp/extension + +pushd /tmp/extension || exit +UNINSTALLED=$(php --ri pdo_sqlsrv | grep 'not present') +[ -z "$UNINSTALLED" ] || install_pdo_sqlsrv +popd || exit diff --git a/extensions/swoole.sh b/extensions/swoole.sh new file mode 100755 index 00000000..d3b9fbc3 --- /dev/null +++ b/extensions/swoole.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +install_swoole() { + curl -Lk https://ghproxy.com/https://github.com/swoole/swoole-src/archive/v4.8.13.tar.gz | gunzip | tar x + cd swoole-src-4.8.13 || exit + + phpize + ./configure --with-php-config=/usr/local/php/bin/php-config + make && make install + + EXTENSION_DIR=$(php-config --extension-dir) + if [ -f "$EXTENSION_DIR/swoole.so" ]; then + echo 'extension=swoole.so' >/usr/local/php/etc/php.d/03-swoole.ini + fi +} + +[ -d "/tmp/extension" ] || mkdir /tmp/extension + +pushd /tmp/extension || exit +UNINSTALLED=$(php --ri swoole | grep 'not present') +[ -z "$UNINSTALLED" ] || install_swoole +popd || exit diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..d0c6f231 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,39 @@ +user www www; #modify +worker_processes auto; #modify + +#error_log logs/error.log; +#error_log logs/error.log notice; +#error_log logs/error.log info; + +#pid logs/nginx.pid; +pid /var/run/nginx.pid; #modify +worker_rlimit_nofile 51200; + +events { + use epoll; + worker_connections 51200; + multi_accept on; +} + +http { + include mime.types; + default_type application/octet-stream; + + #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + # '$status $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #access_log logs/access.log main; + + client_max_body_size 100m; #add + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 120; #65; + + #gzip on; + + ##########################vhost##################################### + include vhost/*.conf; +} diff --git a/supervisord/nginx.conf b/supervisord/nginx.conf new file mode 100644 index 00000000..988d9f12 --- /dev/null +++ b/supervisord/nginx.conf @@ -0,0 +1,9 @@ +[program:nginx] +command=/usr/local/nginx/sbin/nginx -g 'daemon off;' -c /usr/local/nginx/conf/nginx.conf +autostart=true +autorestart=true +priority=5 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 diff --git a/supervisord/php-fpm.conf b/supervisord/php-fpm.conf new file mode 100644 index 00000000..3b4fba3e --- /dev/null +++ b/supervisord/php-fpm.conf @@ -0,0 +1,9 @@ +[program:php-fpm] +command=/usr/local/php/sbin/php-fpm -F --fpm-config /usr/local/php/etc/php-fpm.conf +autostart=true +autorestart=true +priority=5 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 \ No newline at end of file diff --git a/vhost/localhost.conf b/vhost/localhost.conf new file mode 100644 index 00000000..475bad77 --- /dev/null +++ b/vhost/localhost.conf @@ -0,0 +1,54 @@ +server { + listen 80; + server_name localhost; + root /data/wwwroot; + 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; + # } + + location / { + if (!-e $request_filename) { + rewrite ^(.*)$ /index.php?s=$1 last; + break; + } + } + + 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 ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { + expires 30d; + access_log off; + } + + location ~ .*\.(js|css)?$ { + expires 7d; + access_log off; + } + + location ~ /\.(ht|git|vscode|idea) { + deny all; + } + + # https + # listen 443 ssl http2; + # ssl_certificate ssl/localhost.crt; + # ssl_certificate_key ssl/localhost.key; + # ssl_protocols TLSv1 TLSv1.1 TLSv1.2; + # ssl_prefer_server_ciphers on; + # ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; + # keepalive_timeout 70; + # ssl_session_cache shared:SSL:10m; + # ssl_session_timeout 10m; +} \ No newline at end of file diff --git a/www/helloworld.php b/www/helloworld.php new file mode 100644 index 00000000..aaa10d6a --- /dev/null +++ b/www/helloworld.php @@ -0,0 +1 @@ +