php框架laravel 5.1环境构建大发彩票平台开发之FastCGI

1、理论部分

Laravel是一套简洁、优雅的大发彩票平台开发框架(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

1

2

3

4

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模块(默认开启),主配置文件:

1

grep ^Include /etc/httpd/conf/httpd.conf

包含如下内容:

1

Include conf.d/*.conf

查看PHP支持模块配置文件:

1

less /etc/httpd/conf.d/php.conf

包含如下内容:

1

2

3

4

5

6

7

8

9

10

11

<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模块

1

mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.default

2.3.2、step2

启动httpd&mysqld服务:

1

2

3

4

5

6

/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的安全配置请运行,这里不再详述!

1

mysql_secure_installation

2.3.3、step3

配置httpd服务

1)vim编辑/etc/httpd/conf/httpd.conf

启用并更改ServerName(去掉ServerName前面的#)

启用NameVirtaulHost(去掉ServerName前面的#)

1

2

ServerName www.cmdschool.org:80

NameVirtualHost *:80

2.3.4、step4(可选)

1)下载composer并全局安装

1

curl -sS https://getcomposer.org/installer | php

2)查看全局命令目录

1

echo $PATH

显示如下:

1

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

3)移动composer执行文件到全局命令目录(选择分隔符":"的一段路径)

1

mv composer.phar /usr/local/bin/composer

2.3.5、step5

安装框架

1)下载框架

1

wget http://down.golaravel.com/laravel/laravel-master.zip

2)解压框架

1

unzip laravel-master.zip

3)拷贝框架到指定目录

1

2

mkdir /var/www/www.cmdschool.org

cp -rf laravel-master/* www.cmdschool.org/

2.3.6、step6

权限设置

1)目录权限设置

1

2

chown :apache -R www.cmdschool.org

chmod 770 -R www.cmdschool.org

2)确保selinux是Enforcing状态:

1

getenforce

3)恢复预设的selinux type:

1

restorecon -RFvv /var/www/www.cmdschool.org/

4)检查当前的selinux type:

1

ll -dZ /var/www/www.cmdschool.org/

2.3.7、step7

设置虚拟目录:

vim编辑/etc/httpd/conf.d/www.cmdschool.org.conf

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

<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服务:

1

2

/etc/init.d/php-fpm restart

/etc/init.d/httpd restart

2.3.8、step8

设置防火墙:

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.9、step9

In Client:

以下在windows客户端下测试:

1)修改本机的hosts(相当于dns解析)

1

notepad %SystemRoot%\System32\drivers\etc\hosts

增加如下内容:

1

10.168.0.177 www.cmdschool.org

2)浏览器测试

浏览器测试你可以看到如下提示:

wKioL1ZlQaPBO86GAAA0JhpSOok107.png

3)日志的排查方法

In lfSer:

参阅如下日志可知属于代码级别的错误,排查方法如下:

配置文件日志:

tail -f /var/log/apache2/www.cmdschool.org.error.log

wKioL1ZlQpfAusT_AAEP8HDUDio442.png

监看以上信息表明PHP代码已经完成送到fastCGI网关

tail -f /var/log/php-fpm/error.log

wKiom1ZlQp3SwsZWAABUkDLyr4Q598.png

监看以上日志无任何反应,证明php-fpm解析php代码无任何异常。

tail -f /var/www/www.cmdschool.org/storage/logs/laravel.log

wKiom1ZlQ6aw2VkuAAIdI-OVT4M009.png

监看以上信息发现错误,可见这种错误是框架已经预见的,应该由php程序员处理,与运维无关。

参考文献:

猜你喜欢

转载自blog.csdn.net/qq_42772238/article/details/81167662