centos 部署php_Centos 搭建简单PHP环境

使用Nginx 搭建PHP环境

一.安装php

1、默认centos7 自带的是php5.4版本,升级php5.6。不升级只有yum 安装

2、升级php5.6

Java

yum install epel-release

1

yuminstallepel-release

Java

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

1

rpm-ivhhttp://rpms.famillecollet.com/enterprise/remi-release-7.rpm

3、安装PHP5.6.x

yum源配置好了,下一步就安装PHP5.6

Java

yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-gd php-redis

1

yuminstall--enablerepo=remi--enablerepo=remi-php56phpphp-opcachephp-develphp-mbstringphp-mcryptphp-mysqlndphp-phpunit-PHPUnitphp-pecl-xdebugphp-pecl-xhprofphp-gdphp-redis

4、安装PHP-fpm

Java

yum install --enablerepo=remi --enablerepo=remi-php56 php-fpm

1

yuminstall--enablerepo=remi--enablerepo=remi-php56php-fpm

php-fpm,并设置php-fpm开机自启

Java

service php-fpm start

chkconfig php-fpm on

1

2

3

servicephp-fpmstart

chkconfigphp-fpmon

二.配置Nginx

在相应的目录下找到nginx.conf配置文件,这里是在默认目录下,开启Nginx支撑PHP的模块

Java

修改前

#location ~ \.php$ {

# root html;

# fastcgi_pass 127.0.0.1:9000;

# fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

# include fastcgi_params;

修改后

location ~ \.php$ {

root /usr/local/www/html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

修改前

#location~\.php${

#roothtml;

#fastcgi_pass127.0.0.1:9000;

#fastcgi_indexindex.php;

#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;

#includefastcgi_params;

修改后

location~\.php${

root/usr/local/www/html;

fastcgi_pass127.0.0.1:9000;

fastcgi_indexindex.php;

fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;

includefastcgi_params;

}

首先将注释,也就是#号去掉,接着将fastcgi_param对应的/scripts$fastcgi_script_name改成$document_root$fastcgi_script_name

保存完修改后的配置,重启一下nginx,让配置生效,我们就可以通过nginx来处理PHP请求了

三.测试是否成功

然后,你可以写一个php文件在浏览器中运行一下了;

Java

vi /usr/local/www/html/info.php

i

Esc

:wq

1

2

3

4

5

vi/usr/local/www/html/info.php

i

Esc

:wq

然后,在自己电脑浏览器输入 虚拟机ip/info.php运行,会出现php的配置一些信息安装成功

另外也可以安装Apache来运行PHP

1、安装centos7默认自带(Apache2.4.6)版本

Java

yum -y install httpd

1

yum-yinstallhttpd

2、修改其配置文件:

/etc/httpd/conf/http.conf

修改一下端口号和根目录

3、开启apache服务

Java

systemctl start httpd.service

1

systemctlstarthttpd.service

4、设置apache服务开机启动

Java

systemctl enable httpd.service

1

systemctlenablehttpd.service

5.开启防火墙

参考资料:

https://blog.csdn.net/hailanzi/article/details/79510240

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值