使用Docker搭建CentOS 7 + Apache 2.4+ PHP7

从Docker Hub上Pull最新的CentOS 7镜像并新建容器

# sudo docker pull centos
docker run -p 8082:80 --name centos_c -itd centos:latest

 进入container  (镜像):

# docker exec -it centos_c  bash

 

修改镜像,安装所需软件

  • 安装ifconfig命令(原先没有)

ifconfig命令是在net-tools软件包中,安装net-tools即可,net-tools包括ifconfig,netstat等命令

# yum install net-tools

 

  • 安装wget命令(原先没有)
yum install wget

 

  • 更新yum源,使用阿里云的yum源(也可以选其他的),先备份原来的,再下载新的
# cd /etc/yum.repos.d/
# mv CentOS-Base.repo CentOS-Base.repo_backup
# wget http://mirrors.aliyun.com/repo/Centos-7.repo
# mv Centos-7.repo CentOS-Base.repo
# yum makecache

 

安装使用Apache作为应用代理服务器

  • 安装Apache
# yum install httpd

 

  • 设置Apache服务开机自启动(可选,不过设置自启动方便)
# /sbin/chkconfig httpd on
  • 启动Apache服务

在CentOS 7中无法直接使用/sbin/service这样的方式来启动服务,会报Failed to get D-Bus connection: No connection to service manager - CentOS 7错误
但是可以把httpd文件拷贝到/etc/init.d/目录下,直接使用/etc/init.d/httpd -k start来启动Apache服务,不拷贝到此目录下也可以,原理一样的,找到可执行文件即可

# cp /usr/sbin/httpd /etc/init.d/
# /etc/init.d/httpd -k start

执行上述命令时会报警告
httpd: Could not reliably determine the server's fully qualified domain name

消除这个警告需要更改Apache的设置文件httpd.conf,取消注释ServerName即可,并把www.example.com换成自己的IP地址或是localhost

同时: 按照这篇文档http://drupal.org/node/15365说明,把apache conf里面的AllowOverride None改为AllowOverride All.

# vi /etc/httpd/conf/httpd.cof

执行yum install httpd-devel,进行安装,如果不安装的话,后期不会生成.so的扩展文件(如:modules/libphp7.so)

yum install httpd-devel

 

执行yum list |grep php7 , 查看是否有php7的源,如果没有则需要进行更新yum源:

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm   ##CentOs 7.X

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

如果想删除上面安装的包,重新安装

rpm -qa | grep webstatic

rpm -e  上面搜索到的包即可

安装PHP:

yum install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-mcrypt.x86_64 php72w-mysql.x86_64 php72w-pdo.x86_64  

 

yum install php72w-xml.x86_64  php72w-opcache.x86_64  

 

 保持/var/www/目录的用户与apache 的一致:

root# chown apache:apache -R /var/www/html 

 

posted on 2018-03-06 00:17  clearriver  阅读(813)  评论(0编辑  收藏  举报

导航