您好,登錄后才能下訂單哦!
1、理論部分
Laravel是一套簡潔、優(yōu)雅的PHP Web開發(fā)框架(PHP Web Framework)。它可以讓你從面條一樣雜亂的代碼中解脫出來;它可以幫你構(gòu)建一個完美的網(wǎng)絡(luò)APP,而且每行代碼都可以簡潔、富于表達力。
2、實驗部分
2.1、實驗環(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模塊(默認開啟),主配置文件:
grep ^Include /etc/httpd/conf/httpd.conf
包含如下內(nèi)容:
Include conf.d/*.conf
查看PHP支持模塊配置文件:
less /etc/httpd/conf.d/php.conf
包含如下內(nèi)容:
<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)關(guān)閉apache的php模塊
mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.default
2.3.2、step2
啟動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的安全配置請運行,這里不再詳述!
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)移動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
<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服務(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客戶端下測試:
1)修改本機的hosts(相當(dāng)于dns解析)
notepad %SystemRoot%\System32\drivers\etc\hosts
增加如下內(nèi)容:
10.168.0.177 www.cmdschool.org
2)瀏覽器測試
瀏覽器測試你可以看到如下提示:
3)日志的排查方法
In lfSer:
參閱如下日志可知屬于代碼級別的錯誤,排查方法如下:
配置文件日志:
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)錯誤,可見這種錯誤是框架已經(jīng)預(yù)見的,應(yīng)該由php程序員處理,與運維無關(guā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
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。