linux 安装 php

时间:2021-05-09 08:49:25

1.  libxml2安装

          tar -zxvf libxml2-2.6.26.tar.gz

cd libxml2-2.6.26

./configure  --prefix=/usr/local/libxml

make

make install

make clean

2. zlib安装

         tar -zxvf zlib-1.2.3.tar.gz
         cd zlib-1.2.3
          ./configure  --prefix=/usr/local/zlib

(CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/zlib/  ) 64位操作系统的编译方法
          make
          make install
          make clean

3.  libpng安装

         tar -zxvf libpng-1.2.12.tar.gz
         cd libpng-1.2.12
         ./configure --prefix=/usr/local/libpng
        make
        make install
        make clean

4. jpeg安装 

tar -zxvf jpegsrc.v6b.tar.tar
        cd jpeg-6b

注意:首先看有没有装libtool (whereis libtool),没有就需要yum install libtool.

cp /usr/share/libtool/config/config.guess .  (64位操作系统需要拷贝这个到当前目录下面)

cp /usr/share/libtool/config/config.sub .  (64位操作系统需要拷贝这个到当前目录下面)

mkdir /usr/local/jpeg
        mkdir /usr/local/jpeg/include
        mkdir /usr/local/jpeg/lib
        mkdir /usr/local/jpeg/bin
        mkdir /usr/local/jpeg/man

mkdir /usr/local/jpeg/man1

mkdir /usr/local/jpeg/man/man1

./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
         make
         make install
         make clean

5. 安装 freetype  

tar -zxvf freetype-2.2.1.tar.gz

cd freetype-2.2.1

./configure --prefix=/usr/local/freetype

make

make install

6. GD安装

tar -jxvf libgd-2.1.1.tar.bz2
           cd libgd-2.1.1
            ./configure --prefix=/usr/local/gd --with-zlib --with-png=/usr/local/libpng --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype

vi Makefile
           编辑 Makefile  将
           CPPFLAGS = -I/usr/local/jpeg/include (该选项也可能为空,只要参考下面的修改就可以了)
           改为
           CPPFLAGS = -I/usr/local/jpeg/include -I/usr/local/libpng/include 
           make
           make install
           make clean

7.   libiconv安装

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

将iconv.h连接到php的安装源程序中(php的安装源程序必须要和iconv.h在同一磁盘目录下面,否则link会出错),否则会php make会出错
            cd /usr/home/ty/php-5.1.6/ext/iconv/(该目录为php的安装源程序目录)
           这里的php-5.1.6就是下面解压缩的路径
          link /usr/local/libiconv/include/iconv.h iconv.h

8.   安装 openssl

tar -zxvf openssl-1.0.1c.tar.gz
          cd openssl-1.0.1c
         ./config -fPIC --prefix=/usr/local/openssl/ enable-shared
          make
          make install
          在/etc/ld.so.conf文件的最后面,添加如下内容:
          /usr/local/openssl/lib

9. 安装curl

下载地址 http://curl.haxx.se/download/curl-7.17.1.tar.gz

tar -zxvf curl-7.17.1.tar.gz

cd curl

./configure --prefix=/usr/local/curl  --with-ssl=/usr/local/openssl  (先安装openssl 需注意)

curl version:    7.17.1

Host setup:      x86_64-unknown-linux-gnu

Install prefix:  /usr/local/curl

Compiler:        gcc

SSL support:     enabled (OpenSSL)(必须开启这个)

SSH support:     no      (--with-libssh2)

zlib support:    enabled

krb4 support:    no      (--with-krb4*)

GSSAPI support:  no      (--with-gssapi)

SPNEGO support:  no      (--with-spnego)

c-ares support:  no      (--enable-ares)

ipv6 support:    no      (--enable-ipv6)

IDN support:     no      (--with-libidn)

Build libcurl:   Shared=yes, Static=yes

Built-in manual: enabled

Verbose errors:  enabled (--disable-verbose)

SSPI support:    no      (--enable-sspi)

ca cert path:    ${prefix}/share/curl/curl-ca-bundle.crt

LDAP support:    no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)

LDAPS support:   no      (--enable-ldaps)

make

make install

10. 安装PHP      

tar -zxvf php-5.3.27.tar.gz
          cd php-5.3.27

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/local/libxml --with-mysql=/usr/local/mysql --with-curl=/usr/local/curl --with-zlib-dir=/usr/local/zlib --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng  --with-freetype-dir=/usr/local/freetype  --with-iconv=/usr/local/libiconv --with-config-file-path=/usr/local/php/lib  --with-gd=/usr/local/gd  --disable-debug --disable-safe-mode  --enable-short-tags --disable-posix --enable-exif --enable-ftp --enable-sockets  -enable-mbstring=all

make
         make install
         make clean
         cp /usr/src/php-5.3.27/php.ini-dist /usr/local/php/lib/php.ini

11. 修改apache配置文件 httpd.conf

            vi /usr/local/apache/conf/httpd.conf
            在httpd.conf文件相应的地方添加下面几行(如果在安装php5时,有的配置可以已经加上了,就不需要再重新添加了)
            LoadModule php5_module modules/libphp5.so
            AddType application/x-httpd-php .php
           在DirectoryIndex index.html index.html.var 后面添加index.php

配置完成... ..

12. 测试

           写个测试脚本检查环境是否安装正常    可以 根据实际情况需要对 php.ini进行必要的修改

php5.6编译参数如下

首先安装基本的扩展

yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
libmcrypt libmcrypt-devel

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc  --disable-debug  --enable-shared  --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir=/usr/local/libxml --enable-pcntl --enable-shmop --enable-sockets --with-curl=/usr/local/curl --with-zlib=/usr/local/zlib --enable-zip --with-bz2  --enable-exif --with-pcre-dir=/usr/local/pcre --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng --with-freetype-dir=/usr/local/freetype   --with-gd=/usr/local/gd  --with-iconv=/usr/local/libiconv