- 論壇徽章:
- 0
|
廣州文豆PHP
服務器篇--之 LAMP安裝手記
Server OS: Cent OS
Apache: http-2.2.11
PHP:PHP-5.2.9
Mysql: 5.1.32
GD: gd-2.0.35
JPEG:jpeg-6b
libpng:libpng-1.2.35
libxml2:libxml2-2.6.19
freetype:freetype-2.3.9
ZendOptimizer:ZendOptimizer-3.3.0a-linux-glibc21-i386
記得安裝Linux的時候不要安裝系統(tǒng)默認的apache,mysql和php以及相關的軟件。已經(jīng)安裝的請用rpm -e * 刪除已經(jīng)安裝的包。
一,安裝apache2
(這里我把軟件包都放/root下了)
# cd /root
進入目錄/root
# tar -zvxf httpd-2.2.11.tar.gz
解壓httpd-2.2.11.tar.gz
# cd httpd-2.2.11
進入httpd-2.2.11目錄
# mkdir -p /usr/local/apache2
生成/usr/local/apache2目錄
# ./configure --prefix=/usr/local/apache2
或者
# ./configure --prefix=/usr/local/apache --enable-modules=so --enable-rewrite
配置是否支持重寫
# make
編譯
# make install
安裝apache
# vi /usr/local/apache2/conf/httpd.conf
設置DocumentRoot 的路徑
保存退出,現(xiàn)在就這么簡單配置apache。
# /usr/local/apache2/bin/apachectl -k start
啟動apahce
用瀏覽器查看
http://www.wengdo.com
(這里寫你自己網(wǎng)站,如
http://localhost/
),得到It works,說明apache已經(jīng)配置成功了。
# /usr/local/apache2/bin/apachectl -k stop
停止apache
# /usr/local/apache/bin/apachectl restart
重啟Apache
把httpd 添加到系統(tǒng)的啟動項里
# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
# chmod 700 /etc/rc.d/init.d/httpd
# vi /etc/rc.d/init.d/httpd
在第三行后增加
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 90 90
# description:http server
注意:沒有這幾行,在使用chkconfig時會提示你:service httpd does not support chkconfig。
chkconfig –add httpd
chkconfig –level 345 httpd on
這樣,在運行級別345上httpd就可以自動啟動了。
二,Mysql的安裝
# cd /root
# tar -zvxf mysql-5.1.32-linux-i686-glibc23.tar.gz
# mkdir -p /usr/local/mysql (省略也可)
# cp -r mysql-5.1.32-linux-i686-glibc23/* /usr/local/mysql
# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
添加mysql用戶及用戶組
# groupadd mysql
# useradd -g mysql mysql
修改mysql目錄權限
# chown -R root /usr/local/mysql
# chgrp -R mysql /usr/local/mysql
# chown -R mysql /usr/local/mysql/data
生成mysql系統(tǒng)數(shù)據(jù)庫
# /usr/local/mysql/scripts/mysql_install_db --user=mysql&
啟動mysql服務
# /usr/local/mysql/bin/mysqld_safe --user=mysql&
如出現(xiàn) Starting mysqld daemon with databases from /usr/local/mysql/data
代表正常啟動mysql服務了, 按Ctrl + C 跳出
修改 mysql 的 root 密碼
# /usr/local/mysql/bin/mysqladmin -u root -p password "wengdo"
wengdo 這里可以換為你自己的密碼
把你編譯目錄的一個腳本COPY過去
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
用ntsysv設置使mysql每次啟動都能自動運行。
好了,至此mysql安裝完畢,你可以這樣起動你的mysql服務
# /etc/rc.d/init.d/mysqld start
下面這步比較關鍵,
# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
大家可以不做這步,大可以在編譯其他軟件的時候自定義myslq的庫文件路徑,但我還是喜歡把庫文件鏈接到默認的位置,這樣你在編譯類似PHP,Vpopmail等軟件時可以不用指定mysql的庫文件地址。
三,安裝GD庫 (如果你用系統(tǒng)自帶的GD庫,可以省略這一步)
建立目錄:
# mkdir -p /usr/local/jpeg6
# mkdir -p /usr/local/jpeg6/bin
# mkdir -p /usr/local/jpeg6/lib
# mkdir -p /usr/local/jpeg6/include
# mkdir -p /usr/local/jpeg6/man
# mkdir -p /usr/local/jpeg6/man1
# mkdir -p /usr/local/jpeg6/man/man1
# cd /root
# tar -zvxf jpegsrc.v6b.tar.gz
# cd jpeg-6b
# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
# make
# make install
- 安裝libpng
# cd /root
# tar -zvxf libpng-1.2.35.tar.gz
# cd libpng-1.2.35
# cp scripts/makefile.std makefile
# make
# make install
- 安裝 freetype
# cd /root
# tar -zvxf freetype-2.3.9.tar.gz
# cd freetype-2.3.9
# mkdir -p /usr/local/freetype
# ./configure --prefix=/usr/local/freetype
# make
# make install
# cd /root
# tar -zvxf gd-2.0.35.tar.gz
# mkdir -p /usr/local/gd2
# cd gd-2.0.35
# ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6/ --with-png=/usr/local/lib/ --with-zlib=/usr/local/lib/ --with-freetype=/usr/local/freetype/ --enable-m4_pattern_allow
# make
# make install
四,安裝PHP5
php5必須有l(wèi)ibxml2支持!
安裝libxml2
# cd /root
# tar -zxvf libxml2-2.6.19.tar.gz
# cd libxml2-2.6.19
# mkdir -p /usr/local/libxml2
# ./configure --prefix=/usr/local/libxml2
# make
# make install
安裝php5
# cd /root
# tar -zvxf php-5.2.9.tar.gz
# mkdir -p /usr/local/php
# cd php-5.2.9
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
--with-mysql=/usr/local/mysql/
--with-curl=/usr/local/curl --enable-ftp
--with-libxml-dir=/usr/local/libxml2
--with-expat-dir=/usr/lib --enable-soap
--with-xsl=/usr/local/libxslt --enable-xslt
--with-gd=/usr/local/gd2/
--with-jpeg-dir=/usr/local/jpeg6/
--with-zlib-dir=/usr/local/lib/
--with-png=/usr/local/lib/
--with-freetype-dir=/usr/local/freetype/
# make
# make install
# cp php.ini-dist /usr/local/php/lib/php.ini (別忘記了)
其中./configure 后的
--prefix=/usr/local/php
--with-apxs2=/usr/local/apache2/bin/apxs
--with-mysql=/usr/local/mysql/
--with-libxml-dir=/usr/local/libxml2
是必要的選項
--with-gd=/usr/local/gd2/
--with-jpeg-dir=/usr/local/jpeg6/
--with-png=/usr/local/lib
--with-zlib-dir=/usr/lib
--with-freetype-dir=/usr/local/freetype
這是讓PHP支持GD庫的配置選項
--with-curl=/usr/local/curl 支持CURL庫
--enable-ftp 打開FTP庫函數(shù)支持
--enable-soap --with-xsl=/usr/local/libxslt --enable-xslt
讓PHP支持SOAP, 上面這些一般用得少, 可以去掉
如果服務器自帶 GD庫及其相關的庫,可以用下面這個方式去配置PHP
# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-freetype-dir=/usr --with-png-dir=/usr --with-gd --enable-gd-native-ttf --with-ttf --with-gdbm --with-gettext --with-iconv --with-jpeg-dir=/usr --with-png --with-zlib --with-xml --enable-calendar --with-apxs=/usr/local/apache2/bin/apxs
五,安裝 ZendOptimizer
# cd /root
# tar -zxvf ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gz
# cd ZendOptimizer-3.3.0a-linux-glibc21-i386
# ./install.sh
然后出現(xiàn)圖形界面,按提示Next
六,配置一些信息
配置 httpd.conf 讓apache支持PHP
# vi /usr/local/apache2/conf/httpd.conf
找到 AddType application/x-gzip .gz .tgz 在其下添加如下內(nèi)容
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
重啟apache
# /usr/local/apache2/bin/apachectl restart
在你設置的目錄里建一內(nèi)容為 PHP文件, 輸入URL地址查看PHP配置是否正確
安裝時可能會出現(xiàn)的一些問題
編譯最新的GD庫2.0.35版本,用默認的 ./configure編譯
當make的時候,出現(xiàn)以下錯誤
configure.ac:64: error: possibly undefined macro: AM_ICONV
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
make: *** [configure] Error 1
解決方法:
編譯加m4_pattern_allow參數(shù),上面已添加
# ./configure --enable-m4_pattern_allow
數(shù)據(jù)庫可能會出現(xiàn)這樣的錯誤
"Can't connect to local MySQL server through socket '/tmp/mysql.sock'"
檢查是否存在那個socket文件,可以在/etc/my.cnf 中指定 socket = /tmp/mysql.sock
使用.mysqld_safe --socket=/tmp/mysql.sock & 啟動mysql進程,
有時pam_mysql使用/var/lib/mysql/mysql.sock
所以做個連接 ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
或者是修改/etc/my.cnf
有可能是權限問題,看看mysql的錯誤日志,一步一步調(diào)整
重啟Apache出錯
重新啟動apache報如下錯誤:
httpd: Syntax error on line 53 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
原因:是Linux有一個SELinux保護模式引起的。
解決辦法:
1關閉SELINUX的方法:
# vi /etc/selinux/config
將SELINUX=enforcing 改成SELINUX=disabled 需要重啟
這個方法可能會對服務器帶來風險。
2不關閉SELINUX的方法:
# setenforce 0
# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache2/modules/libphp5.so
# service httpd restart
# setenforce 1
PHP 在Make 或者Make install的時候出錯,報錯信息:
Installing PEAR environment: /usr/local/lib/php/
/usr/local/php-5.2.5/sapi/cli/php: error while loading shared libraries: /usr/local/gd2/lib/libgd.so.2: cannot restore segment prot after reloc: Permission denied
make[1]: *** [install-pear-installer] Error 127
make: *** [install-pear] Error 2
安裝出錯,這時候輸入 tail /var/log/messages 查看錯誤日志
# tail /var/log/messages
...
Mar 3 06:40:46 localhost setroubleshoot: SELinux is preventing /usr/local/php-5.2.5/sapi/cli/php from loading /usr/local/gd2/lib/libgd.so.2.0.0 which requires text relocation. For complete SELinux messages. run sealert -l 6e29749f-3908-480d-bcc1-9042f8a9e846
你可以找到 run sealert -l 6e29749f-3908-480d-bcc1-9042f8a9e846,執(zhí)行它
# sealert -l 6e29749f-3908-480d-bcc1-9042f8a9e846
...
The following command will allow this access:
chcon -t textrel_shlib_t /usr/local/gd2/lib/libgd.so.2.0.0
找到 following command chcon -t textrel_shlib_t /usr/local/gd2/lib/libgd.so.2.0.0
# chcon -t textrel_shlib_t /usr/local/gd2/lib/libgd.so.2.0.0
再次運行make install 或make
忘了mysql的root口令怎么辦
# /usr/local/mysql/support-files/mysql.server stop
# mysqld_safe --skip-grant-tables &
# mysqladmin -u user password 'newpassword'
# mysqladmin flush-privileges
本文出處:
http://www.wengdo.com/lnmp-lamp/php-news-38.html
本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u/14986/showart_2182255.html |
|