http://www.centos.bz/2011/09/centos-compile-lamp-apache-mysql-php/comment-page-1/#commentsphp
編譯安裝:html
首先卸載掉php mysql httpd yum -y remove httpd yum -y remove php yum -y remove mysql-server mysql yum -y remove php-mysql rpm -e httpd rpm -e mysql rpm -e php
先用yum 安裝所須要的環境包:mysql
yum -y install gcc gcc-c++ make automake autoconf kernel-devel ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel pcre-devel libtool-libs freetype-devel gd zlib-devel file bison patch mlocate flex diffutils readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel
下載lamp環境的源碼包:linux
wget http://212.199.163.181/services/all/phpMyAdmin/phpMyAdmin-3.4.10.2-all-languages.tar.gz wget http://mirrors.sohu.com/php/php-5.2.17.tar.gz wget http://mysql.ntu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.62.tar.gz wget http://archive.apache.org/dist/httpd/httpd-2.2.22.tar.gz
解壓:c++
tar zxvf php-5.2.17.tar.gz tar zxvf httpd-2.2.22.tar.gz tar zxvf mysql-5.1.62.tar.gz
安裝httpd:es6
cd httpd-2.2.22/sql
./configure --prefix=/usr/local/apache --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-headers=shared --enable-rewrite=shared --enable-static-support
make
make install
編譯參數介紹:數據庫
--prefix=/usr/local/apache:指定安裝目錄 --with-included-apr:在編譯時強制使用當前源代碼中綁定的APR版本 --enable-so:容許運行時加載DSO模塊 --enable-deflate=shared:將deflate模塊編譯爲DSO --enable-expires=shared:將expires模塊編譯爲DSO --enable-headers=shared:將headers模塊編譯爲DSO --enable-rewrite=shared:將rewrite模塊編譯爲DSO --enable-static-support:使用靜態鏈接(默認爲動態鏈接)編譯全部二進制支持程序 更詳細的編譯參數解釋:http://lamp.linux.gov.cn/Apache/ApacheMenu/programs/configure.html
複製啓動腳本:開機自啓動apache
cp build/rpm/httpd.init /etc/init.d/httpd //使用init腳本管理httpd chmod 755 /etc/init.d/httpd //增長執行權限 chkconfig --add httpd //添加httpd到服務項 chkconfig httpd on //設置開機啓動 ln -fs /usr/local/apache/ /etc/httpd ln -fs /usr/local/apache/bin/httpd /usr/sbin/httpd ln -fs /usr/local/apache/bin/apachectl /usr/sbin/apachectl ln -fs /usr/local/apache/logs /var/log/httpd //設置軟連接以適應init腳本
安裝mysql:json
groupadd mysql useradd -g mysql mysql cd /usr/local/src/mysql-5.1.62 ##進入解壓後的源碼目錄 ./configure --prefix=/usr/local/mysql/ --localstatedir=/usr/local/mysql/data --without-debug --with-unix-socket-path=/tmp/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=gbk,gb2312,utf8 --with-pthread make make install
PS:與到一個錯誤
gcc: all-static: No such file or directory make[4]: *** [replace] 錯誤 1 make[4]: Leaving directory `/tmp/LAMP/mysql-5.0.56/extra' make[3]: *** [all-recursive] 錯誤 1 make[3]: Leaving directory `/tmp/LAMP/mysql-5.0.56/extra' make[2]: *** [all] 錯誤 2 make[2]: Leaving directory `/tmp/LAMP/mysql-5.0.56/extra' make[1]: *** [all-recursive] 錯誤 1 make[1]: Leaving directory `/tmp/LAMP/mysql-5.0.56' make: *** [all] 錯誤 2
問題解決:http://www.wumingx.cn/post/324.html
http://hi.baidu.com/lzdpntspocegjtr/item/c8560de9f9fd0bf82a09a4b1
編譯參數解釋:
--prefix=/usr/local/mysql/:指定安裝位置 --localstatedir=/usr/local/mysql/data:指定數據庫文件位置 --without-debug:禁用調用模式 --with-unix-socket-path=/tmp/mysql.sock:指定sock文件位置 --with-client-ldflags=-all-static: --with-mysqld-ldflags=-all-static:以純靜態方式編譯服務端和客戶端 --enable-assembler:使用一些字符函數的彙編版本 --with-extra-charsets=gbk,gb2312,utf8 :gbk,gb2312,utf8字符支持 --with-pthread:強制使用pthread庫(posix線程庫)
更多編譯參數請執行./configure --help命令查看
mysql的後續配置:
cp support-files/my-medium.cnf /etc/my.cnf //複製配置文件夾my.cnf /usr/local/mysql/bin/mysql_install_db --user=mysql //初始化數據庫 chown -R root.mysql /usr/local/mysql chown -R mysql /usr/local/mysql/data cp /tmp/mysql-5.1.62/support-files/mysql.server /etc/rc.d/init.d/mysqld //init啓動腳本 chown root.root /etc/rc.d/init.d/mysqld chmod 755 /etc/rc.d/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on ln -s /usr/local/mysql/bin/mysql /usr/bin ln -s /usr/local/mysql/bin/mysqladmin /usr/bin service mysqld start
PS:給root用戶設置遠程訪問和密碼
grant all on *.* to root@'%' identified by 'morohstk22';
grant all on *.* to root@localhost identified by 'morohstk22'
*.* 前面的*爲你要訪問的數據庫名 例如要訪問1db將*修改成1db *爲全部
root@'%'爲root用戶能夠以任何ip訪問 'morohstk22' 爲root用戶的mysql數據庫密碼 不是系統密碼
安裝php:
首先安裝幾個PHP的依賴包:若是你用的是centos5能夠跳過此步驟 若是是centOS6 或者是RHEL6(其實同樣的CentOS就是RHEL的克隆版)
libmcrypt-2.5.8.tar.gz mhash-0.9.9.9.tar.gz mcrypt-2.6.8.tar.gz libiconv-1.14.tar.gz 固然這些均可以在Google上找到下載的ftp服務器。這裏貼幾個但不必定能下載到。下載不到的Google下包的名字就能夠找到。 wget http://superb-dca2.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz wget http://superb-dca2.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz wget http://superb-sea2.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
而後解壓:
能夠編輯一個腳本
vim /usr/local/src/lamp/tar.sh #!/bin/sh cd /usr/local/src/lamp/ ls *.tar.gz > ls.list for TAR in `cat ls.list` do tar -zxvf $TAR done
解壓 完成後:進入安裝:
cd libmcrypt-2.5.8 ./configure --prefix=/usr make && make install cd ../mhash-0.9.9.9 ./configure --prefix=/usr make && make install cd ../mcrypt-2.6.8 ./configure make && make install cd ../libiconv-1.14 ./configure --prefix=/usr/local/libiconv make && make install
OK安裝完成後進入php的配置。相關加載模塊參考PHP手冊 或者 --help 查看./confugure --help查看相關參數和支持。固然編譯安裝後也可動態加載模塊
cd ../php-5.2.17 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --enable-bcmath --with-bz2 --with-curl --enable-ftp --with-gd --enable-gd-native-ttf --with-gettext --with-mhash --enable-mbstring --with-mcrypt --enable-soap --enable-zip --with-iconv=/usr/local/libiconv --with-mysql=/usr/local/mysql --without-pear make make test ##這一步若是有時間能夠運行 沒時間能夠忽略 make install
編譯參數解釋:
--prefix=/usr/local/php:設置安裝路徑
--with-apxs2=/usr/local/apache/bin/apxs:編譯共享的 Apache 2.0 模塊
--with-config-file-path=/etc:指定配置文件php.ini地址
--with-config-file-scan-dir=/etc/php.d:指定額外的ini文件目錄
--with-openssl:編譯OpenSSL支持
--with-zlib:編譯zlib支持
--enable-bcmath:啓用BC風格精度數學函數
--with-bz2:BZip2支持
--with-curl:CRUL支持
--enable-ftp:FTP支持
--with-gd:GD支持
--enable-gd-native-ttf:啓用TrueType字符串函數
--with-gettext:啓用GNU gettext支持
--with-mhash:mhash支持
--enable-mbstring:啓用支持多字節字符串
--with-mcrypt:編譯mcrypt加密支持
--enable-soap:SOAP支持
--enable-zip:啓用zip 讀/寫支持
--with-iconv=/usr/local/libiconv:iconv支持
--with-mysql=/usr/local/mysql:啓用mysql支持
--without-pear:不安裝PEAR
更多編譯參數解釋參考http://www.php.net/manual/zh/configure.about.php或者./configure --help查看
http://www.cnblogs.com/foundwant/p/3179295.html
make報錯:"usr/bin/ld: cannot find -l*** 在Linux編譯程序時,有的程序會報錯以下: #gmake -f dc_debug.mak ....... /usr/bin/ld: cannot find -ldscompress_x32 collect2: ld returned 1 exit status gmake: *** [dc_shl2_v2.0.0_130423_b1_x32.exe] Error 1 問題緣由: 該問題的緣由通常是因爲ld 在進行庫鏈接時找不到庫文件所致; 解決方案: 出現該問題時,去lib目錄下查找相關的庫文件,基本以下: #cd /usr/lib #ll | grep libltdl lrwxrwxrwx 1 root root 16 Dec 13 2012 libltdl.so.3 -> libltdl.so.3.1.4 -rwxr-xr-x 1 root root 24004 Nov 23 2009 libltdl.so.3.1.4 上述庫文件中沒有庫的入口:libltdl.so 能夠手動創建一個鏈接來解決 #ln -s ./libltdl.so.3 ./libltdl.so 可是深究問題,應該是該庫的頭文件庫沒有安裝所致: #yum list all | grep ltdl libtool-ltdl.i386 1.5.22-7.el5_4 installed libtool-ltdl-devel.i386 1.5.22-7.el5_4 server 下面就安裝頭文件: #yum -y install libtool-ltdl-devel.i386 。。。 查看後發現確實是因爲devel頭文件沒有安裝所致 # rpm -ql libtool-ltdl-devel.i386 /usr/include/ltdl.h /usr/lib/libltdl.a /usr/lib/libltdl.la /usr/lib/libltdl.so
PHP安裝後配置:
cp php.ini-dist /usr/local/php/etc/php.ini //複製配置文件php.ini 在/etc/httpd/conf/httpd.conf文件中加入php文件類型解析: Addtype application/x-httpd-php .php 重啓Apache 和mysql /usr/local/apache/bin/apachectl restart service mysqld restart
OK下面網站基本配置完成 (如下爲可選安裝)
PHP加載動態模塊:
例如我在編譯安裝PHP時沒有開啓FTP能夠以下操做:
[root@vbok ~]# cd /usr/local/src/php-5.2.17 [root@vbok php-5.2.17]# find . -name ftp ./ext/ftp [root@vbok php-5.2.17]# cd ext/ftp [root@vbok ftp]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519 [root@vbok ftp]# ./configure --with-php=config=/usr/local/php/bin/php-config --enable-ftp ##或者:去掉 --enable-ftp [root@vbok ftp]# ./configure --with-php=config=/usr/local/php/bin/php-config [root@vbok ftp]#make [root@vbok ftp]#make install ##生成一個路徑內有一個ftp.so的文件 /usr/local/php/lib/php/extensions/no-debug-non-zts-2006 0613/ftp.so 而後編輯php.ini文件 [root@vbok ftp]#vim /usr/local/php/etc/php.ini extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-2006 0613/" extension = ftp.so 保存退出 而後重啓apache
驗證ftp是否開啓:
方法1.站點下建立 phpinfo()函數調用php配置文件查看不過分介紹
方法2.
[root@166 ~]# /usr/local/php/bin/php php php-config phpize [root@166 ~]# /usr/local/php/bin/php -m PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/openssl.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/openssl.so: cannot open shared object file: No such file or directory in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/php_gd2.dll' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/php_gd2.dll: cannot open shared object file: No such file or directory in Unknown on line 0 [PHP Modules] bcmath bz2 ctype curl date dom filter ftp gd gettext hash iconv json libxml mbstring mcrypt mhash mysql mysqli pcre PDO pdo_sqlite posix Reflection session SimpleXML soap sockets SPL SQLite standard tokenizer xml xmlreader xmlwriter Zend Optimizer zip zlib [Zend Modules] Zend Extension Manager Zend Optimizer [root@166 ~]#
OK ftp 加載成功
再次驗證 cat /www/phpinfo.php
<?php
phpinfo();
?>
wget http://files6.directadmin.com/services/custombuild/ZendOptimizer-3.2.6-linux-glibc23-x86_64.tar.gz wget http://files6.directadmin.com/services/custombuild/ZendOptimizer-3.2.6-linux-glibc21-i386.tar.gz
解壓安裝:
cd /usr/local/src/ZendOptimizer-3.2.6-linux-glibc23-x86_64/ sh install.sh
一下安裝來至網絡:(由於寫文檔時我已經搭建完成這個是整理檔案)