1、安装httpd
yum install httpd
创建测试文件
cd /var/www/html
vim index.php
加入以下内容
<html>
<head>
<title>PHP Page</title>
</head>
<body>
<h1>PHP start</h1>
<?php
phpinfo();
?>
<h1>PHP end</h1>
</body>
</html>
启动httpd服务器
service httpd start
关闭防火墙
service iptables stop
修改httpd配置文件,添加默认启动文件
vim /etc/httpd/conf/httpd.conf
/index
修改完后从新加载一下服务
service httpd reload
2、安装PHP
yum install php
进入PHP配置文件查看信息
vim /etc/httpd/conf.d/php.conf
把hpptd的配置文件中的默认头文件删除
vim /etc/httpd/conf/httpd.conf
找到index.php ,去掉
重启httpd服务
service httpd restart
然后测试一下index.php 如果能够解释phpinfo()函数,说明php成功安装。
3、安装MYSQL数据库
yum install mysql mysql-server
服务器程序:mysqld
启动服务器程序:service mysqld start 初次启动服务器会初始化数据库
服务脚本:/etc/rc.d/init.d/mysqld
配置文件:/etc/my.cnf
数据文件:/var/lib/mysql
对数据库用户受权
mysql> grant all on . to 'root'@'192.168.1.%' identified by '12321';
mysql> grant all on . to 'root'@'127.0.0.1' identified by '12321';
mysql> grant all on . to 'root'@'localhost' identified by '12321';
mysql> flush privileges;
安装PHP连接MYSQL模块
yum install php-mysql
测试代码
<?php
$conn = mysql_connect('localhost','root','12321');
if ($conn)
echo "succ";
else
echo "failute";
mysql_close();
?>
如果把localhost改成服务器IP或者是127.0.0.1会连接失败。解决办法,把LINUX防火墙关闭。
关闭SELINUX
chkconfig --level 12345 iptables off
chkconfig --level 12345 ip6tables off
service iptables stop
service ip6tables stop
查看SELinux状态:
1、/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态
SELinux status: enabled
2、getenforce ##也可以用这个命令检查
关闭SELinux:
1、临时关闭(不用重启机器):
setenforce 0 ##设置SELinux 成为permissive模式
##setenforce 1 设置SELinux 成为enforcing模式
2、修改配置文件需要重启机器:
修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled
转载于:https://blog.51cto.com/351842/2053669