您好,登錄后才能下訂單哦!
源碼包:
httpd-2.4.9 | Apache2.4.9編譯安裝包 |
apr-1.5.1 | Apache可移植運行庫 |
apr-util-1.5.3 | Apache可移植運行庫工具 |
php-5.5.30 | PHP源碼包 |
mysql-5.5.47 | 通用二進制版( Generic) |
一、PHP作為模塊編譯LAMP:
注: 1、由于PHP作為Apache的模塊,所以編譯PHP的時候,需要在httpd之后。 2、這里為了支持apache的worker或event這兩個MPM,編譯時使用了--enable-maintainer-zts選項。 3、PHP連接MySQL數據庫需要mysql客戶端的開發組件支持,不過:如果使用PHP5.3以上版本,為了鏈接MySQL數據庫,可以指定mysqlnd,這樣在本機就不需要先安裝MySQL或MySQL開發包了。mysqlnd從php 5.3開始可用,可以編譯時綁定到它(而不用和具體的MySQL客戶端庫綁定形成依賴),但從PHP 5.4開始它就是默認設置了。 # ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd |
1.編譯apr-1.5.1:
[root@localhost ~]# yum install -y pcre-devel #安裝perl正則表達式的依賴包 [root@localhost ~]# cd lamp/ [root@localhost lamp]# tar xf apr-1.5.1.tar.gz [root@localhost lamp]# cd apr-1.5.1 [root@localhost apr-1.5.1]# ./configure --prefix=/usr/local/apr && make && make install
2.編譯apr-util-1.5.3:
[root@localhost lamp]# tar xf apr-util-1.5.3.tar.bz2 [root@localhost lamp]# cd apr-util-1.5.3 [root@localhost apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ && make && make install
3.編譯httpd-2.4.9:
[root@localhost lamp]# tar xf httpd-2.4.9.tar.gz [root@localhost lamp]# cd httpd-2.4.9 [root@localhost httpd-2.4.9]# ./configure --prefix=/usr/local/httpd-2.4.9 \ #指定安裝目錄 > --sysconfdir=/etc/httpd \ #配置文件目錄 > --enable-modules=most \ #編譯進大多數常用模塊 > --enable-mods-shared=most \ #將常用模塊編譯為動態模塊,shared > --enable-so \ #使Apache支持動態加載模塊 > --enable-ssl \ #支持ssl > --enable-mpms-shared=all \ #將所有支持的MPM模塊編譯為動態模塊 > --with-apr=/usr/local/apr \ #指定apr所在位置 > --with-apr-util=/usr/local/apr-util \ #指定apr-util位置 > --with-mpm=event \ #指定默認MPM為event > --enable-proxy \ #開啟代理模塊 > --enable-proxy-fcgi \ #開啟fcgi模塊,需要一并開啟--enable-proxy選項 > --enable-deflate \ #支持壓縮 > make && make install #安裝 #############安裝完成后,還需要對運行環境做些配置################ 將目錄鏈接為httpd: [root@localhost ~]# ln -sv /usr/local/httpd-2.4.9 /usr/local/httpd 添加命令搜索路徑文件: [root@localhost ~]# vim /etc/profile.d/httpd.sh 1.添加一行:export PATH=/usr/local/httpd/bin:$PATH 加載環境變量文件: [root@localhost ~]# source /etc/profile.d/httpd.sh 導出頭文件 [root@localhost ~]# ln -sv /usr/local/httpd/include/ /usr/include/httpd `/usr/include/httpd' -> `/usr/local/httpd/include/' 編輯man文檔目錄: [root@localhost ~]# vim /etc/man.config 1.添加一行:MANPATH /usr/local/httpd/man
4.測試是否可以成功啟動:
測試啟動并查看是否監聽在80端口: [root@localhost ~]# httpd -k start AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'ServerName' directive globally to suppress this message [root@localhost ~]# ss -tnl|grep 80 LISTEN 0 128 :::80 :::* [root@localhost ~]#
5.解壓mysql:
[root@localhost lamp]# tar xf mysql-5.5.47-linux2.6-x86_64.tar.gz -C /usr/local/ #############安裝完成后,還需要對運行環境做些配置################ 創建用戶和組: [root@localhost lamp]# groupadd -r mysql [root@localhost lamp]# useradd -r -g mysql mysql 將mysql-5.5.47目錄鏈接為mysql: [root@localhost lamp]# ln -sv /usr/local/mysql-5.5.47-linux2.6-x86_64/ /usr/local/mysql `/usr/local/mysql' -> `/usr/local/mysql-5.5.47-linux2.6-x86_64/' 提供命令搜索路徑: [root@localhost lamp]# vim /etc/profile.d/mysql.sh 1.添加一行:export PATH=/usr/local/mysql/bin:$PATH 加載環境文件: [root@localhost lamp]# source /etc/profile.d/mysql.sh 鏈接頭文件: [root@localhost lamp]# ln -sv /usr/local/mysql/include/ /usr/include/mysql `/usr/include/mysql/include' -> `/usr/local/mysql/include/' 導出庫文件: [root@localhost lamp]# vim /etc/ld.so.conf.d/mysql.conf 1.添加一行:/usr/local/mysql/lib 重新加載庫文件: [root@localhost lamp]# ldconfig
6.配置、初始化并啟動MySQL:
為目錄添加權限: [root@localhost ~]# cd /usr/local/mysql [root@localhost mysql]# chown -R root.mysql . 創建數據目錄: [root@localhost mysql]# mkdir /data [root@localhost mysql]# chown -R mysql.mysql /data 初始化mysql: [root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data 初始化 查看數據目錄是否有文件,如果有就證明初始化成功: [root@localhost mysql]# ls /data/ mysql mysql-bin.000001 mysql-bin.000002 mysql-bin.index performance_schema test 提供啟動腳本: [root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@localhost mysql]# chkconfig --add mysqld [root@localhost mysql]# chkconfig mysqld on 提供配置文件并配置: [root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf [root@localhost mysql]# vim /etc/my.cnf 1.在[mysqld]范圍中添加一行:datadir = /data 啟動mysql測試: [root@localhost mysql]# service mysqld start Starting MySQL... [ OK ] [root@localhost mysql]# [root@localhost mysql]# ss -tnl|grep 3306 LISTEN 0 50 *:3306 *:*
7.編譯php-5.5.30:
[root@localhost lamp]# yum install -y openssl-devel bzip2-devel libmcrypt-devel [root@localhost lamp]# cd php-5.5.30 [root@localhost php-5.5.30]./configure --prefix=/usr/local/php-5.5.30 \ #指定安裝目錄 > --with-mysql=/usr/local/mysql \ #指定MySQL安裝目錄 > --with-openssl \ #使用openssl庫,需要安裝openssl-devel包 > --with-mysqli=/usr/local/mysql/bin/mysql_config \ #指定mysql_config > --enable-mbstring \ #開啟多字符串支持 > --with-freetype-dir \ > --with-jpeg-dir \ #支持jpeg > --with-png-dir \ #支持png > --with-zlib \ #指定zlib > --with-libxml-dir=/usr \ #指定libxml庫 > --enable-xml \ #開啟xml > --enable-sockets \ #開啟套接字方式支持 > --with-apxs2=/usr/local/apache/bin/apxs \ #apxs是Apache的模塊支持庫,要想編譯為Apache模塊,依賴于apxs > --with-mcrypt \ #指定加密庫,需要libmcrypt-devel包 > --with-config-file-path=/etc \ #指定配置文件所在目錄 > --with-config-file-scan-dir=/etc/php.d \ #指定附加目錄 > --with-bz2 \ #指定bz2壓縮庫,需要bzip2-devel > --enable-maintainer-zts #支持apache的worker或event這兩個MPM #############安裝完成后,還需要對運行環境做些配置################ 連接目錄: [root@localhost lamp]# ln -sv /usr/local/php-5.5.30/ /usr/local/php `/usr/local/php' -> `/usr/local/php-5.5.30/ 導出頭文件: [root@localhost lamp]# ln -sv /usr/local/php-5.5.30/include/ /usr/include/php `/usr/include/php' -> `/usr/local/php-5.5.30/include/' 添加命令搜索路徑文件: [root@localhost lamp]# vim /etc/profile.d/php.sh 1.添加一行:export PATH=/usr/local/php/bin:$PATH 讀取到環境變量: [root@localhost lamp]# source /etc/profile.d/php.sh 導出庫文件: [root@localhost lamp]# vim /etc/ld.so.conf.d/php.conf 1.添加一行:/usr/local/php/lib 重新加載庫文件: [root@localhost lamp]# ldconfig
8.在httpd配置文件(/etc/httpd/httpd.conf)中添加如下兩行并將DirectoryIndex修改為index.php:
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps <IfModule dir_module> DirectoryIndex index.php </IfModule>
9.重新啟動httpd服務并查看是否加載php模塊:
[root@localhost mysql]# httpd -k restart [root@localhost mysql]# httpd -M|grep php php5_module (shared) [root@localhost mysql]#
10.提供一個index.php文件并測試:
<?php $link = mysql_connect('127.0.0.1','root',''); if ($link) echo "Success..."; else echo "Failure..."; mysql_close(); phpinfo(); ?>
上面這個文件是連接mysql,如果連接成功就輸出Success,如果連接失敗就輸出Failure。并且后面跟著輸出一個php測試頁面。
可以關閉掉mysql再測試:
[root@localhost htdocs]# service mysqld stop Shutting down MySQL. [ OK ] [root@localhost htdocs]#
11.編譯Xcache
解包: [root@localhost lamp]# tar xf xcache-3.2.0.tar.gz 執行phpize(phpize是用來擴展php擴展模塊的,通過phpize可以建立php的外掛模塊): [root@localhost lamp]# cd xcache-3.2.0 [root@localhost xcache-3.2.0]# phpize Configuring for: PHP Api Version: 20121113 Zend Module Api No: 20121212 Zend Extension Api No: 220121212 編譯: [root@localhost xcache-3.2.0]# ./configure \ > --enable-xcache \ #開啟cache功能 > --with-php-config=/usr/local/php/bin/php-config \ #指定php的配置程序,這個程序是告訴編譯程序php的信息的 > && make && make install 編譯后有一條信息,記錄下來稍后會用到: Installing shared extensions: /usr/local/php-5.5.3/lib/php/extensions/no-debug-zts-20121212/ 復制xcache.ini到/etc/php.d目錄: [root@localhost xcache-3.2.0]# mkdir /etc/php.d [root@localhost xcache-3.2.0]# cp xcache.ini /etc/php.d/ 修改配置文件: [root@localhost xcache-3.2.0]# vim /etc/php.d/xcache.ini 將:extension = xcache.so 修改為剛才編譯完成后保留的位置: extension = /usr/local/php-5.5.3/lib/php/extensions/no-debug-zts-20121212/xcache.so
12.測試Xcache的作用:
沒啟動Xcache:
[root@localhost php.d]# ab -c 10 -n 100 http://10.10.10.11/pma/index.php This is ApacheBench, Version 2.3 <$Revision: 1554214 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 10.10.10.11 (be patient).....done Server Software: Apache Server Hostname: 10.10.10.11 Server Port: 80 Document Path: /pma/index.php Document Length: 9047 bytes Concurrency Level: 10 Time taken for tests: 3.876 seconds Complete requests: 100 Failed requests: 0 Total transferred: 1037900 bytes HTML transferred: 904700 bytes Requests per second: 25.80 [#/sec] (mean) Time per request: 387.550 [ms] (mean) Time per request: 38.755 [ms] (mean, across all concurrent requests) Transfer rate: 261.53 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 5.4 0 27 Processing: 290 383 25.3 387 438 Waiting: 272 356 25.3 360 409 Total: 308 385 24.5 388 438 Percentage of the requests served within a certain time (ms) 50% 388 66% 399 75% 401 80% 404 90% 412 95% 419 98% 430 99% 438 100% 438 (longest request)
啟動Xcache:
[root@localhost php.d]# ab -c 10 -n 100 http://10.10.10.11/pma/index.php This is ApacheBench, Version 2.3 <$Revision: 1554214 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 10.10.10.11 (be patient).....done Server Software: Apache Server Hostname: 10.10.10.11 Server Port: 80 Document Path: /pma/index.php Document Length: 9047 bytes Concurrency Level: 10 Time taken for tests: 0.728 seconds Complete requests: 100 Failed requests: 0 Total transferred: 1037900 bytes HTML transferred: 904700 bytes Requests per second: 137.39 [#/sec] (mean) Time per request: 72.784 [ms] (mean) Time per request: 7.278 [ms] (mean, across all concurrent requests) Transfer rate: 1392.57 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 5.0 0 25 Processing: 29 70 23.4 67 129 Waiting: 8 53 23.2 50 128 Total: 29 72 23.9 69 129 Percentage of the requests served within a certain time (ms) 50% 69 66% 80 75% 86 80% 95 90% 111 95% 117 98% 125 99% 129 100% 129 (longest request)
二、PHP的FastCGI方式結合Apache:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。