Docker CentOS7 LNMP环境yum方式安装
2016-06-14 23:13
1501 查看
在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
相关文章推荐
- Android之获取手机上的图片和视频缩略图thumbnails
- nginx代理指定目录
- Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL
- 访问Nginx发生SSL connection error的一种情况
- Centos6 编译安装Python
- 数据库链接字符串查询网站
- Nginx+Naxsi部署专业级Web应用防火墙
- 硬盘安装CentOS 6.2以及添加GRUB启动菜单
- CentOS 6.2实战部署Nginx+MySQL+PHP
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- LNMP源码安装(RHEL)