Apache-2.2.23 + PHP-5.2.17

一、安裝所需:

注:我自己的安裝環境爲centos 5.5 64

1、類庫:

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz
wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
wget http://pecl.php.net/get/memcache-2.2.6.tgz
wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://pecl.php.net/get/imagick-2.3.0.tgz

2、Apache2.2.23下載地址:點擊打開鏈接

二、安裝apache

    cd /usr/local/src

    tar -zxvf httpd-2.2.23

    cd httpd-2.2.23

    ./configure -prefix=/usr/local/apache -enable-module=so

    make 
    make install

在終端中輸入:/usr/local/apache/bin/apachectl start 啓動apache服務器
                  輸入:/usr/local/apache/bin/apachectl restart  重新啓動服務器

添加mod_rewrite模塊

     cd /usr/local/src/httpd-2.2.23/modules/mappers/
         /usr/local/apache/bin/apxs -c mod_rewrite.c
        /usr/local/apache/bin/apxs -i -a -n mod_rewrite mod_rewrite.la


三、安裝PHP

tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make
make install

cd ../


tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../


tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../


ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config


tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../


tar zxvf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17/


./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap


make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /usr/local/php/etc/php.ini
cd ../


tar zxvf memcache-2.2.6.tgz
cd memcache-2.2.6/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../


tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../


tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make
make install
cd ../


tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../


tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../


修改php.ini文件
  手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"
  修改爲extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
  並在此行後增加以下幾行,然後保存:
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"


  再查找output_buffering = Off
  修改爲output_buffering = On

配置eAccelerator加速PHP:
mkdir -p /home/eaccelerator_cache
vim /usr/local/php/etc/php.ini

按shift+g鍵跳到配置文件的最末尾,加上以下配置信息:
引用
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/home/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"


創建php-fpm配置文件(php-fpm是爲PHP打的一個FastCGI管理補丁,可以平滑變更php.ini配置而無需重啓php-cgi):
  在/usr/local/php/etc/目錄中創建php-fpm.conf文件:
rm -f /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf


輸入以下內容:

<?xml version="1.0" ?>
<configuration>
  All relative paths in this config are relative to php's install prefix
  <section name="global_options">
    Pid file
    <value name="pid_file">/usr/local/php/logs/php-fpm.pid</value>
    Error log file
    <value name="error_log">/usr/local/php/logs/php-fpm.log</value>
    Log level
    <value name="log_level">notice</value>
    When this amount of php processes exited with SIGSEGV or SIGBUS ...
    <value name="emergency_restart_threshold">10</value>
    ... in a less than this interval of time, a graceful restart will be initiated.
    Useful to work around accidental curruptions in accelerator's shared memory.
    <value name="emergency_restart_interval">1m</value>
    Time limit on waiting child's reaction on signals from master
    <value name="process_control_timeout">5s</value>
    Set to 'no' to debug fpm
    <value name="daemonize">yes</value>
  </section>
  <workers>
    <section name="pool">
      Name of pool. Used in logs and stats.
      <value name="name">default</value>
      Address to accept fastcgi requests on.
      Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
      <value name="listen_address">127.0.0.1:9000</value>
      <value name="listen_options">
        Set listen(2) backlog
        <value name="backlog">-1</value>
        Set permissions for unix socket, if one used.
        In Linux read/write permissions must be set in order to allow connections from web server.
        Many BSD-derrived systems allow connections regardless of permissions.
        <value name="owner"></value>
        <value name="group"></value>
        <value name="mode">0666</value>
      </value>
      Additional php.ini defines, specific to this pool of workers.
      <value name="php_defines">
        <value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
        <value name="display_errors">0</value>
      </value>
      Unix user of processes
      <value name="user">www</value>
      Unix group of processes
      <value name="group">www</value>
      Process manager settings
      <value name="pm">
        Sets style of controling worker process count.
        Valid values are 'static' and 'apache-like'
        <value name="style">static</value>
        Sets the limit on the number of simultaneous requests that will be served.
        Equivalent to Apache MaxClients directive.
        Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
        Used with any pm_style.
        <value name="max_children">128</value>
        Settings group for 'apache-like' pm style
        <value name="apache_like">
          Sets the number of server processes created on startup.
          Used only when 'apache-like' pm_style is selected
          <value name="StartServers">20</value>
          Sets the desired minimum number of idle server processes.
          Used only when 'apache-like' pm_style is selected
          <value name="MinSpareServers">5</value>
          Sets the desired maximum number of idle server processes.
          Used only when 'apache-like' pm_style is selected
          <value name="MaxSpareServers">35</value>
        </value>
      </value>
      The timeout (in seconds) for serving a single request after which the worker process will be terminated
      Should be used when 'max_execution_time' ini option does not stop script execution for some reason
      '0s' means 'off'
      <value name="request_terminate_timeout">0s</value>
      The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
      '0s' means 'off'
      <value name="request_slowlog_timeout">0s</value>
      The log file for slow requests
      <value name="slowlog">logs/slow.log</value>
      Set open file desc rlimit
      <value name="rlimit_files">65535</value>
      Set max core size rlimit
      <value name="rlimit_core">0</value>
      Chroot to this directory at the start, absolute path
      <value name="chroot"></value>
      Chdir to this directory at the start, absolute path
      <value name="chdir"></value>
      Redirect workers' stdout and stderr into main error log.
      If not set, they will be redirected to /dev/null, according to FastCGI specs
      <value name="catch_workers_output">yes</value>
      How much requests each process should execute before respawn.
      Useful to work around memory leaks in 3rd party libraries.
      For endless request processing please specify 0
      Equivalent to PHP_FCGI_MAX_REQUESTS
      <value name="max_requests">1024</value>
      Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
      Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
      Makes sense only with AF_INET listening socket.
      <value name="allowed_clients">127.0.0.1</value>
      Pass environment variables like LD_LIBRARY_PATH
      All $VARIABLEs are taken from current environment
      <value name="environment">
        <value name="HOSTNAME">$HOSTNAME</value>
        <value name="PATH">/usr/local/bin:/usr/bin:/bin</value>
        <value name="TMP">/tmp</value>
        <value name="TMPDIR">/tmp</value>
        <value name="TEMP">/tmp</value>
        <value name="OSTYPE">$OSTYPE</value>
        <value name="MACHTYPE">$MACHTYPE</value>
        <value name="MALLOC_CHECK_">2</value>
      </value>
    </section>
  </workers>
