注册 登录

清河洛

LAMP环境源码安装②PHP源码安装

qingheluo2016-12-17清河洛367
php源码安装:安装php时的配置:./configure --prefix=/usr/local/php5.5 --with-config-file-path=/usr/local/php5.5/lib \--with-apxs2=/usr/local/httpd2/bin/apxs \--with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd \--with-freetype-dir --with-gd --with-zlib --with-libxml-dir \--with-jpeg-dir --with...

php源码安装:安装php时的配置:

./configure --prefix=/usr/local/php5.5 --with-config-file-path=/usr/local/php5.5/lib \

--with-apxs2=/usr/local/httpd2/bin/apxs \

--with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd \

--with-freetype-dir --with-gd --with-zlib --with-libxml-dir \

--with-jpeg-dir --with-png-dir --enable-mbstring --enable-bcmath \

--enable-sockets --enable-mbregex --with-iconv-dir --with-curl \

--enable-shared --with-mcrypt --with-mhash --with-bz2

--with-config-file-path:设置配置文件存放位置

--with-apxs2:让apache支持php,为apache生成php模块并自动修改httpd.conf配置文件,使其引入php模块

--with-mysql --with-pdo-mysql --with-mysqli

这三项如果指定了mysql安装路径那么连接mysql时使用mysql官方自带的libmysql驱动,当这三项的值都设置为mysqlnd,那么就会使用php自带的mysqlnd驱动,libmysql驱动是比较老的驱动, PHP 5.3开始已经建议使用mysqlnd.

使用mysqlnd首先规避了许可协议和版权的问题,由为mysqlnd内置于PHP源代码,所以在编译安装php时就不需要预先安装mysql server也可以,另外最重要的是,mysqlnd是专门为php优化编写的驱动,它使用了PHP本身的特性,在内存管理,性能上比libmysql更有优势,引入特有的函数mysqli_fetch_all()和一些性能统计函数mysqli_get_cache_stats(), mysqli_get_client_stats(), mysqli_get_connection_stats(),等,另外SSL支持、压缩协议支持、命名管道支持、增强的持久连接等都是mysqlnd所特有的。

--enable-mbstring :开启多字节字符串的支持

--enable-bcmath :启用bcmatch(高精度数学运算)

--enable-sockets :网络编程接口。它包含大量的库函数

--enable-mbregex :多字节正则表达式的支持

--with-iconv-dir=DIR :开启对转换字符编码的支持

--with-mcrypt=DIR :加密扩展库Mcrypt

--with-mhash=DIR :支持哈希计算

安装完成以后需要手动把php.ini复制到php安装目录下的lib目录下,php.ini文件可以在php的源码包里面找到,5.4版本之前是php.ini-dist(开发测试版本)和php.ini-recommended(线上生产版本)文件,5.4版本之后是php.ini-development(开发测试版本)和php.ini-production(线上生产版本)

最后还需要配置apache使其支持php,打开apache的配置文件,在配置文件中的标签中间增加

AddType application/x-httpd-php .php

让apache遇到php文件时调用php模块解释执行。

编译安装php以后添加新的模块(以添加redis模块为例):

当我们安装好php之后可能会忘记装一些模块,或者需要增加模块的时候我们可以使用php自带的phpize命令安装

假如已经安装好的php的安装目录为:/usr/local/php/

使用/usr/local/php/bin/php -m查看当前php加载了哪些模块

扩展模块的安装步骤(我们以安装redis-5.0.2模块为例):

一、下载模块的源码,解压并且进入到解压目录下

    tar -zxvf redis-5.0.2.tgz
    cd redis-5.0.2/

二、在模块的源码目录中使用phpize命令生成configure文件:/usr/local/php/bin/phpize

三、编译并使用make命令安装

    ./configure --with-php-config=/usr/local/php/bin/php-config
    make && make instlll
    Installing shared extensions:    /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
    最后的提示表示扩展模块的安装目录,即编译过的so模块文件的存放目录

四、在php.ini配置文件中添加一行extension=redis.so

五、重启php-fpm即可完成模块的安装

附:网络上查找的一个php7.0安装配置

yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

./configure \<br />
--prefix=/usr/local/php \<br />
--with-config-file-path=/etc \<br />
--enable-fpm \<br />
--with-fpm-user=nginx \<br />
--with-fpm-group=nginx \<br />
--enable-inline-optimization \<br />
--disable-debug \<br />
--disable-rpath \<br />
--enable-shared \<br />
--enable-soap \<br />
--with-libxml-dir \<br />
--with-xmlrpc \<br />
--with-openssl \<br />
--with-mcrypt \<br />
--with-mhash \<br />
--with-pcre-regex \<br />
--with-sqlite3 \<br />
--with-zlib \<br />
--enable-bcmath \<br />
--with-iconv \<br />
--with-bz2 \<br />
--enable-calendar \<br />
--with-curl \<br />
--with-cdb \<br />
--enable-dom \<br />
--enable-exif \<br />
--enable-fileinfo \<br />
--enable-filter \<br />
--with-pcre-dir \<br />
--enable-ftp \<br />
--with-gd \<br />
--with-openssl-dir \<br />
--with-jpeg-dir \<br />
--with-png-dir \<br />
--with-zlib-dir \<br />
--with-freetype-dir \<br />
--enable-gd-native-ttf \<br />
--enable-gd-jis-conv \<br />
--with-gettext \<br />
--with-gmp \<br />
--with-mhash \<br />
--enable-json \<br />
--enable-mbstring \<br />
--enable-mbregex \<br />
--enable-mbregex-backtrack \<br />
--with-libmbfl \<br />
--with-onig \<br />
--enable-pdo \<br />
--with-mysqli=mysqlnd \<br />
--with-pdo-mysql=mysqlnd \<br />
--with-zlib-dir \<br />
--with-pdo-sqlite \<br />
--with-readline \<br />
--enable-session \<br />
--enable-shmop \<br />
--enable-simplexml \<br />
--enable-sockets \<br />
--enable-sysvmsg \<br />
--enable-sysvsem \<br />
--enable-sysvshm \<br />
--enable-wddx \<br />
--with-libxml-dir \<br />
--with-xsl \<br />
--enable-zip \<br />
--enable-mysqlnd-compression-support \<br />
--with-pear \<br />
--enable-opcache

make && make install

配置环境变量vim /etc/profile在末尾追加export PATH=/usr/local/php/bin:$PATH

执行命令使得改动立即生效source /etc/profile

配置php-fpm

需要在安装软件包目录

cp php.ini-production /etc/php.ini

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm

启动php-fpm

/etc/init.d/php-fpm start



网址导航