源碼編譯安裝LAMP雖然過程繁瑣,但能夠根據本身PHP程序的須要配置相應的環境,很是的靈活。對於比較急於配置好LAMP的同窗,能夠使用lamp一鍵安裝。 php
卸載yum或rpm安裝的amp軟件
在編譯安裝lamp以前,首先先卸載已存在的rpm包吧。 html
- rpm -e httpd
- rpm -e mysql
- rpm -e php
- yum -y remove httpd
- yum -y remove php
- yum -y remove mysql-server mysql
- yum -y remove php-mysql
禁用SeLinux
selinux可能會導致編譯安裝失敗,咱們先禁用它。 mysql
- sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config //永久禁用,須要重啓生效
- setenforce 0 //臨時禁用,不須要重啓
yum安裝必要工具
一、安裝編譯工具gcc gcc-c++make automake autoconf kernel-devel
二、安裝PHP所需依賴,如libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel等 linux
- 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
下載所需源碼
apache:http://httpd.apache.org/
mysql:http://mysql.com/downloads/mysql/
php:http://php.net/downloads.php
phpmyadmin:http://www.phpmyadmin.net/home_page/downloads.php
咱們這裏選擇的版本爲:apache-2.2.22,mysql-5.1.62,php-5.2.17,phpmyadmin-3.4.10.2 nginx
或者這裏下 c++
mkdir -p /data0/software
cd /data0/software
wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.14-fpm-0.5.14.diff.gz
wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wget http://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz
- cd /tmp
- wget -c http://apache.ziply.com//httpd/httpd-2.2.22.tar.gz
- wget -c http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.64.tar.gz/from/http://mysql.he.net/
- wget -c http://us2.php.net/get/php-5.2.17.tar.gz/from/am.php.net/mirror
- wget -c http://iweb.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.4.10.2/phpMyAdmin-3.4.10.2-all-languages.tar.gz
- tar xzf httpd-2.2.22.tar.gz
- tar xzf mysql-5.1.62.tar.gz
- tar xzf php-5.2.17.tar.gz
- tar xzf phpMyAdmin-3.4.10.2-all-languages.tar.gz
安裝apache2.2.22
- cd /tmp/httpd-2.2.22
- ./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 web
- 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腳本
安裝mysql5.1.62
- groupadd mysql
- useradd -g mysql mysql
- cd /tmp/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
編譯參數解釋:
–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命令查看。 sql
- 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
- /usr/local/mysql/bin/mysqladmin -u root password '新密碼' //設置root密碼
安裝PHP5.2.17
在編譯php以前,先要解決兩個問題:centos 6上libmcrypt的安裝和可能有些系統找不到libiconv致使的錯誤。
一、centos 6官方源已經沒有libmcrypt的rpm包,咱們這裏選擇編譯安裝,固然你也能夠導入第三方源安裝(centos 5略過此步)。
下載源碼: shell
- cd /tmp
- 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
- tar xzf libmcrypt-2.5.8.tar.gz
- tar xzf mhash-0.9.9.9.tar.gz
- tar xzf mcrypt-2.6.8.tar.gz
- //安裝libmcrypt
- cd /tmp/libmcrypt-2.5.8
- ./configure --prefix=/usr
- make && make install
- //安裝libmcrypt
- cd /tmp/mhash-0.9.9.9
- ./configure --prefix=/usr
- make && make install
- //安裝mcrypt
- /sbin/ldconfig //搜索出可共享的動態連接庫
- cd /tmp/mcrypt-2.6.8
- ./configure
- make && make install
二、解決可能出現的libiconv錯誤。 數據庫
- cd /tmp
- wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
- tar xzf libiconv-1.14.tar.gz
- cd libiconv-1.14
- ./configure --prefix=/usr/local/libiconv
- make && make install
開始安裝php-5.2.17:
- cd /tmp/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 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查看。
- cp php.ini-dist /usr/local/php/etc/php.ini //複製配置文件php.ini
在/etc/httpd/conf/httpd.conf文件中加入php文件類型解析:
- Addtype application/x-httpd-php .php
重啓httpd:
安裝ZendOptimizer-3.3.9(可選)
ZendOptimizer的做用是分析,優化由Zend 編譯器加密產生的代碼的程序,對不是Zend編譯器加密過的程序,沒有必要安裝這個。
64位:http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
32位:http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
- cd /tmp
- wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
- tar xzf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
- cd /tmp/ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/
- mkdir -p /usr/local/Zend/lib/
- cp ZendOptimizer.so /usr/local/Zend/lib
加載zendoptimizer,創建/etc/php.d/zend.ini文件,加入以下代碼加載:
- [zend]
- zend_optimizer.optimization_level=15
- zend_extension=/usr/local/Zend/lib/ZendOptimizer.so
重啓httpd生效:
安裝eAccelerator-0.9.6.1(可選)
eAccelerator是一個自由開放源碼php加速器,優化和動態內容緩存,提升了php腳本的緩存性能,使得PHP腳本在編譯的狀態下,對服 務器的開銷幾乎徹底消除。 它還有對腳本起優化做用,以加快其執行效率。使您的PHP程序代碼執效率能提升1-10倍。相似的php加速器有:Xcache,APC等。下面是安裝方 法:
- cd /tmp
- wget http://voxel.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.zip
- unzip eaccelerator-0.9.6.1.zip
- cd eaccelerator-0.9.6.1
- export PHP_PREFIX="/usr/local/php"
- $PHP_PREFIX/bin/phpize
- ./configure -enable-eaccelerator=shared -with-php-config=$PHP_PREFIX/bin/php-config
- make && make install
- cd /tmp
- mkdir eaccelerator
- chmod 0777 eaccelerator
加載eAccelerator,建立/ec/php.d/ea.ini文件,加入以下代碼加載:
- [eaccelerator]
- zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
- eaccelerator.shm_size="32"
- eaccelerator.cache_dir="/tmp/eaccelerator"
- eaccelerator.enable="1"
- eaccelerator.optimizer="1"
- eaccelerator.check_mtime="1"
- eaccelerator.debug="0"
- eaccelerator.filter=""
- eaccelerator.shm_max="0"
- eaccelerator.shm_ttl="0"
- eaccelerator.shm_prune_period="0"
- eaccelerator.shm_only="0"
- eaccelerator.compress="1"
- eaccelerator.compress_level="9"
eaccelerator參數設置參考:http://www.centos.bz/2012/03/eaccelerator-parameter/
重啓httpd生效: