docker 安装PHP+nginx
下载镜像:
docker pull nginx docker pull php:7.4-fpm
启动nginx镜像:
docker run --network host --name mynginx \ -v /mnt/hgfs/www:/www \ -v /mnt/hgfs/www/vm_nginx/conf.d:/etc/nginx/conf.d \ --privileged=true \ -d nginx
参考:docker四种网络模式,容器localhost访问宿主机端口 https://blog.csdn.net/ma726518972/article/details/108146218
编辑default.conf:
server { listen 7002; server_name 127.0.0.1; location / { root /www/hlyun_v3/hlyun_gateway/src/public; index index.html index.htm index.php; try_files $uri $uri/ /index.php?$query_string; } error_page 500 502 503 504 /50x.html; location ~ \.php$ { root /www/hlyun_v3/hlyun_gateway/src/public; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } }
启动PHP镜像
docker run --network host --name myphp \ -v /mnt/hgfs/www:/www \ --privileged=true \ -d php:7.4-fpm
安装PHP扩展
docker exec -it myphp /bin/bash docker-php-ext-install pdo pdo_mysql
修改PHP-FPM
cp /usr/local/etc/php-fpm.d/www.conf /www