docker run -t -i -p 5566:80 xxx/centos7:latest bash
安裝Nginx
新增CentOS 7 的Ngnix yum repository ,因為Ngnix 不直接由CentOS提供$ sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
ps. 如果是CentOS 6 則安裝 epel repository ( CentOS )
$ sudo yum install epel-release
安裝ngnix
$ sudo yum install nginx
啟動php-fpm
# php-fpm
啟動ngnix
因為CentOS 7已不使用service啟動服務,而使用systemctl start <service> , 且使用systemctl 啟動服務時會報錯
# systemctl restart nginx
Failed to get D-Bus connection: No connection to service manager.
原因:
https://github.com/docker/docker/issues/7459#issuecomment-52327775
大意是說:
在container內必須使用程式本身的管理工具去啟動。systemctl不會作用。
ex.
啟動nginx
# nginx
停止nginx
# nginx -s stop
啟動mysql(MariaDB)
切換成mysql使用者
# su mysql
This account is currently not available.
解決mysql使用者不能使用
# vim /etc/passwd
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/bin/bash
重新登陸
# su mysql
啟動mysql
$ cd /usr/libexec/
$ ./mysqld
報錯:
...
151023 10:27:11 [ERROR] mysqld: File '/var/lib/mysql/aria_log_control' not found (Errcode: 13)
原來是aria_log_control這隻檔案有問題
# ls /var/lib/mysql/aria_log_control -l
-rw-rw---- 1 root root 52 Jul 8 10:33 /var/lib/mysql/aria_log_control
把它刪掉
# rm /var/lib/mysql/aria_log_control
再度重啟mysql
$ ./mysqld
報錯:
...
151023 10:36:27 [ERROR] mysqld: Can't create/write to file '/var/lib/mysql/aria_log.00000001' (Errcode: 13)
一樣是權限問題
# ls /var/lib/mysql/aria_log.00000001 -l
-rw-rw---- 1 root root 16384 Jul 8 10:33 aria_log.00000001
更變權限
# cd /var/lib/
# chown mysql:mysql -R mysql/
啟動mysql(成功)
$ ./mysqld
停止mysql
# mysqladmin shutdown
MySQL停止的方法
http://stackoverflow.com/questions/11091414/how-to-stop-mysqld
$ /usr/local/mysql/bin/mysqladmin -u root -p shutdown
或
$ sudo mysqld stop
或
$ sudo /usr/local/mysql/bin/mysqld stop
或
$ sudo mysql.server stop
php頁面打不開(連結變成下載php檔案) [ 與 nginx vhost配置 類似問題 ]
在 /etc/nginx/conf.d/default.conf 中server{}區塊解除註解這一段,並修改
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#root html;
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
如果上面那段root和fastcgi_param 維持原值任一一個沒改,頁面會出現File not found,nginx error log會報下面錯誤
2015/11/16 09:08:00 [error] 941#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.x.x, server: localhost, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.x.x:5566"
請勿解除註解下面這一段
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
不然會報錯
2015/11/16 08:22:55 [alert] 837#0: 1024 worker_connections are not enough
2015/11/16 08:22:55 [error] 837#0: *1022 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /info.php HTTP/1.0", upstream: "http://127.0.0.1:80/info.php", host: "127.0.0.1"
最後瀏覽器打開
http://192.168.x.x:5566/
就能訪問你docker上的php程式了
參考資料:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7 # How To Install Linux, Nginx, MySQL, PHP (LEMP) stack On CentOS 7
https://bbs.archlinux.org/viewtopic.php?id=160277 [SOLVED] Cannot start mysqld after switching to MariaDB
https://mariadb.com/kb/en/mariadb/problem-while-starting-mariadb-server/ problem while starting mariadb server?
http://www.ahlinux.com/nginx/4936.html nginx fastcgi错误primary script unknown如何解决
http://serverfault.com/questions/406158/nginx-php5-fpm-file-not-found Nginx + php5-fpm = “File not found”