LAMP搭建3:PHP安装

2023-01-31 01:01:19 lamp 搭建 安装

1.进入/usr/local/src/目录下载安装包PHP-5.4.36.tar.bz2

[root@Centos6 ~]# cd /usr/local/src

[root@CentOS6 src]# ls

php-5.4.36.tar.bz2

2.解压安装包

[root@CentOS6 src]# tar jxvf php-5.4.36.tar.bz2

[root@CentOS6 src]# echo $?

0

3.进入安装目录

[root@CentOS6 src]# cd php-5.4.36

4.配置安装选项

[root@CentOS6 php-5.4.36]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-Mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-Sockets --enable-exif --disable-ipv6

php编译安装中常见配置错误处理请参考:

(1)Http://www.poluoluo.com/jzxy/201505/364819.html

(2)http://blog.sina.com.cn/s/blog_75a07c3b0101kcwb.html

错误1:configure: error: Cannot find OpenSSL's <evp.h>

解决:[root@CentOS6 php-5.4.36]# yum install -y openssl openssl-devel

错误2:configure: error: Please reinstall the BZip2 distribution

解决:[root@CentOS6 php-5.4.36]# yum install bzip2 bzip2-devel

错误3:configure: error: jpeglib.h not found.

解决:[root@CentOS6 php-5.4.36]# yum -y install libjpeg-devel

错误4:configure: error: png.h not found.

解决:[root@CentOS6 php-5.4.36]# yum -y install libpng-devel

错误5:configure: error: freetype-config not found.

解决:[root@CentOS6 php-5.4.36]# yum -y install freetype-devel

错误6:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决:由于centos官方源中没有libmcrypy-devel这个包,我们需要安装一个工具epel,然后再安装libmcrypy-devel。

[root@CentOS6 php-5.4.36]# rpm -ivh 'http://www.lishiming.net/data/p_w_upload/forum/epel-release-6-8_32.noarch.rpm'

[root@CentOS6 php-5.4.36]# yum list |grep -i mcrypt

libmcrypt.i686                              2.5.8-9.el6                  epel

libmcrypt-devel.i686                        2.5.8-9.el6                  epel

libtomcrypt.i686                            1.17-21.el6                  epel

libtomcrypt-devel.i686                      1.17-21.el6                  epel

libtomcrypt-doc.noarch                      1.17-21.el6                  epel

mcrypt.i686                                 2.6.8-10.el6                 epel

php-mcrypt.i686                             5.3.3-5.el6                  epel

[root@CentOS6 php-5.4.36]# yum install -y libmcrypt-devel

直到配置全部正确:

[root@CentOS6 php-5.4.36]# echo $?

0

5.编译:

[root@CentOS6 php-5.4.36]# make

[root@CentOS6 php-5.4.36]# echo $?

0

6.安装:

[root@CentOS6 php-5.4.36]# make install

[root@CentOS6 php-5.4.36]# echo $?

0

7.查看安装结果:

[root@CentOS6 php-5.4.36]# ls /usr/local/php/

bin  etc  include  lib  php

8.将php加入系统环境变量:

[root@CentOS6 support-files]# vim /etc/profile.d/path.sh

#!/bin/bash

export PATH=$PATH:/etc/init.d/:/usr/local/mysql/bin/:/usr/local/apache2/bin/:/usr/local

/php/bin/

[root@CentOS6 support-files]# source /etc/profile.d/path.sh

9.测试PHP

[root@CentOS6 php-5.4.36]# php -m # -m选项查看php的静态模块

[root@CentOS6 php-5.4.36]# php -i # -i选项列出php配置的详细信息,包括模块的

部分配置选项说明:

[root@CentOS6 php-5.4.36]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6

--with-apxs2 帮助安装动态模块的工具

[root@CentOS6 php-5.4.36]# ls /usr/local/apache2/modules/

httpd.exp  libphp5.so  mod_deflate.so  mod_expires.so  mod_rewrite.so

Apache目录下多了一个动态模块libphp5就是apxs的功劳

--with-mysql 说明php依赖MySQL,所以才先安装MySQL


相关文章