本文小编为大家详细介绍“redhat如何安装php和mysql”,内容详细,步骤清晰,细节处理妥当,希望这篇“redhat如何安装php和mysql”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
redhat安装php和mysql的方法:1、通过“yum install httpd”安装Apache2并启动;2、使用“yum install mysql mysql-server”安装MySQL并启动;3、通过“yum install php”安装PHP,然后重新启动Apache以使php生效即可。
在RedHat上安装部署Apache+MySQL+PHP环境
1. 安装Apache2
chkconfig --levels 2345 httpd on
chkconfig --levels 2345 mysqld on
测试环境(虚拟机):
登录本地的MySQL创建一个表,创建一个用户,设定该用户对表的操作权限
use test;
create table login(
uid char(20),
dt int,
text char(50)
);
grant select,insert,update,delete on *.* to alan@"%" identified by 'password';
test.php
<?php
$host = 'xxx.xxx.xxx.xxx';
$user = 'alan';
$passwd = 'password';
$db = 'test';
$conn = mysql_connect($host,$user,$passwd);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
echo "select data from MySQL<br >";
mysql_select_db($db, $conn);
$select_sql = "select * from login";
$result = mysql_query($select_sql);
echo "<table border='1'><tr><th>uid</th><th>time</th><th>text</th></tr>";
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>".$row['uid']."</td>";
echo "<td>".$row['dt']."</td>";
echo "<td>".$row['text']."</td>";
echo "</tr>";
}
echo "</table><br >";
echo "<form action='insert.php' method='post'>
Name:<input type='text' name='uid' />
text:<input type='text' name='text' />
<input type='submit'></form>";
mysql_close($conn);
?>
insert.php
<?php
$host = 'xxx.xxx.xxx.xxx';
$user = 'alan';
$passwd = 'password';
$db = 'test';
$conn = mysql_connect($host,$user,$passwd);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db, $conn);
$dt = time();
$insert_sql = "insert into login(uid,dt,text) values('$_POST[uid]', $dt, '$_POST[text]')";
echo "SQL: ".$insert_sql."<br >";
if (!mysql_query($insert_sql, $conn)) {
die('Error: ' . mysql_error());
}
echo "1 record added.<br >";
mysql_close($conn);
?>
1. 访问页面
2. 提交表单,执行一条sql插入语句
3. 返回页面刷新查看结果
相关配置与环境
Apache主配置文件:/etc/httpd/conf/httpd.conf
Apache主配置目录,可以将不同类型的配置分门别类放入这个目录中:/etc/httpd/conf.d/
Apache网站根目录:/var/www/html/
Apache日志文件目录:/var/log/httpd
MySQL的my.cnf配置文件:/etc/my.cnf
MySQL数据库文件位置:/usr/lib/mysql