编译php 加mysql_linux下为已经编译好的php环境添加mysql扩展(php安装完成后如何添加mysql扩展)...

本文介绍了在Linux系统中,如何在已经编译安装的PHP环境中,手动编译并添加MySQL扩展。详细步骤包括下载PHP源码,使用phpize工具,配置并编译安装,以及解决编译过程中的常见错误和依赖问题。
摘要由CSDN通过智能技术生成

下载解压

# wget  http://cn2.php.net/distributions/php-5.6.30.tar.gz

# tar zxvf php-5.6.30.tar.gz

# cd php-5.6.30

配置

#./configure --prefix=/usr/local/php \

--with-curl \

--with-freetype-dir \

--with-gd \

--with-gettext \

--with-iconv-dir \

--with-kerberos \

--with-libdir=lib64 \

--with-libxml-dir \

--with-mysqli \

--with-jpeg-dir \

--with-openssl \

--with-pcre-regex \

--with-pdo-mysql \

--with-pdo-sqlite \

--with-pear \

--with-png-dir \

--with-xmlrpc \

--with-xsl \

--with-zlib \

--enable-fpm \

--enable-bcmath \

--enable-libxml \

--enable-inline-optimization \

--enable-gd-native-ttf \

--enable-mbregex \

--enable-mbstring \

--enable-opcache \

--enable-pcntl \

--enable-shmop \

--enable-soap \

--enable-sockets \

--enable-sysvsem \

--enable-xml \

--enable-zip

编译安装

配置成功后继续完成编译安装php

# make && make install

2.cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm还可以做成服务

复制php-fpm文件到php安装目录

# cp -R ./sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf

拷贝php.ini文件

安装目录有2个文件:php.ini-development和php.ini-production

注意php.ini-production拥有较高的安全性设定,则适合上线当产品使用

# cp php.ini-development /usr/local/php/lib/php.ini

或者

# cp php.ini-production /usr/local/php/lib/php.ini

如果遇到

-bash: /etc/init.d/php-fpm: Permission denied

解决方法 chmod 755 /etc/init.d/php-fpm

/etc/init.d/php-fpm start

/sbin/chkconfig --add php-fpm (添加到开机服务列表)

/sbin/chkconfig php-fpm on

linux下如何执行PHP脚本

为简化输入可把此php执行程序 copy 到系统命令目录下:

验证:输入以下命令,如正确获取 php 版本,说明操作成功。

这样,以后再执行PHP脚本时可直接采用以下输入方式即可。

问题背景

平常我们都是先安装mysql,然后才能去安装php。假如先安装php,后安装mysql,由于php需要连接mysql,因而在php引擎中需要配置使用mysql.so扩展。这时需要手动编译生成mysql.so扩展。

解决方案

使用phpize工具能够生成mysql.so,但是必须加上"--with-mysql=mysql客户端的路径"。也就是mysql.so模块必须用到mysql客户端才行。

可以这样理解,mysql.so内部会调用mysql客户端,以便实现连接mysql数据库服务器。

我们常常用到的mysql_connect()可能就是调用了mysql客户端才能完成连接数据库的操作。

实践生成mysql.so的过程

大体思路:需要用到php的源码包才行。通过源码包中提供的phpize文件(一个专门挂接php扩展的工具),phpize的规则:去哪个目录下运行phpize文件,那么就会在该目录下生成一个configure文件。

具体的安装步骤如下

php安装完成后添加mysql扩展基本步骤如下:

1、进入php源代码目录:

[root@localhost /]# # cd cd /usr/local/php-5.3.28

2、再进入要添加的mysql扩展源码目录:

[root@localhost php-5.3.28]cd ext/mysql/

[root@localhost mysql]# yum install autoconf (CentOS 5.4需安装)

3、调用已经编译好的php可执行程序phpize:

[root@localhost mysql] /usr/local/php/bin/phpize

4、然后configure:

[root@localhost mysql]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysql=/usr/local/mysql/ --with-zlib-dir=/usr/local/lib

注意:

/usr/local/mysql 为mysql的安装目录

/usr/local/lib/php/extensions/no-debug-non-zts-20090626/ 为php扩展的动态库存放目录

5、编译安装

[root@localhost mysql]#make

[root@localhost mysql]#make install

6、编译完成之后,将会自动把mysql.so放到了默认的php扩展目录下(phpinfo可查看,我的为 /usr/local/php/lib/php/extensions/no-debug-zts-20090626),再修改php.ini,去掉;extension=mysql.so前面的分号。如果没有这句,需要自行添加。

