您好,登錄后才能下訂單哦!
本篇文章為大家展示了怎么在Docker中搭建一個php開發環境,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
docker 安裝
使用官方提供的安裝腳本,安裝最新版的Docker
curl -sSL https://get.docker.com/ | sh
安裝完成后,通過如下命令啟動Docker的守護進程,并讓它隨系統啟動自動加載
sudo service docker start
sudo chkconfig docker on
## 或者
sudo systemctl start docker
sudo systemctl enable docker
添加用戶(jerry)到Docker組
sudo usermod -aG docker jerry
命令筆記(centos),基于docker鏡像2233466866/lnmp
下載鏡像
docker pull 2233466866/lnmp
創建基本目錄
mkdir -p /app/lnmp/default /docker/lnmp/data/mysql /docker/lnmp/conf/vhost /docker/lnmp/logs /docker/lnmp/temp /docker/lnmp/backup
下載容器配置文件到本地相應目錄
docker run -itd -v /sys/fs/cgroup:/sys/fs/cgroup:ro --privileged=true --name=lnmp 2233466866/lnmp
docker exec -it lnmp /bin/bash
docker cp lnmp:/etc/my.cnf /docker/lnmp/conf/my.cnf
docker cp lnmp:/usr/local/nginx/conf/nginx.conf /docker/lnmp/conf/nginx.conf
cp /docker/lnmp/conf/my.cnf /docker/lnmp/backup/my.cnf
cp /docker/lnmp/conf/nginx.conf /docker/lnmp/backup/nginx.conf
查看或修改基本配置(代碼目錄,日志保存目錄及vhost目錄配置添加)
my.cnf
[mysqld]
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
nginx.conf
user www; worker_processes auto; worker_cpu_affinity auto; worker_cpu_affinity auto; pid logs/nginx.pid; events { worker_connections 102400; } http { charset utf-8; server_tokens off; log_format main '$remote_addr - $remote_user [$time_iso8601] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; include mime.types; default_type application/octet-stream; client_max_body_size 20M; sendfile on; keepalive_timeout 20; gzip on; gzip_vary on; gzip_comp_level 1; gzip_types text/css application/javascript application/json image/png image/webp image/apng image/jpeg image/x-icon; autoindex_localtime on error_log /logs/z_error.log; access_log /logs/z_$host.log main; server { listen 80 default; root /www/default; return 500; } include vhost/*.conf; }
停止并刪除測試容器
docker stop lnmp
docker rm lnmp
重新創建容器
docker run -dit \
-p 80:80 \
-p 443:443 \
-p 3306:3306 \
-p 9000:9000 \
-e TC="Asia/Shanghai" \
-v /sys/fs/cgroup:/sys/fs/cgroup:ro \
-v /app/lnmp:/www \
-v /docker/lnmp/data/mysql:/data/mysql \
-v /docker/lnmp/conf/my.cnf:/etc/my.cnf \
-v /docker/lnmp/conf/nginx.conf:/usr/local/nginx/conf/nginx.conf \
-v /docker/lnmp/conf/vhost:/usr/local/nginx/conf/vhost \
-v /docker/lnmp/logs:/logs \
--privileged=true \
--name=lnmp \
2233466866/lnmp
mysql 數據庫配置(/etc/my.cnf)
/bin/mysql_secure_installation
cat /var/log/mysqld.log|grep 'A temporary password'
SET PASSWORD = PASSWORD('123456');
php.ini 配置(/usr/local/php7/lib/php.ini)
mysqli.default_socket = /var/lib/mysql/mysql.sock
linux 相關設置修改
添加不能登陸的用戶www
groupadd www
useradd -M -g www -s /usr/sbin/nologin www
修改時區(/etc/profile)
TZ='Asia/Shanghai'; export TZ
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
多站點配置
www.test.test.conf
server { listen 80; server_name test.test; rewrite ^(.*)$ $scheme://www.test.test$1 permanent; } server { listen 80; server_name www.test.test; if ($time_iso8601 ~ "^(\d{4}-\d{2}-\d{2})") { set $ttt $1; } access_log /logs/$host-$ttt-access.log main; root /www/test; location / { index index.php index.html index.htm; } location ~* \.php { include fastcgi_params; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
上述內容就是怎么在Docker中搭建一個php開發環境,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。