zoukankan      html  css  js  c++  java
  • CentOS下编译搭建LAMP环境

    搭建LAMP环境须知

    搭建LAMP环境时,需要安装的所有软件都要按照一定的顺序安装,我们按照Apache->MySQL->PHP的顺序安装。但是在安装PHP之前,应先安装PHP5需要的最新版本库文件,例如libxml2、libmcrypt,以及GD2库等文件。安装GD2库是为了让PHP5支持GIF、PNG和JPEG图片格式,所以在安装GD2库之前还要先安装最新的zlib、libpng、freetype和jpegsrc等库文件。而且中间还会穿插安装一些软件。

    确认搭建LAMP所需的环境是否已经安装:

    [root@centos6 ~]# rpm -q make gcc gcc-c++ zlib-devel libtool libtool-ltdl libtool-ltdl-devel bisonncurses-devel

    安装libpng时需要:zlib-devel
    安装php时需要:libtool、libtool-ltdl、libtool-ltdl-devel
    安装mysql时需要:bison、ncurses-devel

    如果没安装则使用yum安装:

    [root@centos6 ~]# yum -y install make gcc gcc-c++ zlib-devel libtool libtool-ltdllibtool-ltdl-devel bison ncurses-devel

    需要安装的程序包

    httpd-->http://httpd.apache.org/
    mysql-->http://dev.mysql.com/downloads/
    php-->http://cn2.php.net/downloads.php
    libxml2-->ftp://xmlsoft.org/libxml2/
    libmcrypt[PHPlibmcrypt模块]-->ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/
    libgd-->https://bitbucket.org/libgd/gd-libgd/downloads
    zlib-->http://www.zlib.net
    autoconf-->http://ftp.gnu.org/gnu/autoconf/
    freetype-->http://download.savannah.gnu.org/releases/freetype/
    libpng-->ftp://ftp.simplesystems.org/pub/libpng/png/src/
    jpegsrc-->http://www.ijg.org/files/
    apr[Apache库文件]-->http://apr.apache.org/download.cgi
    apr-util[Apache库文件]-->http://apr.apache.org/download.cgi
    pcre-->http://sourceforge.net/projects/pcre
    cmake[MySQL编译工具]-->http://www.cmake.org
    gd库-->http://libgd.bitbucket.org/

    安装规则

    软件源代码包存放位置 :/usr/local/src

    源码包编译安装位置:/usr/local/软件名字 (编译安装的软件一般安装在/usr/local/下)

    源代码安装:配置(configure)、编译(make)、安装(make install)

    前期准备

    配置防火墙,开启80端口、3306端口

    [root@centos6 ~]# vim /etc/sysconfig/iptables
    # 添加到默认的22端口下面:
    -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许80端口通过防火墙)
    -A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT(允许3306端口通过防火墙)
    [root@centos6 ~]# /etc/init.d/iptables restart
    

      

    关闭SELINUX
    [root@centos6 ~]# vim /etc/selinux/config
    # SELINUX=enforcing # 注释掉
    # SELINUXTYPE=targeted # 注释掉
    SELINUX=disabled # 增加
    :wq 保存,关闭
    [root@centos6 ~]# shutdown -r now # 重启系统
    

    查看httpd、mysql、php是否安装

    [root@centos6 ~]# rpm -q httpd mysql php
    

    卸载对应已安装软件

    [root@centos6 ~]# rpm -e httpd --nodeps
    [root@centos6 ~]# rpm -e mysql --nodeps
    [root@centos6 ~]# rpm -e php --nodeps

    编译安装libxml2(xml的C语言编译器)

    [root@centos6 ~]# tar -zxvf libxml2-2.6.30.tar.gz 
    [root@centos6 ~]# cd libxml2-2.6.30 
    [root@centos6 libxml2-2.6.30]# ./configure --prefix=/usr/local/libxml2
    [root@centos6 libxml2-2.6.30]# make
    [root@centos6 libxml2-2.6.30]# make install
    

    注:选项--prefix=/usr/local/libxml2作用是将软件安装到/usr/local/libxml2目录下。如果安装成功以后,在/usr/local/libxml2/目录下将生成bin、include、lib、share四个目录。在后面安装PHP5源代码的配置时,会通过在configure命令的选项中加上"--with-libxml-dir=/usr/local/libxml2"选项,用于指定安装libxml2库文件的位置。

    [root@centos6 ~]# rpm -qa | grep python-devel
    [root@centos6 ~]# yum install python-devel
    [root@centos6 ~]# rpm -qa | grep python-devel

    编译安装libmcrypt(加密算法扩展库)

    [root@centos6 ~]# tar -zxvf libmcrypt-2.5.8.tar.gz
    [root@centos6 ~]# cd libmcrypt-2.5.8
    [root@centos6 libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt 
    [root@centos6 libmcrypt-2.5.8]# make
    [root@centos6 libmcrypt-2.5.8]# make install

    如果安装成功就会在/usr/local/libmcrypt/目录下生成bin、include、lib、man、share五个目录。然后在安装PHP5源代码包的配置时,就可以通过configure命令加上"--with-mcrypt-dir=/usr/local/libmcrypt"选项,指定这个libmcrypt库文件的位置。
    如./configure时报错:configure: error: C++ compiler cannot create executables,解决方案:运行下面命令,然后重新configure(配置)

    [root@centos6 libmcrypt-2.5.8]# yum install gcc gcc-c++ gcc-g77 

    安装完成libmcrypt库以后,不同的linux系统版本有可能还要安装一下libltdl库。安装方法和前面的步骤相同,可以进入到解压缩的目录/usr/local/src/libmcrypt-2.5.8下,找到libltdl库源代码所在的目录libltdl,进入这个目录按照下面几个命令配置、编译、安装就可以了。

    [root@centos6 libltdl]# pwd 
    /usr/local/src/libmcrypt-2.5.8/libltdl # 进入软件源代码目录  
    [root@centos6 libltdl]# ./configure –enable-ltdl-install # 配置ltdl库的安装  
    [root@centos6 libltdl]# make  # 编译 
    [root@centos6 libltdl]# make install  # 安装

    编译安装zlib(zlib是提供数据压缩用的函式库、安装GD需要)

    [root@centos6 LAMP]# tar -zxvf zlib-1.2.5.tar.gz 
    [root@centos6 LAMP]# cd ./zlib-1.2.5  
    [root@centos6 zlib-1.2.5]# ./configure  --prefix=/usr/local/zlib
    [root@centos6 zlib-1.2.5]# make && make install

    如果安装成功将会在/usr/local/zlib目录下生成include、lib、share三个目录。在安装PHP5配置时,在configure命令的选项中加上"--with-zlib-dir=/usr/local/libmcrypt"选项,用于指定zlib库文件位置。

    编译安装libpng(安装GD需要)

    [root@centos6 LAMP]# tar -zxvf libpng-1.5.4.tar.gz 
    [root@centos6 LAMP]# cd ./libpng-1.5.4 
    [root@centos6 libpng-1.5.4]# ./configure --prefix=/usr/local/libpng  --enable-shared 
    [root@centos6 libpng-1.5.4]# make && make install
    

    在./configure --prefix=/usr/local/libpng这步最后会提示:configure: error: ZLib not installed

    解决方法如下:

    1. 进入zlib的源文件目录,执行命令 make clean,清除zlib;
    2. 重新配置 ./configure,后面不要接--prefix参数; 
    3. make && make install;
    4. 进入libpng目录,执行命令 ./configure --prefix=/usr/local/libpng;
    5. make && make install;
    6. 安装成功

    如果安装成功将会在/usr/local/libpng目录下生成bin、include、lib和share四个目录。在安装GD2库配置时,通过在configure命令选项中加上"--with-png=/usr/local/libpng"选项,指定libpng库文件的位置。

    编译安装jpeg(安装GD2库前所需的jpeg8库文件,需要自己手动创建安装需要的目录,它们在安装时不能自动创建)

    [root@centos6 LAMP]# tar -zxvf jpegsrc.v8c.tar.gz 
    [root@centos6 LAMP]# cd ./jpeg-8c/  
    [root@centos6 jpeg-8c]# mkdir /usr/local/jpeg/   	     (创建jpeg软件的安装目录) 
    [root@centos6 jpeg-8c]# mkdir /usr/local/jpeg/bin/  		(创建存放命令的目录) 
    [root@centos6 jpeg-8c]# mkdir /usr/local/jpeg/lib/    		(创建jpeg库文件所在目录) 
    [root@centos6 jpeg-8c]# mkdir /usr/local/jpeg/include/  	(创建存放头文件目录)  
    [root@centos6 jpeg-8c]# mkdir -p /usr/local/jpeg/man/man1      (建立存放手册的目录)	
    [root@centos6 jpeg-8c]# ./configure --prefix=/usr/local/jpeg  --enable-shared --enable-static(建立共享库使用的GNU的libtool和静态库使用的GNU的libtool)
    [root@centos6 jpeg-8c]# make && make install

    在安装GD2库配置时,可以在configure命令的选项中加上"--with-jpeg=/usr/local/jpeg8"选项,指定jpeg8库文件的位置。安装PHP时也要指定该库文件的位置。

    编译安装freetype  (安装GD需要)

    [root@centos6 LAMP]# tar -zxvf freetype-2.4.6.tar.gz 
    [root@centos6 LAMP]# cd ./freetype-2.4.6 
    [root@centos6 freetype-2.4.6]# ./configure --prefix=/usr/local/freetype/ --enable-shared 
    [root@centos6 freetype-2.4.6]# make && make install

    如果安装成功将会在/usr/local/freetype目录下存在bin、include、lib和share四个目录。并在安装GD2库时,通过configure命令选项中加上"--with-freetype=/usr/local/freetype/"选项,指定freetype库文件位置。

    编译安装autoconf  (唯一注意的地方是configure时,不用指定路径)

    [root@centos6 LAMP]# tar -zxvf autoconf-2.68.tar.gz 
    [root@centos6 LAMP]# cd ./autoconf-2.68
    [root@centos6 autoconf-2.68]# ./configure 
    [root@centos6 autoconf-2.68]# make && make install

    编译安装GD

    [root@centos6 LAMP]# tar -zxvf gd-2.0.35.tar.gz 
    [root@centos6 LAMP]# cd ./gd-2.0.35 
    [root@centos6 gd-2.0.35]# ./configure                    	# 配置命令   
    						> --prefix=/usr/local/gd               # 指定安装软件的位置  
    						> --with-jpeg=/usr/local/jpeg         	# 指定去哪找jpeg库文件   
    						> --with-png=/usr/local/libpng        	# 指定去哪找png库文件 
    						> --with-zlib=/usr/local/zlib     	# 指定去哪找zlib库文件  
    						> --with-freetype=/usr/local/freetype   # 指定去哪找freetype 2.x字体库的位置 
    [root@centos6 gd-2.0.35]# make && make install
    

    如果安装成功会在/usr/local/gd/目录下存在bin、include和lib这三个目录。在安装PHP5时,通过在configure命令选项中加上"--with-gd=/usr/local/gd"选项,指定GD库文件的位置。

    如果报错:

    gd_png.c 中 gdMalloc函数的问题
    make[2]: *** [gd_png.lo] Error 1
    make[2]: Leaving directory `/tmp/gd-2.0.35'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/tmp/gd-2.0.35'
    make: *** [all] Error 2

    解决方案:

    vi gd_png.c
    找到#include "png.h"改成#include "/usr/local/libpng/include/png.h"
    如果报错:unrecognized option –with-zlib
    那就重新安装一次zlib,注意,需要把原先解压出来的源码删掉,重新解压进行安装。

    安装apache

    先安装apr、apr-util、pcre

    [root@centos6 ~]# rpm -qa | grep apr
    [root@centos6 ~]# yum remove apr apr-util 
    # 查看当前是否已经安装apr、apr-util,若有则卸载。
    

      

    # 编译安装apr
    [root@centos6 LAMP]# tar zxvf apr-1.5.1.tar.gz 
    [root@centos6 LAMP]# cd apr-1.5.1  
    [root@centos6 apr-1.5.1]# ./configure --prefix=/usr/local/apr && make && make install 
    

      

    # 编译安装apr-util 
    [root@centos6 LAMP]# tar zxvf apr-util-1.5.3.tar.gz 
    [root@centos6 LAMP]# cd apr-util-1.5.1  
    [root@centos6 apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    [root@centos6 apr-util-1.5.3]# make && make install 
    

      

    # 编译安装pcre(主要这里是使用pcre而不是pcre2,否则在编译时会出错)	
    [root@centos6 LAMP]# tar zxvf pcre-8.37.tar.gz
    [root@centos6 LAMP]# cd pcre-8.37  
    [root@centos6 pcre-8.37]# ./configure --prefix=/usr/local/pcre
    [root@centos6 pcre-8.37]# make 
    [root@centos6 pcre-8.37]# make install
    

      

    # 编译安装apache
    [root@centos6 LAMP]# tar zxvf httpd-2.4.9.tar.gz 
    [root@centos6 LAMP]# cd httpd-2.4.9 
    [root@centos6 httpd-2.4.9]# ./configure   
    	> --prefix=/usr/local/apache2  
    	> --enable-mods-shared=all  
    	> --enable-deflate  
    	> --enable-speling  
    	> --enable-cache  
    	> --enable-file-cache  
    	> --enable-disk-cache  
    	> --enable-mem-cache  
    	> --enable-so   
    	> --enable-expires=shared  
    	> --enable-rewrite=shared  
    	> --enable-static-support  
    	> --sysconfdir=/etc/httpd  
    	> --with-z=/usr/local/zlib  
    	> --with-apr=/usr/local/apr  
    	> --with-apr-util=/usr/local/apr-util  
    	//> --with-pcre=/usr/local/pcre  
    	> --disable-userdir
    [root@centos6 httpd-2.4.9]# make && make install
    

    安装完成后,进入/usr/local/apache2/目录下,检查是否有以下文件:

    bin build  cgi-bin  error htdocs icons  include  logs  man  manual  modules

    启动Apache服务器,并查端口是否开启,启动Apache服务器的命令行如下: 

    [root@centos6 httpd-2.4.9]# /usr/local/apache2/bin/apachectl 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@centos6 httpd-2.4.9]# vi /etc/httpd/httpd.conf
    加上:ServerName localhost:80  重启apache  # netstat -tnl|grep 80 查看端口情况

    开机启动apache

    [root@centos6 apache2]# echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local
    [root@centos6 LAMP]# /usr/local/apache2/bin/apachectl start  
    [root@centos6 LAMP]# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd 
    [root@centos6 LAMP]# chmod +x /etc/init.d/httpd  
    [root@centos6 ~]# chkconfig --add httpd 
    

    注意:如果提示service httpd does not support chkconfig错误解决办法:

    编辑/etc/rc.d/init.d/httpd在文件第二行加入 
    #chkconfig:2345 10 90             
    #description:Activates/Deactivates Apache Web Server
    
    开机自动启动apache的另一种方法: 
    修改/etc/rc.local文件 
    # vim /etc/rc.local  
    在文件中添加/usr/local/apache/bin/apachectl start
    

      

    # 启动、关闭、开启apache
    [root@centos6 ~] # /etc/init.d/httpd start 
    [root@centos6 ~] # /etc/init.d/httpd restart 
    [root@centos6 ~] # /etc/init.d/httpd stop

    安装MySQL

    mysql版本5.5以上编译安装时需要用到软件cmake,cmake特性是独立于源码编译,编译工作可以在另外一个目录中而非源码目录中进行,好处是可以保证源码目录不受任何一次编译的影响。估计以后的版本也会采用这种方式,所以特地记录一下安装步骤及过程,以供参考。

    注意:此安装是默认centos下已经安装了最新工具包,比如GNU、make、GCC、Perl、libncurses5-dev,如果在编译安装过程中发现有缺失的工具包,先yum install 单独下载安装再继续即可。

    以下安装中涉及的几点需要提前说明的问题: 

     所有下载的文件将保存在 /usr/local/src/ 目录下

    • mysql将以mysql用户运行,而且将加入 service 开机自动运行
    • mysql将被安装在 /usr/local/mysql/ 目录下
    • mysql默认安装使用 utf8 字符集
    • mysql的数据和日志文件保存在 /usr/local/mysql/data/ 对应目录下
    • mysql的配置文件保存于/etc/my.cnf
    [root@centos6 ~]# yum -y install make gcc-c++ bison-devel ncurses-devel

    下载安装cmake [CMake编译器]

    [root@centos6 ~]# tar zxvf cmake-3.0.0.tar.gz
    [root@centos6 ~]# cd  cmake-3.0.0  
    [root@centos6 ~]# ./bootstrap  
    [root@centos6 ~]# gmake  
    [root@centos6 ~]# make && make install

    在使用时可能会出现error,若提示是/usr/bin/cmake文件不存在

    解决办法:

    [root@centos6 ~]# whereis cmake  # 得到cmke的可执行文件的路径,如在:/usr/local/bin/cmake 
    [root@centos6 ~]# ln -s /usr/local/bin/cmake /usr/bin/cmake # 创建一个链接文件即可解决

    卸载旧版MySQL

    [root@centos6 ~]# rpm -qa | grep mysql
    [root@centos6 ~]# rpm -e mysql  # 普通删除模式
    [root@centos6 ~]# rpm -e --nodeps mysql	# 强力删除模式
    

      

    [root@centos6 ~]# yum -y install make gcc-c++ bison-devel ncurses-devel
    # 安装编译所需要的包 bison-devel、ncurses-devel、cmake需要编译安装(如上面的cmake的安装过程)

    编译安装mysql:

    [root@centos6 ~]# tar xvf mysql-5.6.16.tar.gz
    [root@centos6 ~]# cd mysql-5.6.16
    [root@centos6 ~]# cmake 
      -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
      -DMYSQL_DATADIR=/usr/local/mysql/data 
      -DSYSCONFDIR=/etc 
      -DWITH_MYISAM_STORAGE_ENGINE=1 
      -DWITH_INNOBASE_STORAGE_ENGINE=1 
      -DWITH_MEMORY_STORAGE_ENGINE=1 
      -DWITH_READLINE=1 
      -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock 
      -DMYSQL_TCP_PORT=3306 
      -DENABLED_LOCAL_INFILE=1 
      -DWITH_PARTITION_STORAGE_ENGINE=1 
      -DEXTRA_CHARSETS=all 
      -DDEFAULT_CHARSET=utf8 
      -DDEFAULT_COLLATION=utf8_general_ci
    [root@centos6 ~]# make && make install
    # 配置编译的参数可以到mysql的官网查看

    配置MySQL

    1、设置权限

    [root@centos6 ~]# cat /etc/passwd  # 查看用户列表
    [root@centos6 ~]# cat /etc/group # 查看用户组列表
    
    # 创建mysql用户以及用户组
    [root@centos6 ~]# groupadd mysql
    [root@centos6 ~]# useradd -g mysql mysql
    
    [root@centos6 ~]# chown -R mysql:mysql /usr/local/mysql   # 修改/usr/local/mysql权限
    

      

    2、初始化配置

    注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置。注意:在CentOS 6.4版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。

    [root@centos6 ~]# mv /etc/my.cnf /etc/my.cnf.bak
    [root@centos6 ~]# rm /etc/my.cnf  # 可以删除掉/etc/my.cnf这个文件

    如果你需要用于生产环境,不要急着做下面的mysql启动操作。建议把上一步骤中mysql初始化生成的/usr/local/mysql/mysql.cnf删除,然后把你优化好的mysql配置文件my.cnf放到/etc下。(这是我做mysql主从复制和mysql优化的经验!)

    [root@centos6 ~]# cd /usr/local/mysql 
    # 进入安装路径,执行初始化配置脚本,创建系统自带的数据库和表
    [root@centos6 ~]scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
    # 复制服务启动脚本
    [root@centos6 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
    # 启动MySQL服务
    [root@centos6 ~]# service mysql start
    # 设置开机自动启动服务
    [root@centos6 ~]# chkconfig mysql on
    # 编辑PATH路径
    [root@centos6 ~]# vim /etc/profile
    # 在文件末尾添加
    PATH=/usr/local/mysql/bin:$PATH
    export PATH
    [root@centos6 ~]# source /etc/profile  # 保存让配置立即生效
    # 修改密码
    [root@centos6 ~]# mysql -uroot
    mysql> SET PASSWORD = PASSWORD('123456');
    # 登陆
    [root@centos6 ~]# mysql -uroot -p

    编译安装PHP

    [root@centos6 ~]# yum -y install libXpm-devel
    [root@centos6 ~]# rpm -ql libXpm-devel
    
    # 确保已经安装了libXpm。查找到libXpm-devel的安装位置为/usr/lib64/libXpm.so,将选项--with-xpm-dir=/usr/lib64添加到php的配置选项中。
    
    [root@centos6 ~]# tar -zxvf php-5.4.11.tar.gz
    [root@centos6 ~]# cd ./php-5.4.11 
    [root@centos6 php-5.4.11]# ./configure 
            > --prefix=/usr/local/php   
    	> --with-config-file-path=/usr/local/php/etc         # 配置文件路径,指定php.ini位置 
    	> --with-apxs2=/usr/local/apache2/bin/apxs           # apxs功能是使用mod_so中的   //  LoadModule指令,加载指定模块到 apache,要求 apache 要打开SO模块  
    	> --with-mysql=/usr/local/mysql                      # mysql安装目录,对mysql的支持 
    	> --with-mysqli=/usr/local/mysql/bin/mysql_config    # mysqli文件目录,优化支持 
    	> --with-libxml-dir=/usr/local/libxml2               # 打开libxml2库的支持 
    	> --with-png-dir=/usr/local/libpng                   # 打开对png图片的支持
    	> --with-jpeg-dir=/usr/local/jpeg                    # 打开对jpeg图片的支持 
    	> --with-freetype-dir=/usr/local/freetype            # 打开对freetype字体库的支持 
    	> --with-gd=/usr/local/gd                            # 打开gd库的支持 
    	> --with-zlib-dir=/usr/local/zlib                    # 打开zlib库的支持 
    	> --with-mcrypt=/usr/local/libmcrypt                 # 打开libmcrypt库的支持 
    	> --with-xpm-dir=/usr/lib64                           # 打开libXpm库的支持 
    	> --enable-soap                          # 打开soap
    	> --enable-mbstring=all                              # 多字节,字符串的支持 
    	> --enable-sockets                                    # 打开sockets 支持    
    

      

    [root@centos6 php-5.4.11]# make && make install
    # 安装完成后,需要建立PHP配置文件。在使用configure命令安装配置时使用"--with-config-file-path=/usr /local/php/etc/"选项,指定了配置文件的位置。将源码包下面的php.ini-development 文件复制到/usr/local /php/etc/中,并改名为php.ini
    [root@centos6 php-5.4.11]# cp php.ini-development /usr/local/php/etc/php.ini
    修改php.ini 把;date.timezone 前面的分号去掉,改成date.timezone ="PRC"
    更改apache的配置文件,达到解析php文件的目的
    编辑配置文件/etc/httpd/httpd.conf,在LoadModule最后面添加以下内容
    LoadModule php5_module        modules/libphp5.so
    # 确保/usr/local/apache/modules下存在libphp5.so,否则说明php安装不成功
    
    [root@centos6 ~]# vim /etc/httpd/httpd.conf 
    # 添加如下内容:
    AddType application/x-compress .Z 
    AddType application/x-gzip .gz .tgz  
    Addtype application/x-httpd-php .php .phtml 
    Addtype application/x-httpd-php-source .phps
    
    # 将下面一行:
    DirectoryIndex index.html
    # 修改为:
    DirectoryIndex  index.php index.html index.htm
    
    [root@centos6 ~]# /etc/init.d/httpd restart   # 重启apache服务器
    
    # 修改环境变量PATH路径,使PHP能够在命令行中执行
    [root@centos6 ~]# vim /etc/profile
    
    # 在最后添加一下:
    PATH=/usr/local/php/bin:$PATH
    export PATH
    [root@centos6 ~]# source /etc/profile

    编译安装PHP扩展

    pcntl扩展

    [root@centos6 ~]# cd /usr/local/src/php-5.6.16/ext/pcntl		# 进入php源码包里面的pcntl的文件夹里面
    [root@centos6 pcntl]# ln -s /usr/local/php/bin/phpize /usr/local/bin/phpize
    [root@centos6 pcntl]# phpize
    [root@centos6 pcntl]# ./configure --with-php-config=/usr/local/php/bin/php-config
    # 指定到系统中相应的php-config的位置
    [root@centos6 pcntl]# make && make install
    # 编译安装pcntl完毕后会生成了一个 pcntl.so的文件
    [root@centos6 pcntl]# vim /usr/local/php/etc/php.ini
    加上 extension=pcntl.so
    [root@centos6 pcntl]# /etc/init.d/httpd restart

    libevent扩展

    [root@centos6 ~]# yum install wget libevent-devel
    [root@centos6 ~]# pecl install channel://pecl.php.net/libevent-0.1.0
    # 成功后会生成/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/libevent.so
    [root@centos6 ~]# vim /usr/local/php/etc/php.ini
    添加:extension=libevent.so
    [root@centos6 ~]# /etc/init.d/httpd restart

    phpredis扩展

    [root@centos6 ~]# tar -zxvf redis-2.2.7.tgz
    [root@centos6 ~]# cd redis-2.2.7
    [root@centos6 redis-2.2.7]# /usr/local/php/bin/phpize  # 用phpize生成configure配置文件
    [root@centos6 redis-2.2.7]# ./configure --with-php-config=/usr/local/php/bin/php-config  # 配置
    [root@centos6 redis-2.2.7]# make 
    [root@centos6 redis-2.2.7]# make install 
    
    # 配置php支持
    [root@centos6 redis-2.2.7]# vim /usr/local/php/etc/php.ini 
    添加如下: extension="redis.so"
    [root@centos6 redis-2.2.7]# /etc/init.d/httpd restart

    openssl扩展

    [root@centos6 ~]# yum install openssl openssl-devel
    [root@centos6 ~]# cd /usr/local/src/php-5.6.16/ext/openssl
    [root@centos6 openssl]# cp config0.m4  config.m4
    [root@centos6 openssl]# /usr/local/php/bin/phpize
    [root@centos6 openssl]# ./configure --with-php-config=/usr/local/php/bin/php-config
    [root@centos6 openssl]# make && make install 
    [root@centos6 openssl]# vim /usr/local/php/etc/php.ini
    添加:extension=openssl.so
    [root@centos6 openssl]# /etc/init.d/httpd restart

    pdo_mysql扩展

    [root@centos6 ~]# cd /usr/local/src/php-5.6.16/ext/pdo_mysql
    [root@centos6 pdo_mysql]# /usr/local/php/bin/phpize
    [root@centos6 pdo_mysql]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
    [root@centos6 pdo_mysql]# make && make install 
    # 此时出现 /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/说明编译安装成功
    [root@centos6 pdo_mysql]# /usr/local/php/etc/php.ini
    添加extension=pdo_mysql.so
    [root@centos6 pdo_mysql]# /etc/init.d/httpd restart

    curl扩展

    [root@centos6 ~]# cd /usr/local/src/php-5.6.16/ext/curl
    [root@centos6 curl]# /usr/local/php/bin/phpize
    [root@centos6 curl]# yum -y install curl-devel		# 安装curl的dev包
    [root@centos6 curl]# ./configure --with-php-config=/usr/local/php/bin/php-config [--with-curl=DIR(默认路径时无需指定)]
    [root@centos6 curl]# make && make install
    # 会在/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525生成curl.so文件
    [root@centos6 curl]# vim /usr/local/php/etc/php.ini
    添加如下extension=curl.so
    [root@centos6 curl]# /etc/init.d/httpd restart

    bcmath扩展[BC高精度函数库]

    [root@centos6 ~]# cd /usr/local/src/php-5.6.16/ext/bcmath
    [root@centos6 bcmath]# phpize
    [root@centos6 bcmath]# ./configure --with-php-config=/usr/local/php/bin/php-config
    [root@centos6 bcmath]# make 
    [root@centos6 bcmath]# make test
    [root@centos6 bcmath]# make install
    [root@centos6 bcmath]# vim /usr/local/php/etc/php.ini
    # 添加如下extension=bcmath.so
    [root@centos6 bcmath]# /etc/init.d/httpd restart
    

      

  • 相关阅读:
    PAT 甲级 1126 Eulerian Path (25 分)
    PAT 甲级 1126 Eulerian Path (25 分)
    PAT 甲级 1125 Chain the Ropes (25 分)
    PAT 甲级 1125 Chain the Ropes (25 分)
    PAT 甲级 1124 Raffle for Weibo Followers (20 分)
    PAT 甲级 1124 Raffle for Weibo Followers (20 分)
    PAT 甲级 1131 Subway Map (30 分)
    PAT 甲级 1131 Subway Map (30 分)
    AcWing 906. 区间分组 区间贪心
    AcWing 907. 区间覆盖 区间贪心
  • 原文地址:https://www.cnblogs.com/xi-jie/p/11822045.html
Copyright © 2011-2022 走看看