</configuration>

四、配置httpd.conf

      vim /usr/local/apache/conf/httpd.conf

        ServerRoot:apache的安裝目錄

        Listen: apache監聽的端口

       搜索LoadModule,如果有下面兩句

      LoadModule php5_module        modules/libphp5.so

     LoadModule rewrite_module     modules/mod_rewrite.so

     則將前面的註釋刪除掉,如果沒有這兩句,則添加上去

    搜索AddType

    添加:AddType application/x-httpd-php .php .phtml

添加以下配置:

<VirtualHost *:80>


    DocumentRoot /home/htdocs/www    --你的文檔的根目錄。默認情況下,所有的請求從這個目錄進行應答。
    ServerName test.yalv023.com   --訪問域名
        <Directory /home/htdocs/www >   --用於封裝一組指令,使之僅對某個目錄及其子目錄生效。
                Options FollowSymLinks  
                AllowOverride All   
                order allow,deny
                Allow from all
        </Directory>
</VirtualHost>

在<IfModule dir_module>

裏面添加 index.php

至此配置完成.


注:

可能遇到的問題

httpd: Syntax error on line 54 of /usr/share/apache-2.2.11/conf/httpd.conf: Can't locate API module structure `mod_rewrite_module' in file /usr/share/apache-2.2.11/modules/mod_rewrite.so: /usr/share/apache-2.2.11/modules/mod_rewrite.so: undefined symbol: mod_rewrite_module

修改 httpd.conf,將

LoadModule mod_rewrite_module modules/mod_rewrite.so

改爲

LoadModule mod_rewrite modules/mod_rewrite.so

如果出現這個錯誤
Syntax error on line 329 of /usr/local/apache2/conf/httpd.conf:
Can`t loacte API module staructure `mod_rewrite_module` in file 
/usr/local/apache2/modules/mod_rewrite.so:/usr/local/apache2/lib/libapr-
0.so.0:undefined symbol:mod_rewrite_module
修改http.conf 
原來:httpd.conf裏面寫的mod_rewrite_module
改成 rewrite_module

如果重啓apache出現這個錯誤module rewrite_module is built-in and can`t be loaded
表示模塊是內建的,不用再調入,註釋掉
#LoadModule rewrite_module modules/mod_rewrite.so
發佈了47 篇原創文章 · 獲贊 16 · 訪問量 18萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章