34rfdw 发表于 2013-11-28 09:32:51

linux 快速安装LAMP教程

最近学习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.iyunv.com/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.


mlczhg 发表于 2013-11-30 15:30:46

如果超人会飞,那就让我在空中停一停歇。

狂欢‰一夜 发表于 2013-12-4 00:38:22

突然間、一場大雨傾盆而落。讓眼淚有叻繼續流的藉口。

dwd1985 发表于 2013-12-7 00:37:51

甘愿俯身姿态到尘埃,你的微笑璀璨照亮我世界。

lxh999 发表于 2013-12-9 03:59:53

曾经说好的永远,在转眼间都化为乌有。

king71 发表于 2013-12-11 14:14:53

夜里不适合听那首歌因为了解思念是哪种颜色

五郎. 发表于 2013-12-13 14:16:33

神话般的爱情,只出现在童话里。
页: [1]
查看完整版本: linux 快速安装LAMP教程