安裝php
- 下載
php7.3.5
鏡像
sudo docker pull php:7.3.5-fpm
- 創(chuàng)建映射目錄
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
- 創(chuàng)建映射目錄
sudo mkdir -p /http/nginx/logs /http/nginx/conf /http/nginx/conf.d
- 設(shè)置
/http/nginx/conf/nginx.conf
使用sudo touch /http/nginx/conf/nginx.conf
創(chuàng)建文件,編輯文件內(nèi)容如下
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;
}
- 設(shè)置
/http/nginx/conf.d/www.conf
使用sudo touch /http/nginx/conf.d/www.conf
創(chuàng)建文件醇滥,編輯文件內(nèi)容如下
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是否可以運(yùn)行
使用sudo touch /http/htdocs/index.php
創(chuàng)建文件挂洛,編輯文件內(nèi)容如下
<?php
phpinfo();
運(yùn)行出現(xiàn)php環(huán)境信息