在Docker Centos7 安装LNMP环境
运行一个全新centos的镜像,并映射需要的端口。我这里nginx用8081端口,数据库用3308。
docker run -d --name d2o-ss2 -p 8081:8081 -p 3308:3306 -ti \
-h D2O-SS2 --privileged -e "container=docker" \
-v /sys/fs/cgroup:/sys/fs/cgroup centos /usr/sbin/init
进入容器
docker exec -it d2o-ss2 bash
修改时区,安装基本工具,关闭firewalld。
timedatectl set-timezone Asia/Hong_Kong
yum install -y bind-utils net-tools htop mlocate initscripts.x86_64
updatedb
systemctl stop firewalld
systemctl mask firewalld
添加Nginx
源
访问nginx
官网获取最新yum源,地址为:http://nginx.org/en/linux_packages.html
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
添加PHP5.6/PHP7
源
rpm -ivh https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-6.noarch.rpm
rpm -ivh https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-14.ius.centos7.noarch.rpm
加载MariaDB
源
官方没提供rpm来直接导入,需要手动创建repo文件。
vi /etc/yum.repos.d/MariaDB.repo
插入repo文件内容
# MariaDB 10.1 CentOS repository list - created 2015-11-12 02:20 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
执行yum install
开始安装PHP7
yum install MariaDB-server MariaDB-client nginx php70u-fpm php70u-gd php70u-json php70u-intl php70u-mbstring php70u-mcrypt php70u-mysqlnd php70u-opcache php70u-pdo php70u-pdo-dblib php70u-process php70u-pgsql php70u-recode php70u-xml php70u-xmlrpc php70u-cli
启动软件,并设置为开机启动
systemctl start nginx
systemctl start php-fpm
systemctl start mariadb
systemctl enable nginx
systemctl enable php-fpm
systemctl enable mariadb
设置默认MySQL/MariaDB
密码
mysqladmin -u root password ‘new-password’
请将 new-password
替换为你的数据库密码
至此LNMP
的yum
安装就完成了,访问 http://ip/ 应该可以看到nginx的起始页。接下来需要配置一下php-fpm
以便PHP
正常工作。为了方便nginx
和php-fpm
全部使用nginx
权限来启动。
修改php-fpm
配置
vi /etc/php-fpm.d/www.conf
找到user
和group
,修改为nginx
user = nginx
group = nginx
修改nginx
配置
vi /etc/nginx/nginx.conf
找到user
改为nginx
,worker_processes
增大,支持多线程。
user nginx;
worker_processes 4;
重启php-fpm
和nginx
使之生效
systemctl restart php-fpm
systemctl restart nginx
最后示例配置,这个是开启了伪静态(URL重写)的/etc/nginx/conf.d/default.conf
server {
listen 8082;
server_name xxx.net;
root /var/www/Public;
if (!-e $request_filename) {
rewrite (.*) /index.php last;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ .*\.php$ {
root /var/www/Public;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
退出到宿主机,封装成镜像。
docker commit d2o-ss2 d2okkk.net/d2o-ss2
感谢各位dalao 们
参考
http://www.cyberciti.biz/faq/centos-linux-6-7-changing-timezone-command-line/
https://sendya.me/archives/centos7-nginx-php-mariadb-mysql-install.html
http://blog.csdn.net/conupefox/article/details/49369035