1、安装Apache
[root@localhost ~]# yum install httpd -y
打开防火墙80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
systemctl restart firewalld.service
启动Apache并添加到自启动
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
验证
[root@localhost ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 5 2018 01:47:09
打开http:ip,如果看到test123页面,Apache安装成功
2、安装php5
[root@localhost ~]# yum install php php-mysql -y
验证
[root@localhost ~]# php -v
PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
php -v正确输出则php安装成功
3、配置Apache支持php
在/etc/httpd/conf/httpd.conf,找到:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
添加如下内容
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php
检查LoadModule php5_module modules/libphp5.so 是否已经添加 libphp5.so文件是否存在
添加完成后 systemctl restart httpd,重启Apache
在/var/www/html添加php测试文件info.php
<?php phpinfo();?>
用浏览器访问http://IP/,可以查看到PHP配置就表示你成功了。