安装php
- 下载
php7.3.5
镜像
sudo docker pull php:7.3.5-fpm
- 创建映射目录
sudo mkdir -p /http/htdocs
- 生成容器
sudo docker run --name php-fpm -v /http/htdocs:/www -d php:7.3.5-fpm
容器名称为 php-fpm,目录 htdocs挂载到容器的 /www
php已配置完成
安装nginx
- 下载
nginx1.16.0
镜像
sudo docker pull nginx:1.16.0
- 创建映射目录
sudo mkdir -p /http/nginx/logs /http/nginx/conf /http/nginx/conf.d
- 设置
/http/nginx/conf/nginx.conf
使用sudo touch /http/nginx/conf/nginx.conf
创建文件,编辑文件内容如下
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
- 设置
/http/nginx/conf.d/www.conf
使用sudo touch /http/nginx/conf.d/www.conf
创建文件,编辑文件内容如下
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;
include fastcgi_params;
}
}
生成容器并链接php
sudo docker run --name nginx -p 80:80 -d -v /http/htdocs:/usr/share/nginx/html -v /http/nginx/conf:/etc/nginx/conf -v /http/nginx/conf.d:/etc/nginx/conf.d -v /http/nginx/logs:/var/log/nginx --link php-fpm:php nginx:1.16.0
测试php是否可以运行
使用sudo touch /http/htdocs/index.php
创建文件,编辑文件内容如下
<?php
phpinfo();
运行出现php环境信息