linux 快速安装LAMP教程

22 篇文章 0 订阅

最近学习linux,安装lamp遇到一些问题,记录下来分享一下;

------------------------------------------------------------------------------------------------------------------

Linux Apache MySQL PHP/Perl together commonly known as LAMP Server.

参考blog:http://www.howtoforge.com/quick-n-easy-lamp-server-centos-rhel

一 安装apache:

yum install httpd httpd-devel

/etc/init.d/httpd start

二 安装mysql:(如遇问题,参考:http://blog.csdn.net/indexman/article/details/16946141)

yum install mysql mysql-server mysql-devel

/etc/init.d/mysqld start
mysql

mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root';
mysql> FLUSH PRIVILEGES;

mysql -u root -p
Enter Password: <your new password>

1、创建用户:

mysql> GRANT ALL PRIVILEGES ON *.* TO dylan@localhost IDENTIFIED BY 'dylan123';
mysql> FLUSH PRIVILEGES;

2、创建测试数据库:

mysql> create database testdb;
Query OK; 1 row affected (0.03 sec)

mysql> show databases;
+-----------------+
| Database |
+-----------------+
| mysql |
| test |
| test_db |
+-----------------+
6 rows in set (0.00 sec) 

mysql> use testdb
Database changed 

mysql> CREATE TABLE comment_table(
-> id INT NOT NULL auto_increment,
-> comment TEXT,
-> PRIMARY KEY(id));
Query OK, 0 rows affected (0.10 sec)
mysql> show tables;
+-------------------------+
| Tables_in_test_database |
+-------------------------+
| comment_table |
+-------------------------+
1 row in set (0.00 sec)
mysql> INSERT INTO comment_table VALUES ('0','comment');
Query OK, 1 row affected (0.06 sec)
mysql> SELECT * FROM comment_table;
+----+---------+
| id | comment |
+----+---------+
| 1 | comment |
+----+---------+
1 row in set (0.01 sec)

三、安装PHP5:

yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

/etc/init.d/httpd restart

vi /var/www/html/test.php

#test.php 内容如下:

<?php
   php_info();
?>

测试地址:Then point your browser to http://localhost/test.php

四、测试PHP操作mysql:

1、测试PHP能否正常连接mysql:

vi  /var/www/html/test_conn.php

<?php
$link=mysql_connect('127.0.0.1','root','root123');
if(!$link) echo "false!";
else echo " true!";
mysql_close($link);
?>


2、测试PHP提交数据到表comment_table:

 2.1   vi /var/www/html/write_comment_table.html

<html>
<form action=write.php method="get">
<input type="text" name="comment" size="80"> <br>
<input type="submit">
</form>
</html>
 2.2   vi /var/www/html/write.php
<html>
<body>
<?php
$comment=$_GET['comment'];
if ($comment){
$conn=mysql_connect("localhost","root","root123" )
or die("Could not connect to MySQL as root");
mysql_select_db("testdb", $conn)
or die("could not select the test_database");
$string="INSERT INTO comment_table VALUES ('0','$comment')";
mysql_query($string)
or die(mysql_error( ));}

print ($comment);
print ("thanks for submit!!!");
?>
</body>
</html>


3、测试PHP查询表comment_table数据:

 vi /var/www/html/view_comment_table.php

<html>
<?php
$conn=mysql_connect("localhost","root","root123" )
or die("Could not connect to MySQL as root");
mysql_select_db("testdb", $conn)
or die("could not select the test_database");
$string="SELECT * FROM comment_table";
$result= mysql_query($string)
or die(mysql_error( ));
$numbers_cols= mysql_num_fields($result);
print "<b>query: $string</b>";
print "<table border =1>\n";
print "<tr>";
print "<td> ID</td>";
print "<td> Comment </td>";
print "</tr>";
while (list($id,$comment) = mysql_fetch_array($result)){
print "<tr>";
print "<td>$id</td>";
print "<td>$comment</td>";
print "</tr>";}
print "</table>";
mysql_close($conn);
?>
</html>

------------------

dylan presents.


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值