1、前言
公司开发要求使用php5.6版本,由于笔者不想通过编译安装,故引入remi的yum源来完成此项任务,跟之前的lamp环境加载fastcgi的方式大致一样,只是有一点点差异。
2、实验部分
2.1、实验环境
lampSer:
hostname=lamp-fcgi
ipaddress=10.168.0.177
client:
hostnmae=client
ipaddress=10.168.0.8
2.2、yum源的安装
123 | yum -y install http: //rpms .famillecollet.com /enterprise/remi-release-6 .rpm yum -y install httpd mod_proxy_fcgi php56-php-fpm mysql mysql-server php-mysql yum -y install policycoreutils-python |
2.3、配置部分
2.3.1、step1
注:如果你不想了解fastcgi的加载方式本步骤请直接跳过
检查是否引入fastcgi模块(默认开启),主配置文件:
1 | grep ^Include /etc/httpd/conf/httpd .conf |
包含如下内容:
1 | Include conf.d/*.conf |
查看fastcgi支持模块配置文件:
1 | grep LoadModule /etc/httpd/conf .d /mod_proxy_fcgi .conf |
包含如下内容:
1 | LoadModule proxy_fcgi_module modules /mod_proxy_fcgi .so |
2.3.2、step2
1)启动php-fpm、httpd&mysqld服务:
123456 | /etc/init .d /php56-php-fpm start chkconfig php56-php-fpm on /etc/init .d /httpd start chkconfig httpd on /etc/init .d /mysqld start chkconfig mysqld on |
注:关于mysql的安全设置请运行以下指令,这里不再详述!
1 | mysql_secure_installation |
2)确认php-fpm服务启用
1 | netstat -anp | grep php |
应当显示如下:
123 | tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2547 /php-fpm unix 3 [ ] STREAM CONNECTED 34665 2547 /php-fpm unix 3 [ ] STREAM CONNECTED 34664 2547 /php-fpm |
2.3.3、step3
1)vim编辑/etc/httpd/conf/httpd.conf
启用并更改ServerName(去掉ServerName前面的#)
启用NameVirtaulHost(去掉ServerName前面的#)
12 | ServerName www.cmdschool.org:80 NameVirtualHost *:80 |
2)新建虚拟目录:
1 | mkdir /var/www/www .cmdschool.org |
3)添加测试页面:
1 | echo '<?php phpinfo(); ?>' > /var/www/www .cmdschool.org /index .php |
4)确保selinux是Enforcing状态:
1 | getenforce |
5)恢复预设的selinux type:
1 | restorecon -RFvv /var/www/www .cmdschool.org/ |
显示如下:
12 | restorecon reset /var/www/www .cmdschool.org context unconfined_u:object_r:httpd_sys_content_t:s0->system_u:object_r:httpd_sys_content_t:s0 restorecon reset /var/www/www .cmdschool.org /index .php context unconfined_u:object_r:httpd_sys_content_t:s0->system_u:object_r:httpd_sys_content_t:s0 |
6)检查当前的selinux type:
1 | ll -dZ /var/www/www .cmdschool.org/ |
7)开启虚拟目录对fastcgi的支持并设置虚拟目录:
vim编辑/etc/httpd/conf.d/www.cmdschool.org.conf
1234567891011 | DirectoryIndex /index .php index.php <VirtualHost *:80> ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi: //127 .0.0.1:9000 /var/www/www .cmdschool.org/$1 DocumentRoot /var/www/www .cmdschool.org ServerName www.cmdschool.org < /VirtualHost > <Directory /var/www/www .cmdschool.org> Options All AllowOverride all < /Directory > |
8)重启php-fpm&httpd服务:
12 | /etc/init .d /php56-php-fpm restart /etc/init .d /httpd restart |
2.3.4、step4
设置防火墙:
vim编辑/etc/sysconfig/iptables
1 | -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT |
重启防火墙:
1 | /etc/init .d /iptables restart |
2.4.5、step5
In client
测试服务器
1)vim编辑/etc/hosts
确保包含www.cmdschool.org的指向10.168.0.171的唯一值:
1 | 10.168.0.171 www.cmdschool.org |
2)curl测试
1 | curl www.cmdschool.org |
3)浏览器测试
共同学习,写下你的评论
评论加载中...
作者其他优质文章