php框架laravel 5.1环境构建(CentOS 6.5)之FastCGI
1、理论部分
Laravel是一套简洁、优雅的PHP Web开发框架(PHP Web Framework)。它可以让你从面条一样杂乱的代码中解脱出来;它可以帮你构建一个完美的网络APP,而且每行代码都可以简洁、富于表达力。
2、实验部分
2.1、实验环境
lfSer:
hostname=laravel-fastCGI
ipaddress=10.168.0.177
client:
hostnmae=client
ipaddress=10.168.0.8
2.2、yum源的安装
In lfSer
yuminstall-yhttps://mirror.webtatic.com/yum/el6/latest.rpmyuminstall-yhttpdphp56wphp56w-fpmphp56w-mysqlphp56w-pdophp56w-mbstringphp56w-mcryptphp56w-pearyuminstall-ymysqlmysql-serveryum-yinstallwgetunzip
2.3、配置部分
In lfSer
2.3.1、step1
1)检查是否引入php模块(默认开启),主配置文件:
grep^Include/etc/httpd/conf/httpd.conf
包含如下内容:
Includeconf.d/*.conf
查看PHP支持模块配置文件:
less/etc/httpd/conf.d/php.conf
包含如下内容:
<IfModuleprefork.c>LoadModulephp5_modulemodules/libphp5.so</IfModule><IfModuleworker.c>LoadModulephp5_modulemodules/libphp5-zts.so</IfModule>AddHandlerphp5-script.phpAddTypetext/html.phpDirectoryIndexindex.php
2)关闭apache的php模块
mv/etc/httpd/conf.d/php.conf/etc/httpd/conf.d/php.conf.default
2.3.2、step2
启动httpd&mysqld服务:
/etc/init.d/php-fpmstartchkconfigphp-fpmon/etc/init.d/httpdstartchkconfighttpdon/etc/init.d/mysqldstartchkconfigmysqldon
注:关于MySQL的安全配置请运行,这里不再详述!
mysql_secure_installation
2.3.3、step3
配置httpd服务
1)vim编辑/etc/httpd/conf/httpd.conf
启用并更改ServerName(去掉ServerName前面的#)
启用NameVirtaulHost(去掉ServerName前面的#)
ServerNamewww.cmdschool.org:80NameVirtualHost*:80
2.3.4、step4(可选)
1)下载composer并全局安装
curl-sShttps://getcomposer.org/installer|php
2)查看全局命令目录
echo$PATH
显示如下:
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
3)移动composer执行文件到全局命令目录(选择分隔符":"的一段路径)
mvcomposer.phar/usr/local/bin/composer
2.3.5、step5
安装框架
1)下载框架
wgethttp://down.golaravel.com/laravel/laravel-master.zip
2)解压框架
unziplaravel-master.zip
3)拷贝框架到指定目录
mkdir/var/www/www.cmdschool.orgcp-rflaravel-master/*www.cmdschool.org/
2.3.6、step6
权限设置
1)目录权限设置
chown:apache-Rwww.cmdschool.orgchmod770-Rwww.cmdschool.org
2)确保selinux是Enforcing状态:
getenforce
3)恢复预设的selinux type:
restorecon-RFvv/var/www/www.cmdschool.org/
4)检查当前的selinux type:
ll-dZ/var/www/www.cmdschool.org/
2.3.7、step7
设置虚拟目录:
vim编辑/etc/httpd/conf.d/www.cmdschool.org.conf
<VirtualHost*:80>ServerNamewww.cmdschool.orgDocumentRoot/var/www/www.cmdschool.org/public/<Directory/var/www/www.cmdschool.org/public/>OptionsFollowSymlinksDirectoryIndexindex.phpAllowOverrideAllOrderallow,denyAllowfromall</Directory><LocationMatch"^(.*\.php)$">ProxyPassMatchfcgi://127.0.0.1:9000/var/www/www.cmdschool.org/public/</LocationMatch>LogLeveldebugErrorLog/var/log/apache2/www.cmdschool.org.error.logCustomLog/var/log/apache2/www.cmdschool.org.access.logcombined</VirtualHost>
8)重启httpd服务:
/etc/init.d/php-fpmrestart/etc/init.d/httpdrestart
2.3.8、step8
设置防火墙:
vim编辑/etc/sysconfig/iptables
-AINPUT-mstate--stateNEW-mtcp-ptcp--dport80-jACCEPT
重启防火墙:
/etc/init.d/iptablesrestart
2.4.9、step9
In Client:
以下在windows客户端下测试:
1)修改本机的hosts(相当于dns解析)
notepad%SystemRoot%\System32\drivers\etc\hosts
增加如下内容:
10.168.0.177www.cmdschool.org
2)浏览器测试
浏览器测试你可以看到如下提示:
3)日志的排查方法
In lfSer:
参阅如下日志可知属于代码级别的错误,排查方法如下:
配置文件日志:
tail -f /var/log/apache2/www.cmdschool.org.error.log
监看以上信息表明PHP代码已经完成送到fastCGI网关
tail -f /var/log/php-fpm/error.log
监看以上日志无任何反应,证明php-fpm解析php代码无任何异常。
tail -f /var/www/www.cmdschool.org/storage/logs/laravel.log
监看以上信息发现错误,可见这种错误是框架已经预见的,应该由php程序员处理,与运维无关。
参考文献:
laravel框架官方资料:
http://lumen.laravel-china.org/docs
http://www.golaravel.com/
laravel环境构建:
https://vpsineu.com/blog/how-to-install-laravel-on-a-centos-7-vps/
yum源:
http://mirror.webtatic.com/yum/
Composer的使用方法:
http://www.phpcomposer.com/composer-the-new-age-of-dependency-manager-for-php/
http://www.phpcomposer.com/
fastCGI:
http://serverfault.com/questions/587461/apache-2-4-hhvm-3-1-static-content-serving
http://serverfault.com/questions/450628/apache-2-4-php-fpm-proxypassmatch
http://serverfault.com/questions/553899/forwarding-php-requests-via-proxypassmatch-as-a-handler-or-only-when-file-exist
mod_rewrite模块的讲解:
http://www.yeeyan.org/articles/view/jcky/59298
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。