docker 使用镜像centos6 配置PHP+Apache+grpc开发环境

1、docker安装

a、Ubuntu docker安装:

        安装:wget -qO- https://get.docker.com/ | sh

        启动:service docker start

b、centos7 docker安装:

        确保centos内核版本3以上,不然后续可能会出现很多问题,命令 uname -r 查看内核版本

        安装必要工具:yum install -y yum-utils device-mapper-persistent-data lvm2

        添加源:yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

        更新源:yum makecache fast

        安装:yum -y install docker-ce

        启动docker:sudo systemctl start docker

2、下载镜像:docker pull centos:6

3、运行镜像:docker run -i -t -p 1000:80 镜像id /bin/bash (本机1000端口映射到容器80端口)

4、添加yum 源: rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

5、安装Apache: yum -y install httpd

        启动Apache: service httpd start

        apache 设置开机自启动:

                chkconfig --add httpd

                chkconfig --level 2345 httpd on

6、安装php:

        yum -y install mod_php71w php71w-bcmath php71w-cli php71w-common php71w-devel php71w-fpm php71w-gd php71w-mbstring php71w-mysql php71w-snmp  php71w-xml php71w-process php71w-ldap net-snmp net-snmp-devel net-snmp-utils rrdtool

7、验证是否安装成功

/var/www/html/  目录新增 phpinfo.php ,内容  

浏览器验证:http://ip:1000/phpinfo.php (ip替换为真实服务器外网IP)

8、安装系统必要工具: gcc,gcc-c++,wget

yum install gcc gcc-c++ wget

9、安装monodb扩展(其他扩展类似的安装方法)

下载源码包:wget http://pecl.php.net/get/mongodb-1.5.3.tgz

解压:tar zxvf mongodb-1.5.3.tgz

目录切换到 cd mongodb-1.5.3

/usr/bin/phpize

./configure --with-php-config=/usr/bin/php-config

make

make install

10、找到php.ini文件 添加一行:extension=mongodb.so

11、安装grpc 与mongodb类似,扩展下载地址:http://pecl.php.net/get/grpc-1.20.0.tgz

         编译如果出错,请先升级gcc,升级方法:https://blog.csdn.net/dijkstar/article/details/82218170
         extension=grpc.so

12、安装新版本git: https://www.jianshu.com/p/232d76341fbf

每次进入容器,配置生效:source /etc/profile

git 安装完,需添加环境变量 /etc/profile 文件最后加入:

        export PATH=/usr/local/git2/bin/:$PATH

        export PATH=/root/libexec/git-core:$PATH

13、composer install 下载SDK可能报错

解决方法:

        /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024

        /sbin/mkswap /var/swap.1

        /sbin/swapon /var/swap.1

如果还是报错,参考:https://shipengliang.com/software-exp/swapon-failed-operation-not-permitted-%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95.html

14、配置域名

httpd.conf 文件中加入一行

        Include /etc/httpd/extra/vhosts.conf

vhosts.conf 文件中加入配置

		
		        DocumentRoot "/var/www/html/test"
		        ServerName www.test.com
		        ServerAlias
		        
		                Options Indexes FollowSymLinks
		                AllowOverride All
		                Order allow,deny
		                Allow from all
		#               Require all granted
		        
		

运行项目,可能出现错误:STDERR could not be opened: failed to open stream: Permission denied

给项目文件夹test  777 权限就可以了

15、配置Apache重写隐藏index.php

a、/etc/httpd/conf/httpd.conf 文件中开启 LoadModule rewrite_module modules/mod_rewrite.so

b、vhosts.conf 文件中 AllowOverride All

c、项目配置:URL_MODEL 设置为 2

d、项目目录下 .htaccess 文件加入内容:

		
		  Options +FollowSymlinks
		  RewriteEngine On

		  RewriteCond %{REQUEST_FILENAME} !-d
		  RewriteCond %{REQUEST_FILENAME} !-f
		  RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
		

 如果报错 apache No input file specified.   在 .htaccess 文件中 index.php后加个'?', 改为 index.php?

        

你可能感兴趣的:(docker)