最近學習linux,安裝lamp遇到一些問題,記錄下來分享一下;
linux +
apache +
mysql +
php/perl together commonly known as
lamp
server.
參考blog:
一 安裝apache:
二 安裝mysql:(如遇問題,參考:
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:
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:
#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
2.2
vi /var/www/html/write.php
<?php
$comment=$_get['comment'];
if ($comment)
print ($comment);
print ("thanks for submit!!!");
?>
3、測試php查詢表comment_table資料:
vi /var/www/html/view_comment_table.php
<?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 "query: $string";
print "\n";
print "";
print "id";
print "comment ";
print "";
while (list($id,$comment) = mysql_fetch_array($result))
print "";
mysql_close($conn);
?>
------------------
dylan presents.
安裝lamp教程
步驟一,安裝apache2 sudo apt get install apache2 安裝完成。執行如下命令重啟下 sudo etc init.d apache2 restart 在瀏覽器裡輸入http localhost或者是如果看到了it works 那就說明apache就成功的安裝了,apac...
LAMP安裝教程
lamp環境系統需求 lamp安裝及應用步驟 a 新增站點 sh vhost.sh i youripaddres b 管理資料庫 youripaddress phpmyadmin eg 107.84.212.32 phpmyadmin username root password i don t k...
LAMP快速安裝
1.版本介紹 apache安裝 安裝mysql 5.5.48 安裝依賴 yum install ncurses devel libaio devel y cd server tools wget tar zxf cmake 2.8.8.tar.gz cd cmake 2.8.8 configure ...