mac 环境docker运行crmeb pro2.0
1 为什么mac上要用docker运行?
直接运行项目不是更方便高效吗?
是的,但crmeb pro 2.0使用swoole和swoole 加密技术,需要swoole+swoole loader配合使用才行,但目前crmeb pro 2.0官方还未支持mac版本的swoole loader;只能选择docker运行
2 docker 运行环境 搭建注意
使用dnmp作为基础:
https://github.com/yeszao/dnmp
提前说明注意事项:
1 swoole不能为框架内的4.5.2,升级为4.6.7,可以正常运行
https://github.com/swoole/swoole-src/releases/tag/v4.6.7 下载 Source code (tar.gz) 压缩包 下载完成重名为 swoole-4.6.7.tgz
放到 dnmp/services/php/extensions 目录下
dnmp/services/php/extensions/install.sh 607行 修改为
installExtensionFromTgz swoole-4.6.7
https://github.com/yeszao/dnmp/issues/376#issuecomment-865412930
2 swoole loader需要手动添加到php.ini
extension=/www/help/swoole_loader/swoole_loader73.so
3 docker-compose中添加启动命令:
extra_hosts:
- "www.site1.com:172.17.0.1" command:
- /bin/sh
- -c
- |
cd /www/
rm -f runtime/swoole.pid
php think swoole
php think queue:listen --tries=2 volumes:
- ${SOURCE_DIR}:/www/:rw
4 项目文件public/.user.ini删除跨域限制代码
5 php使用7.3,为了和线上保持一致
.env
PHP_VERSION=7.3.29 PHP_PHP_CONF_FILE=./services/php/php.ini
PHP_FPM_CONF_FILE=./services/php/php-fpm.conf
PHP_LOG_DIR=./logs/php
PHP_EXTENSIONS=pdo_mysql,mysqli,mbstring,gd,curl,swoole,redis,bcmath,sdebug,zip
3 完整代码
修改的划线
.env
# PHP source directory
#
SOURCE_DIR=../server
........
PHP_VERSION=7.3.29 PHP_PHP_CONF_FILE=./services/php/php.ini
PHP_FPM_CONF_FILE=./services/php/php-fpm.conf
PHP_LOG_DIR=./logs/php
PHP_EXTENSIONS=pdo_mysql,mysqli,mbstring,gd,curl,swoole,redis,bcmath,sdebug,zip
........
docker-compose.yml
version: "3" services:
nginx:
build:
context: ./services/nginx
args:
NGINX_VERSION: nginx:${NGINX_VERSION}
CONTAINER_PACKAGE_URL: ${CONTAINER_PACKAGE_URL}
NGINX_INSTALL_APPS: ${NGINX_INSTALL_APPS}
container_name: nginx
ports:
- "${NGINX_HTTP_HOST_PORT}:80" - "${NGINX_HTTPS_HOST_PORT}:443" volumes:
- ${SOURCE_DIR}:/www/:rw
- ${NGINX_SSL_CERTIFICATE_DIR}:/ssl:rw
- ${NGINX_CONFD_DIR}:/etc/nginx/conf.d/:rw
- ${NGINX_CONF_FILE}:/etc/nginx/nginx.conf:ro
- ${NGINX_FASTCGI_PHP_CONF}:/etc/nginx/fastcgi-php.conf:ro
- ${NGINX_FASTCGI_PARAMS}:/etc/nginx/fastcgi_params:ro
- ${NGINX_LOG_DIR}:/var/log/nginx/:rw
environment:
TZ: "$TZ" restart: always
networks:
- default php:
build:
context: ./services/php
args:
PHP_VERSION: php:${PHP_VERSION}-fpm-alpine
CONTAINER_PACKAGE_URL: ${CONTAINER_PACKAGE_URL}
PHP_EXTENSIONS: ${PHP_EXTENSIONS}
TZ: "$TZ" container_name: php
expose:
- 9501 extra_hosts:
- "www.site1.com:172.17.0.1" command:
- /bin/sh
- -c
- |
cd /www/
rm -f runtime/swoole.pid
php think swoole
php think queue:listen --tries=2 volumes:
- ${SOURCE_DIR}:/www/:rw
- ${PHP_PHP_CONF_FILE}:/usr/local/etc/php/php.ini:ro
- ${PHP_FPM_CONF_FILE}:/usr/local/etc/php-fpm.d/www.conf:rw
- ${PHP_LOG_DIR}:/var/log/php
- ${DATA_DIR}/composer:/tmp/composer
restart: always
cap_add:
- SYS_PTRACE
networks:
- default ........
services/php/php.ini
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
extension=/www/help/swoole_loader/swoole_loader73.so
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
servicesphp/extension/install.sh
if [[ -z "${EXTENSIONS##*,swoole,*}" ]]; then
echo "---------- Install swoole ----------" isPhpVersionGreaterOrEqual 7 0 if [[ "$?" = "1" ]]; then
installExtensionFromTgz swoole-4.6.7 else installExtensionFromTgz swoole-2.0.11 fi
fi
services/nginx/conf.d/localhost.conf
server {
listen 80 default;
server_name localhost;
root /www/public;
index index.php index.html index.htm;
#charset koi8-r;
access_log /dev/null;
#access_log /var/log/nginx/nginx.localhost.access.log main;
error_log /var/log/nginx/nginx.localhost.error.log warn;
#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 /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 #
#location ~ \.php$ {
# proxy_pass http://127.0.0.1; #}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 #
location ~ [^/]\.php(/|$) {
fastcgi_pass php:9000;
include fastcgi-php.conf;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
#PROXY-START/ location ~* \.(php|jsp|cgi|asp|aspx)$
{
proxy_pass http://php:20199; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
}
location /
{
if (!-e $request_filename) {
proxy_pass http://php:20199; }
proxy_http_version 1.1;
proxy_read_timeout 360s;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
add_header Cache-Control no-cache;
expires 12h;
}
#PROXY-END/
}
本地运行:(mysql/redis使用线上环境)
cd docker
docker-compose up
留言