Ubuntu下LAMP的搭建
Ubuntu下LAMP的搭建
LAMP 的意思是 Linux + Apache + MySql + PHP ,全是免費開源的。
LAMP安裝其實簡單,但是***次安裝時,不太熟悉,走了很多彎路,對應不同版本的linux,apache,mysql,PHP,安裝方法可能會有所不同,一定注意版本的問題,網上資料很多,但是也有很多垃圾資料,搞得頭暈眼花的。以下都在root權限操作。
1. Linux系統(tǒng)為Ubuntu 9.04
命令:cat /etc/issue
文件/etc/issue保存著系統(tǒng)的版本信息。
命令:lsb_release –a
顯示系統(tǒng)的版本信息。如下:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 9.04
Release: 9.04
Codename: jaunty
2. 安裝apache
命令:apt-get install apache2
安裝apache服務器,會聯(lián)網下載,并自動安裝。
命令:/etc/init.d/apache2 start
啟動apache服務器。
命令:netstat –tnl
查看網絡狀態(tài)的命令,apache一般監(jiān)聽80端口,如看到有80端口,說明apache已運行,顯示如下:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
為進一步確認,可打開瀏覽器,輸入http://localhost,出現It works !說明運行成功。默認的頁面是 /var/www/index.html
命令: apache2 –v
查看apache服務器的版本。顯示如下:
Server version: Apache/2.2.11 (Ubuntu)
Server built: Aug 16 2010 17:45:31
命令:/etc/init.d/apache2 stop
停止apache服務器。
3. 安裝php
命令: apt-get install php5
安裝php。
命令:gedit /var/www/testphp.php
輸入:
保存。
測試,在瀏覽器輸入:http://localhost/testphp.php
4. 安裝mysql
命令:apt-get install mysql-server
安裝mysql。安裝過程中會提示輸入用戶名和密碼,輸入用戶名 root,密碼 root ,后面登錄時要用。。
命令:/etc/init.d/mysql start
啟動mysql。
命令:mysql –uroot –proot
以用戶名root,密碼root,登錄mysql,-u代表用戶,-p代表密碼,不帶空格。顯示如下:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.0.75-0ubuntu10.5 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
數據庫操作的命令后要加 ; 號。如:
- show databases; //顯示所有的數據庫名
- create database db; //建立新數據庫db
- use db; //切換數據庫名
- create table em(id int(3) primary key,name char(10)); //建表
- insert into em values(100,’zhang’); //插入數據
- insert into em values(100,’wang’); //插入數據
- insert into em values(100,’zhao’); //插入數據
- show tables; //顯示數據庫中的表名
- select * from em; //查看表中的數據
- exit; //退出
5. 安裝phpmyadmin
命令:apt-get install phpmyadmin
這是個輔助的工具,服務器端安裝后,客戶端可以遠程登錄到服務器,對mysql的數據庫進行相關操作,安裝過程中會提示輸入用戶名和密碼,phpmyadmin的功能是用php實現的,安裝后,在apache的配置文件文件 /etc/apache2/apache2.conf 中加入如下內容:
- Include /etc/phpmyadmin/apache.conf
重啟apache服務器。在瀏覽器中輸入:http://localhost/phpmyadmin,即可登錄,進行數據庫的相關操作。
6. 安裝java
- apt-get install openjdk-6-jre //安裝jre
- apt-get install openjdk-6-jdk //安裝jdk
【編輯推薦】