Giter Club home page Giter Club logo

alphp's Introduction

Alpine PHP Docker

Docker Build Status Docker Pulls MicroBadger Layers (tag) MicroBadger Size (tag)

alphp - 基于alpine的微型php docker环境,php 是 7.x, 包含最新版本swoole。 构建完成的镜像只有30-40M,可以直接用于生产环境作镜像发布。

共有几个镜像

  • swoft/alphp:base 基础镜像,后几个镜像基于它(含有php和一些通用的扩展)
  • swoft/alphp:cli php cli环境镜像,含有最新版本 swoole 和 mongodb 扩展
  • swoft/alphp:fpm 基于 swoft/alphp:cli,含有 nginx php-fpm 组件
  • swoft/alphp:dev 基于 swoft/alphp:cli,含有 nginx php-fpm 以及一些常用工具:vim wget git zip telnet ab 等,可用于开发。

共有几个分支

  • master: 基于 alpine:3.8 镜像, php7.2
  • alpine-edge: 基于 alpine:edge 镜像, php7.2
  • alpine-3.7: 基于 alpine:3.7 镜像, php7.1

Dockerfile links

base on alpine 3.8(php 7.2.x):


直接拉取

docker pull swoft/alphp:base
docker pull swoft/alphp:cli
docker pull swoft/alphp:fpm
docker pull swoft/alphp:dev

hub.docker 地址: https://hub.docker.com/r/swoft/alphp/

本地构建

构建基础镜像

docker build . -f alphp-base.Dockerfile -t swoft/alphp:base

构建功能镜像

  • 构建 swoft/alphp:cli
docker build . -f alphp-cli.Dockerfile -t swoft/alphp:cli
  • 构建 swoft/alphp:fpm
// 在swoft/alphp:cli 的基础上,含有 nginx php-fpm
docker build . -f alphp-fpm.Dockerfile -t swoft/alphp:fpm
  • 构建 swoft/alphp:dev
// 在 swoft/alphp:cli 的基础上,含有 nginx php-fpm 额外包含一些常用工具:vim wget git zip telnet ab 等
docker build . -f alphp-dev.Dockerfile -t swoft/alphp:dev

一些有用的

更改软件源

sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/' /etc/apk/repositories

Dockerfile注意

  • 如果想要主进程接收 docker stop 信号(SIGTERM),一定要用 ENTRYPOINT 或者 RUN 来启动运行主进程,不能使用 CMD。

CMD 会始终使用 sh -c command 来执行命令,这样PID = 1 的就不是真实命令所在进程了

ENTRYPOINT ["php", "/var/www/bin/cli", "taskServer:restart"]

镜像中的一些信息

  • php execute file: /usr/bin/php
  • php ini file: /etc/php7/php.ini
  • 扩展配置目录:/etc/php7/conf.d
  • 扩展编译目录:/usr/lib/php7/modules
  • php-fpm execute file: /usr/bin/php-fpm
  • php-fpm conf: /etc/php7/php-fpm.conf

重新生成 composer autoload

composer up nothing

工具推荐

工具列表

  • composer 包管理
  • phpunit 单元测试
  • phpmd 代码检查
  • 类参考文档生成
  • deployer 一个用PHP编写的部署工具支持流行的框架
  • xhprof 安装

add composer

ADD tools/composer.phar /usr/local/bin/composer
RUN chmod 755 /usr/local/bin/composer

类参考文档生成

  • 使用 sami(推荐)
$ ./vendor/bin/sami.phar -V

生成:

$ php ./vendor/bin/sami.phar update build/sami.conf.php

分开执行:

// The parse command parses a project and generates a database
$ php ./vendor/bin/sami.phar parse config/symfony.php

// The render command renders a project as a static set of HTML files
$ php ./vendor/bin/sami.phar render config/symfony.php
  • 使用 apigen
$ ./vendor/bin/apigen.phar -V
$ ./vendor/bin/apigen.phar generate --help
$ ./vendor/bin/apigen.phar generate -s {source code dir} -d {doc generate dir}
  • 使用phpDocumentor
$ ./vendor/bin/phpDocumentor.phar -V
phpDocumentor version v2.9.0
$ ./vendor/bin/phpDocumentor.phar run -d {source code dir} -t {doc generate dir}

手动管理 php-fpm

#关闭php-fpm
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`

#重启php-fpm
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

端口检查 lsof

lsof :9051

ab 压力测试

安装

// ubuntu
apt-get install apache2-utils
// centos
yum install httpd-tools

安装 swoole

官网 swoole.com 安装相关扩展 redis, zip, mbstring, inotify, pdo_mysql

相关库

编译命令

# phpize
# ./configure --enable-swoole-debug --enable-async-redis --enable-openssl --enable-sockets --enable-coroutine --with-php-config=/usr/local/bin/php-config
# make clean
# make -j
# make install

更多选项说明

使用 ./configure -h 可以看到全部的选项

  • --enable-swoole-debug // 打开调试日志,开启此选项后swoole将打印各类细节的调试日志。生产环境不要启用。
  • --enable-sockets // 增加对sockets资源的支持,依赖sockets扩展
  • --enable-async-redis // 增加异步Redis客户端支持, 依赖hiredis库
  • --enable-openssl // 启用SSL支持,依赖openssl库
  • --enable-http2 // 增加对HTTP2的支持,依赖nghttp2库. 必须开启openssl
  • --enable-coroutine // 启用协程能力(swoole 4 已去除此选项)

相关库

License

MIT

alphp's People

Contributors

daydaygo avatar inhere avatar lu8533783 avatar nelsonsun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alphp's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.