不过有一点需要注意的是,生成的模块名叫mysql.so,跟php.ini里面的php_mysql.so名字不一致,必须把mysql.so改名为php_mysql.so,也可修改php.ini中的文件名,总之文件名必须一致.'./configure' '--prefix=/usr/local/php' '--with-curl' '--with-freetype-dir' '--with-gd' '--with-gettext' '--with-iconv-dir' '--with-kerberos' '--with-libdir=lib64' '--with-libxml-dir' '--with-mysqli' '--with-openssl' '--with-pcre-regex' '--with-pdo-mysql' '--with-pdo-sqlite' '--with-pear' '--with-png-dir' '--with-jpeg-dir' '--with-xmlrpc' '--with-xsl' '--with-zlib' '--with-bz2' '--with-mhash' '--enable-fpm' '--enable-bcmath' '--enable-libxml' '--enable-inline-optimization' '--enable-gd-native-ttf' '--enable-mbregex' '--enable-mbstring' '--enable-opcache' '--enable-pcntl' '--enable-shmop' '--enable-soap' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-xml' '--enable-zip'

PHP的安装虽然有时候很简单,可是如果应用一多,我们安装起来就很头痛了!出错最多的就是安装PHP扩展的时候了。其实不管是你是Apache类的应用还是Nginx类的,PHP的安装都不是很简单,虽然网上有很多configure参数,但是那不一定是适合你的,因为很多都直接关系着你的系统版本和内核。因此要自己亲自不断的调试,才能完全安装成功。

本文总结了一些常见的configure错误信息和解决这些错误的经验。

网上有的说法是:–with-named-curses-libs=/usr/lib/libncursesw.so.5

其实是不对的,虽然能解决configure的错误,但是make的时候会提示错误,正确的做法应该是

centos: yum -y install ncurses-devel

debian: apt-get install libncurses5-dev

2、configure: error: xml2-config not found. Please check your libxml2 installation.

centos: yum -y install libxml2 libxml2-devel

debian: apt-get install libxml2-dev

3、configure: error: Cannot find OpenSSL’s

centos: yum -y install openssl-devel

4、configure: error: libjpeg.(a|so) not found

centos: yum -y install gd

centos: yum -y install gd-devel

debian: apt-get install libjpeg-dev

5、configure: error: libpng.(a|so) not found.

apt-get install libpng12-dev

6、configure: error: cannot find output from lex; giving up

yum -y install flex

7、configure: error: mod_deflate has been requested but can not be built due to prerequisite failures

centos: yum -y install zlib-devel openssl-devel

debian: apt-get install zlib1g-dev

8、configure: error: libxpm.(a|so) not found.

centos: yum -y install libxpm-dev

debian: apt-get install libxpm-dev

9、configure: error: freetype.h not found.

centos: yum install freetype-devel

debian: apt-get install libfreetype6-dev

10、configure: error: …No recognized SSL/TLS toolkit detected

centos: yum -y install libssl-dev

debian: apt-get install libssl-dev

11、Configure: error: Please reinstall the BZip2 distribution

centos: yum install bzip2 bzip2-devel

debian: apt-get install bzip2-devel

12、Configure: error: Please reinstall the libcurl distribution – easy.h should be in /include/curl/

centos: yum install curl curl-devel (For Redhat & Fedora)

# install libcurl4-gnutls-dev (For Ubuntu)

13、Configure: error: Unable to locate gmp.h

centos: yum install gmp-devel

14、Configure: error: Cannot find MySQL header files under /usr. Note that the MySQL client library is not bundled anymore!

yum install mysql-devel (For Redhat & Fedora)

# apt-get install libmysql++-dev (For Ubuntu)

15、Configure: error: Please reinstall the ncurses distribution

Solutions :

centos: yum install ncurses ncurses-devel

16、Checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!

Solutions :

centos: yum install unixODBC-devel

17、Configure: error: Cannot find pspell

Solutions :

centos: yum install pspell-devel

18、configure: error: mcrypt.h not found. Please reinstall libmcrypt.

Solutions :

yum install libmcrypt libmcrypt-devel (For Redhat & Fedora)

# apt-get install libmcrypt-dev

19、Configure: error: snmp.h not found. Check your SNMP installation.

Solutions :

yum install net-snmp net-snmp-devel

20、开启LDAP服务还需要

yum -y install openldap-devel openldap-servers openldap-clients

21、configure: error: cannot find output from lex; giving up

centos: yum -y install flex

22、configure: error: mod_deflate has been requested but can not be built due to prerequisite failures

centos: yum -y install zlib-devel openssl-devel

debian: apt-get install zlib1g-dev

来源:https://www.cnblogs.com/vania/p/7081296.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值