php安装

php安装

环境准备;

#关闭防火墙selinux 将yum源更换成国内源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0   9746      0 --:--:-- --:--:-- --:--:--  9784
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]#  systemctl disable --now firewalld
[root@localhost ~]#   sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@localhost ~]#  setenforce 0

安装php及修改配置文件

# 注:使用yum安装php会自动安装httpd以保证php正常运行
[root@localhost ~]# yum -y install php php-fpm
#:修改配置文件
[root@localhost ~]# cd /etc/httpd/conf.d/
[root@localhost conf.d]# cp /usr/share/doc/httpd/httpd-vhosts.conf  vhosts.conf
[root@localhost ~]#  vim vhosts.conf
#:在文章最后添加
<VirtualHost *:80>
    DocumentRoot "/var/www/html"
    ServerName www.liu.com
    ErrorLog "/var/log/httpd/www.liu.com-error_log"
    CustomLog "/var/log/httpd/www.liu.com-access_log" common
   ProxyRequests off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
   <Directory "/var/www/html">
     Options none
     AllowOverride none
     Require all granted
  </Directory>
</VirtualHost
 #:编辑httpd.conf文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
<IfModule dir_module>
    DirectoryIndex index.php index.html #将这个地方增加index.php
</IfModule>
AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php  #:1
    AddType application/x-httpd-php-source .phps  #:2
    #:添加这两行
    
#: 编辑www.conf文件    
[root@localhost ~]#  vim /etc/php-fpm.d/www.conf
 listen = 0.0.0.0:9000

 #: 编辑测试页
[root@localhost ~]#  cat /var/www/html/index.php 
<?php
    phpinfo();
?>

启动服务

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# systemctl start php-fpm
[root@localhost ~]# systemctl enable php-fpm
[root@localhost ~]# ss -antl 
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                  0.0.0.0:9000              0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         128                        *:80                      *:*       
LISTEN    0         128                     [::]:22                   [::]:* 

测试访问:

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值