歷史兩日,終于在centos 6.0上搭建好了完整的LAMP開發(fā)環(huán)境,中間有很多麻煩,但還是一點(diǎn)點(diǎn)解決了。并且寫好了這份安裝文檔,留給自己和以后再安裝中遇到問題的人。予人玫瑰,手留余香。
一、搭建環(huán)境:
1、CentOS 6.0虛擬機(jī)(最小安裝)
2、putty
3、ssh shell
二、準(zhǔn)備工作:
1、源碼包

2、安裝gcc、gcc-c++編譯器(yum安裝)
若虛擬機(jī)能聯(lián)網(wǎng),直接輸入命令yum install gcc和yum install gcc-c++;若不能聯(lián)網(wǎng),將centos光盤鏡像掛載上,修改yum的本地源,使機(jī)器從本地源yum方式安裝
3、檢查機(jī)器上是否已經(jīng)安裝了mysql、php、apache,使用命令rpm -qa mysql。若安裝了,則使用命令rpm -e 包的全名 --nodeps卸載
4、關(guān)閉selinux,清空防火墻規(guī)則
5、開放80、3306、22端口
因?yàn)槟J(rèn)情況下,防火墻的80、3306、22端口是關(guān)閉的,這樣的話對于客戶機(jī)訪問虛擬機(jī)上的web,會出現(xiàn)訪問不到的現(xiàn)象。所以要開啟。
service iptables stop
#/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT //那是大寫的英文字母I,不是數(shù)字1
#/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
然后保存:
#/etc/rc.d/init.d/iptables save
重啟防火墻
service iptables restart
6、在linux下建立目錄lamp,存放上傳的源碼
7、使用ssh shell將windows下下載好的14個源碼包上傳到/lamp
8、解包
因?yàn)榘芏啵@里編寫shell腳本/lamp/tar.sh進(jìn)行解包
tar.sh
- #!/bin/sh
- cd /lamp
- ls *.tar.gz > ls.list
-
- for TAR in `cat ls.list`
- do
- tar -zxvf $YAR
- done
執(zhí)行腳本tar.sh進(jìn)行解包
9、將源碼包*.tar.gz全都刪除
三、安裝過程:
1、為方便操作,編寫安裝腳本/lamp/lamp.sh進(jìn)行安裝
lamp.sh
- cd /lamp/libxml2-2.6.30
- ./configure --prefix=/usr/local/libxml2/
- make
- make install
-
- cd /lamp/libmcrypt-2.5.8
- ./configure --prefix=/usr/local/libmcrypt/
- make
- make install
-
- cd /lamp/libmcrypt-2.5.8/libltdl
- ./configure --enable-ltdl-install
- make
- make install
-
- cd /lamp/zlib-1.2.3
- ./configure
- make
- make install
-
- cd /lamp/libpng-1.2.31
- ./configure --prefix=/usr/local/libpng/
- make
- make install
-
- mkdir /usr/local/jpeg6
- mkdir /usr/local/jpeg6/bin
- mkdir /usr/local/jpeg6/lib
- mkdir /usr/local/jpeg6/include
- mkdir -p /usr/local/jpeg6/man/man1
- cd /lamp/jpeg-6b
- ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
- make
- make install
-
- cd /lamp/freetype-2.3.5
- ./configure --prefix=/usr/local/freetype/
- make
- make install
-
- cd /lamp/autoconf-2.61
- ./configure
- make
- make install
-
- cd /lamp/gd-2.0.35
- ./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/
- make
- make install
-
- cd /lamp/httpd-2.2.9
- ./configure --prefix=/usr/local/apache2/ --sysconfdir=/etc/httpd/ --with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
- make
- make install
-
- /usr/local/apache2/bin/apachectl start
- echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit
-
- cd /lamp/ncurses-5.6
- ./configure --with-shared --without-debug --without-ada --enable-overwrite
- make
- make install
-
- groupadd mysql
- useradd -g mysql mysql
- cd /lamp/mysql-5.0.41
- ./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all
- make
- make install
-
- cp support-files/my-medium.cnf /etc/my.cnf
- /usr/local/mysql/bin/mysql_install_db --user=mysql
- chown -R root /usr/local/mysql
- chown -R mysql /usr/local/mysql/var
- chgrp -R mysql /usr/local/mysql
-
- /usr/local/mysql/bin/mysqld_safe --user=mysql &
-
- cp /lamp/mysql-5.0.41/support-files/mysql.server /etc/rc.d/init.d/mysqld
- chown root.root /etc/rc.d/init.d/mysqld
- chmod 755 /etc/rc.d/init.d/mysqld
- chkconfig --add mysqld
- chkconfig --list mysqld
- chkconfig --levels 245 mysqld off
-
- cd /lamp/php-5.2.6
- ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apx --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets
- make
- make install
-
- cp php.ini-dist /usr/local/php/etc/php.ini
- echo "Addtype application/x-httpd-php .php .phtml" >> /etc/httpd/httpd.conf
- /usr/local/apache2/bin/apachectl restart 執(zhí)行腳本,進(jìn)行安裝(時(shí)間很長,可以去睡覺了
)
2、配置mysql
cd /usr/local/mysql
bin/mysqladmin version //簡單的測試
bin/mysqladmin varibles //查看所有mysql參數(shù)
bin/mysql -u root //沒有密碼可以直接登錄本機(jī)服務(wù)器
mysql> DELETE FROM mysql.user WHERE Host='localhost' AND User='';
mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');3、安裝zend加速器
mkdir /usr/local/php/etccp php.ini-dist /usr/local/php/etc/php.ini //更改之前設(shè)定的php.ini的配置文件位置,安裝zend要用
進(jìn)入Zend包的目錄
./install-tty4、phpmyadmin的安裝與配置
cd /lamp
cp -a phpMyAdmin-3.0.0-rc1-all-languages /var/www/html/phpmyadmin //拷貝目錄到指定位置(網(wǎng)站主目錄/var/www/html下)并改名為phpmyadmin
cd /usr/local/apache2/htdocs/phpmyadmin/
cp config.sample.inc.php config.inc.php
進(jìn)入/var/www/html/phpmyadmin
修改配置文件config.inc.php,將$cfg['blowfish_secret'] = '' 空格處填上登錄phpmyadmin的密碼,例如:$cfg['blowfish_secret'] = '123456'
四、常見錯誤及備注:
1、若shell腳本是從windows上傳到linux上,而不是直接在linux上寫的,可能會出現(xiàn)執(zhí)行錯誤。解決辦法見我的另一篇日志:《shell腳本在Linux下運(yùn)行錯誤的解決方法》
2、對不能聯(lián)網(wǎng)狀態(tài)下yum本地安裝的方法,見 《centos虛擬機(jī)不能聯(lián)網(wǎng)狀況下yum方式從本地安裝軟件包》
3、linux啟動apache libltdl.so.3:cannot open shared object file:No such file or directory異常
執(zhí)行ln -s /usr/local/lib/libltdl.so.3 /usr/lib/libltdl.so.3 即可
4、若出現(xiàn)Address already in use: make_sock: could not bind to address [::]:80異常
解決方法:reboot啟動linux
5、若出現(xiàn)在linux終端執(zhí)行clear或者top命令時(shí)出現(xiàn):‘xterm’:unknown terminal type的錯誤,參考《在linux終端執(zhí)行clear或top命令時(shí)出現(xiàn):'xterm': unknown terminal type的錯誤》
6、文中源碼包和tar.sh、lamp.sh腳本的下載 點(diǎn)擊下載 提取碼:dn9qqc4x
7、若有其他錯誤,請百度尋找答案,或者給我發(fā)郵件guoyin0612@163.com