一、LAMP介紹:
LAMP是指Linux+Apache+Mysql+Php的組合。以下分别進行介紹:
Apache是世界使用排名第一的Web伺服器軟體。它可以運作在幾乎所有廣泛使用的計算機平台上,由于其跨平台和安全性被廣泛使用,是最流行的Web伺服器端軟體之一。
MySQL是一款開源免費的資料軟體,MySQL是一個小型關系型資料庫管理系統,其體積小、速度快、總體擁有成本低,尤其是開放源碼這一特點,許多中小型網站為了降低網站總體擁有成本而選擇了MySQL作為網站資料庫。
PHP,是英文超級文本預處理語言Hypertext Preprocessor的縮寫。PHP 是一種 HTML 内嵌式的語言,是一種在伺服器端執行的嵌入HTML文檔的腳本語言,語言的風格有類似于C語言,被廣泛的運用。
二、實驗環境:
伺服器位址:
<a href="http://cexpert.blog.51cto.com/attachment/201208/28/5251990_1346159369oyy1.png"></a>
Apache所需要的安裝包:
httpd-2.2.3-31.el5.i386.rpm
Mysql所需要的安裝包:
mysql-5.0.77-3.el5.i386.rpm
mysql-server-5.0.77-3.el5.i386.rpm
Php所需要的安裝包:
php-5.1.6-23.2.el5_3.i386.rpm
php-mysql-5.1.6-23.2.el5_3.i386.rpm
php-mbstring-5.1.6-23.2.el5_3.i386.rpm
三、LAMP環境搭建過程:
1 、配置本地yum:
[root@localhost ~]# cd /etc/yum.repos.d/
#建立一個本地yum倉庫:
[root@localhost yum.repos.d]# cp rhel-debuginfo.repo local.repo
#編輯yum倉庫:
[root@localhost yum.repos.d]# vim local.repo
<a href="http://cexpert.blog.51cto.com/attachment/201208/28/5251990_1346159370Gecj.png"></a>
為了能夠很好的解決軟體包之間的依賴性,本地yum是一個不錯的選擇;其實隻需要建立一個Server目錄的倉庫就能夠滿足我們本實驗的需要;
2 、挂載CD光牒:
#建立一個CD光牒的挂載點 :
[root@localhost ~]# mkdir /mnt/cdrom
#對CD光牒進行挂載:
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]#
3 、Apache安裝:
[root@localhost ~]# yum install httpd -y
<a href="http://cexpert.blog.51cto.com/attachment/201208/28/5251990_1346159370N9JL.png"></a>
4 、Mysql安裝:
[root@localhost ~]# yum install mysql mysql-server -y
<a href="http://cexpert.blog.51cto.com/attachment/201208/28/5251990_1346159371B9UV.png"></a>
5 、Php安裝:
[root@localhost ~]# yum install php php-mysql php-mbstring -y
<a href="http://cexpert.blog.51cto.com/attachment/201208/28/5251990_1346159374Nc8B.png"></a>
6 、啟動httpd服務,并将httpd服務設定成開機自動運作:
[root@localhost ~]# service httpd start
Starting httpd: [ OK ]
[root@localhost ~]# chkconfig httpd on
7 、啟動mysqld服務,并将mysqld服務設定成開機自動運作:
[root@localhost ~]# service mysqld start
...
[root@localhost ~]# chkconfig mysqld on
8 、給mysql的root設定一條密碼:
[root@localhost ~]# mysqladmin -u root -p password '123'
Enter password:
9 、登入mysql和退出mysql:
<a href="http://cexpert.blog.51cto.com/attachment/201208/28/5251990_13461593782kzE.png"></a>
四、對LAMP環境進行測試:
1 、測試Apache調用php的正确性:
編輯一個php驗證頁面:
[root@localhost ~]# cd /var/www/html
[root@localhost html]# vim index.php
<a href="http://cexpert.blog.51cto.com/attachment/201208/28/5251990_1346159378jZIs.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201208/28/5251990_13461593783i0q.png"></a>
2 、測試php調用mysql的正确性:
<a href="http://cexpert.blog.51cto.com/attachment/201208/28/5251990_1346159379Ttiy.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201208/28/5251990_13461593842HVf.png"></a>
LAMP環境搭建成功了!
本文轉自 cexpert 51CTO部落格,原文連結:http://blog.51cto.com/cexpert/975583