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
yum install -y https://mirror.webtatic.com/yum/el6/latest.rpm yum install -y httpd php56w php56w-fpm php56w-mysql php56w-pdo php56w-mbstring php56w-mcrypt php56w-pear yum install -y mysql mysql-server yum -y install wget unzip
2.3、配置部分
In lfSer
2.3.1、step1
1)检查是否引入php模块(默认开启),主配置文件:
grep ^Include /etc/httpd/conf/httpd.conf
包含如下内容:
Include conf.d/*.conf
查看PHP支持模块配置文件:
less /etc/httpd/conf.d/php.conf
包含如下内容:
<IfModule prefork.c> LoadModule php5_module modules/libphp5.so </IfModule> <IfModule worker.c> LoadModule php5_module modules/libphp5-zts.so </IfModule> AddHandler php5-script .php AddType text/html .php DirectoryIndex index.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-fpm start chkconfig php-fpm on /etc/init.d/httpd start chkconfig httpd on /etc/init.d/mysqld start chkconfig mysqld on
注:关于MySQL的安全配置请运行,这里不再详述!
mysql_secure_installation
2.3.3、step3
配置httpd服务
1)vim编辑/etc/httpd/conf/httpd.conf
启用并更改ServerName(去掉ServerName前面的#)
启用NameVirtaulHost(去掉ServerName前面的#)
ServerName www.cmdschool.org:80 NameVirtualHost *:80
2.3.4、step4(可选)
1)下载composer并全局安装
curl -sS https://getcomposer.org/installer | php
2)查看全局命令目录
echo $PATH
显示如下:
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
3)移动composer执行文件到全局命令目录(选择分隔符":"的一段路径)
mv composer.phar /usr/local/bin/composer
2.3.5、step5
安装框架
1)下载框架
wget http://down.golaravel.com/laravel/laravel-master.zip
2)解压框架
unzip laravel-master.zip
3)拷贝框架到指定目录
mkdir /var/www/www.cmdschool.org cp -rf laravel-master/* www.cmdschool.org/
2.3.6、step6
权限设置
1)目录权限设置
chown :apache -R www.cmdschool.org chmod 770 -R www.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> ServerName www.cmdschool.org DocumentRoot /var/www/www.cmdschool.org/public/ <Directory /var/www/www.cmdschool.org/public/> Options FollowSymlinks DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> <LocationMatch "^(.*\.php)$"> ProxyPassMatch fcgi://127.0.0.1:9000/var/www/www.cmdschool.org/public/ </LocationMatch> LogLevel debug ErrorLog /var/log/apache2/www.cmdschool.org.error.log CustomLog /var/log/apache2/www.cmdschool.org.access.log combined </VirtualHost>
8)重启httpd服务:
/etc/init.d/php-fpm restart /etc/init.d/httpd restart
2.3.8、step8
设置防火墙:
vim编辑/etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重启防火墙:
/etc/init.d/iptables restart
2.4.9、step9
In Client:
以下在windows客户端下测试:
1)修改本机的hosts(相当于dns解析)
notepad %SystemRoot%\System32\drivers\etc\hosts
增加如下内容:
10.168.0.177 www.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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。