1、理論部分
我們提供的服務(wù)有:網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、博野ssl等。為上千企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的博野網(wǎng)站制作公司
Laravel是一套簡(jiǎn)潔、優(yōu)雅的PHP Web開發(fā)框架(PHP Web Framework)。它可以讓你從面條一樣雜亂的代碼中解脫出來;它可以幫你構(gòu)建一個(gè)完美的網(wǎng)絡(luò)APP,而且每行代碼都可以簡(jiǎn)潔、富于表達(dá)力。
2、實(shí)驗(yàn)部分
2.1、實(shí)驗(yàn)環(huán)境
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模塊(默認(rèn)開啟),主配置文件:
grep ^Include /etc/httpd/conf/httpd.conf
包含如下內(nèi)容:
Include conf.d/*.conf
查看PHP支持模塊配置文件:
less /etc/httpd/conf.d/php.conf
包含如下內(nèi)容:
LoadModule php5_module modules/libphp5.so LoadModule php5_module modules/libphp5-zts.so AddHandler php5-script .php AddType text/html .php DirectoryIndex index.php
2)關(guān)閉apache的php模塊
mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.default
2.3.2、step2
啟動(dòng)httpd&mysqld服務(wù):
/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
注:關(guān)于MySQL的安全配置請(qǐng)運(yùn)行,這里不再詳述!
mysql_secure_installation
2.3.3、step3
配置httpd服務(wù)
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)移動(dòng)composer執(zhí)行文件到全局命令目錄(選擇分隔符":"的一段路徑)
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
權(quán)限設(shè)置
1)目錄權(quán)限設(shè)置
chown :apache -R www.cmdschool.org chmod 770 -R www.cmdschool.org
2)確保selinux是Enforcing狀態(tài):
getenforce
3)恢復(fù)預(yù)設(shè)的selinux type:
restorecon -RFvv /var/www/www.cmdschool.org/
4)檢查當(dāng)前的selinux type:
ll -dZ /var/www/www.cmdschool.org/
2.3.7、step7
設(shè)置虛擬目錄:
vim編輯/etc/httpd/conf.d/www.cmdschool.org.conf
ServerName www.cmdschool.org DocumentRoot /var/www/www.cmdschool.org/public/ Options FollowSymlinks DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all ProxyPassMatch fcgi://127.0.0.1:9000/var/www/www.cmdschool.org/public/ LogLevel debug ErrorLog /var/log/apache2/www.cmdschool.org.error.log CustomLog /var/log/apache2/www.cmdschool.org.access.log combined
8)重啟httpd服務(wù):
/etc/init.d/php-fpm restart /etc/init.d/httpd restart
2.3.8、step8
設(shè)置防火墻:
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客戶端下測(cè)試:
1)修改本機(jī)的hosts(相當(dāng)于DNS解析)
notepad %SystemRoot%\System32\drivers\etc\hosts
增加如下內(nèi)容:
10.168.0.177 www.cmdschool.org
2)瀏覽器測(cè)試
瀏覽器測(cè)試你可以看到如下提示:
3)日志的排查方法
In lfSer:
參閱如下日志可知屬于代碼級(jí)別的錯(cuò)誤,排查方法如下:
配置文件日志:
tail -f /var/log/apache2/www.cmdschool.org.error.log
監(jiān)看以上信息表明PHP代碼已經(jīng)完成送到fastCGI網(wǎng)關(guān)
tail -f /var/log/php-fpm/error.log
監(jiān)看以上日志無任何反應(yīng),證明php-fpm解析php代碼無任何異常。
tail -f /var/www/www.cmdschool.org/storage/logs/laravel.log
監(jiān)看以上信息發(fā)現(xiàn)錯(cuò)誤,可見這種錯(cuò)誤是框架已經(jīng)預(yù)見的,應(yīng)該由php程序員處理,與運(yùn)維無關(guān)。
參考文獻(xiàn):
laravel框架官方資料:
http://lumen.laravel-china.org/docs
http://www.golaravel.com/
laravel環(huán)境構(gòu)建:
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