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.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>
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.