Tag:LAMP

Tag (LAMP)'s result:

(转)在Redhat安装部署Apache+MySQL+PHP(LAMP)

原文地址:https://my.oschina.net/alanlqc/blog/145449 1. 安装Apache2 yum install httpd Apache安装完成后,手动启动Apache2 /etc/init.d/httpd start 这时,直接在浏览器中输入服务器的IP地址,即可看到Apache2的默认页面。此时的Apache仅仅能提供HTTP服务,不能执行php、也不能连接MySQL数据库。 2. 安装MySQL yum install mysql mysql-server 完成后,使用如下命令启动MySQL服务: /etc/init.d/mysqld start 3. 安装PHP5 yum install php 安装完php5后,必须要重新启动Apache以使php生效: /etc/init.d/httpd restart 这时,Apache已经可以解析执行php脚本了。由于Apache的默认网站根目录位于:/var/www/html/,因此在此目录建立一个info.php用来测试Apache+PHP的正确安装与否: echo “<?php phpinfo(); ?>” > /var/www/html/info.php 然后在浏览器中访问 IP/info.php,出现了PHPINFO的输出信息则表示安装成功 安装php的mysql模块 yum install php-mysql 完成后再次重启Apache /etc/init.d/httpd restart 最后还需要将LAMP组件设置为自动启动: 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……

php+mysql实现超原始的注册登录

涉及主要知识点: 1.php操作mysql 2.加密函数md5() 3.php用?页面间传递参数 4.$_GET[]和$_POST[] 平台:redhat6+php5.3+mysql14.14+ Apache/2.2.15 (经典LAMP) 注册页面(regtest.php): <!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”> <html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″> <title>welcome to regtest.php</title> </head> <body> <h1>reg</h1> <form method=”post” action=”reg_check.php”> username<input type=”text” name=”username” > password:<input type=”password” name=”password”> password again:<input type=”password” name=”pwd_again”> <input type=”submit” value=”submit”> <input type=”reset” value=”clean”> </form> </body> </html> 注册验证页面(reg_check.php): 用于验证注册和写入数据库 <?php $db = mysql_connect(“127.0.0.1″,”root”,”root”) or die(“Fail to connect db”); mysql_select_db(“userdb”,$db) or die (“can’t connect to userdb”.mysql_error()); $username=$_POST[‘username’]; $password=$_POST[‘password’]; $pwd_again=$_POST[‘pwd_again’]; if($username==””||$password==””) { echo”error:username or password empty”; } else { if($password!=$pwd_again) { echo”password is different!”; echo”<a href=’regtest.php’>input again</a>”; } else { $md5pass=md5($password); $sql=”insert into user(username,password) values(‘$username’,’$md5pass’)”; $result=mysql_query($sql); if(!$result) { echo”Fail reg!”.mysql_error(); echo”<a href=’regtest.php’>返回</a>”; } else { echo”Success reg!”; } } } ?> 看下数据库: 登录页面(logintest.php): <!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”> <html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″> <title>welcome to login</title> </head> <body> <form method=”post” action=”login_check.php”> username:<input type=”text” name=”username” > password:<input type=”password” name=”password”> <input type=”submit” value=”login”> <input type=”reset” value=”clean”> <a href=”regtest.php” >reg</a> </form> </body> </html> 登陆验证页面(login_check.php) <?php $username=$_POST[‘username’]; $password=$_POST[‘password’]; $db = mysql_connect(“127.0.0.1″,”root”,”root”) or die(“Fail to connect db!”); mysql_select_db(“userdb”,$db)……