CentOS 7安装php

我们已经在上一篇里安装上了nginx;现在我们想要php(也许还包括mysql)。

(CentOS 7里使用mariadb替代了mysql)

# yum install mariadb-client mariadb-server

# yum install php php-fpm php-mysql

# systemctl enable php-fpm

# systemctl start php-fpm

修改/etc/nginx/conf.d/default.conf:

找到下面的注释:

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

移除相应行的注释,并修改配置:

1. 在配置文件的server段增加"root=/usr/share/nginx/html",使其对该server全局有效;

2. 注释所有location段里的root行,以继承server段的root值;

3. 修改fastcgi_param SCRIPT_FILENAME的值为\$document_root\$fastcgi_script_name

注意不要拼写错误。

重启nginx:

# systemctl restart nginx

写个php测试下:

# vi /usr/share/nginx/html/info.php

<?php phpinfo() ?>

Q&A

Q1. 显示php代码而不是执行结果

A1. nginx的配置文件没有打开fastcgi

Q2. 访问php显示File not found但文件明明在那里

A2. 这表示nginx没有找到php文件。修改fastcgi_param SCRIPT_FILENAME的值为\$document_root\$fastcgi_script_name。

Q3. 显示空页面

A3. 这表示nginx找到文件但php-frm解析器未能找到该文件并向前端返回空页面。注意root的值。

猜你喜欢

转载自www.cnblogs.com/byeyear/p/9460333.html
今日推荐