PHP安装中遇到的一个问题

PHP也装过很多次了,但每次都会遇到新问题。

编译参数是这样的

./configure \
--prefix=/usr/local/php \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sqlite-utf8 \
--enable-zip \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-bz2 \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-gmp \
--with-jpeg-dir \
--with-libxml-dir \
--with-mcrypt \
--with-mhash \
--with-mysql-sock=/tmp/mysql.sock \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-unixODBC=/usr/lib/odbc \
--with-openssl \
--with-openssl-dir \
--with-pdo-mysql \
--with-png-dir \
--with-pspell \
--with-snmp \
--with-t1lib \
--with-tidy \
--with-ttf \
--with-xpm-dir \
--with-zlib \
--with-zlib-dir \

编译环境及软件依赖都配置好了之后,configure也没有问题,make时候报错了,如下:

ext/mysqli/.libs/mysqli_repl.o: In function `zif_mysqli_disable_reads_from_master':
/usr/local/src/php-5.2.14/ext/mysqli/mysqli_repl.c:44: undefined reference to `mysql_disable_reads_from_master'
ext/mysqli/.libs/mysqli_repl.o: In function `zif_mysqli_disable_rpl_parse':
/usr/local/src/php-5.2.14/ext/mysqli/mysqli_repl.c:60: undefined reference to `mysql_disable_rpl_parse'
ext/mysqli/.libs/mysqli_repl.o: In function `zif_mysqli_enable_reads_from_master':
/usr/local/src/php-5.2.14/ext/mysqli/mysqli_repl.c:77: undefined reference to `mysql_enable_reads_from_master'
ext/mysqli/.libs/mysqli_repl.o: In function `zif_mysqli_enable_rpl_parse':
/usr/local/src/php-5.2.14/ext/mysqli/mysqli_repl.c:94: undefined reference to `mysql_enable_rpl_parse'
ext/mysqli/.libs/mysqli_repl.o: In function `zif_mysqli_master_query':
/usr/local/src/php-5.2.14/ext/mysqli/mysqli_repl.c:112: undefined reference to `mysql_master_query'
ext/mysqli/.libs/mysqli_repl.o: In function `zif_mysqli_rpl_parse_enabled':
/usr/local/src/php-5.2.14/ext/mysqli/mysqli_repl.c:131: undefined reference to `mysql_rpl_parse_enabled'
ext/mysqli/.libs/mysqli_repl.o: In function `zif_mysqli_rpl_probe':
/usr/local/src/php-5.2.14/ext/mysqli/mysqli_repl.c:148: undefined reference to `mysql_rpl_probe'
ext/mysqli/.libs/mysqli_repl.o: In function `zif_mysqli_rpl_query_type':
/usr/local/src/php-5.2.14/ext/mysqli/mysqli_repl.c:169: undefined reference to `mysql_rpl_query_type'
ext/mysqli/.libs/mysqli_repl.o: In function `zif_mysqli_slave_query':
/usr/local/src/php-5.2.14/ext/mysqli/mysqli_repl.c:208: undefined reference to `mysql_slave_query'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

在安装mysqli扩展的时候编译出错了,这个问题在google上也没有找到有用的解决办法,苦寻无果之后在编译参数中去掉了mysqli的参数,改成下面这样

root@CESC:/usr/local/src/php-5.2.14# more php5.sh 
./configure \
--prefix=/usr/local/php \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sqlite-utf8 \
--enable-zip \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-bz2 \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-gmp \
--with-jpeg-dir \
--with-libxml-dir \
--with-mcrypt \
--with-mhash \
--with-mysql-sock=/tmp/mysql.sock \
--with-mysql=/usr/local/mysql \
--with-unixODBC=/usr/lib/odbc \
--with-openssl \
--with-openssl-dir \
--with-pdo-mysql \
--with-png-dir \
--with-pspell \
--with-snmp \
--with-t1lib \
--with-tidy \
--with-ttf \
--with-xpm-dir \
--with-zlib \
--with-zlib-dir \

再make就可以通过了。

装好之后再按照下面办法单独把mysqli编译进去

安装mysqli扩展
cd /usr/local/src/php-5.2.14/ext/mysqli/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-mysqli=/usr/local/mysql/bin/mysql_config
make
make install

上面的操作会在extension_dir目录下生成mysqli.so文件

root@CESC:/usr/local/php/lib/php/extensions/no-debug-zts-20060613# ls 
mysqli.so

extension_dir需要在php.ini中设置正确

; Directory in which the loadable extensions (modules) reside.
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20060613/"

在php.ini中打开mysqli扩展支持

extension=mysqli.so

使用下面命令可以看到已经加上了mysqli的支持

root@CESC:~# /usr/local/php/bin/php -m|grep mysql
mysql
mysqli
pdo_mysql

重启apache,访问info.php再确认下。

这个问题花了大概得三个小时时间,刚开始有点钻牛角尖了,最后换了个思路很快解决了。

安装zabbix2.2.5+php5.5+mysql5.5.9+nginx1.5.1

先安装php,nginx和mysql
php编译参数:

./configure \
–prefix=/usr/local/php5 \
–with-bz2 \
–with-curl \
–enable-ftp \
–enable-sockets \
–enable-bcmath \
–disable-ipv6 \
–with-gd \
–with-jpeg-dir=/usr/local \
–with-png-dir=/usr/local \
–with-freetype-dir=/usr/local \
–enable-gd-native-ttf \
–with-iconv-dir=/usr/local \
–enable-mbstring \
–enable-calendar \
–with-gettext \
–with-libxml-dir=/usr/local \
–with-zlib \
–with-pdo-mysql=mysqlnd \
–with-mysqli=mysqlnd \
–with-mysql=mysqlnd \
–enable-dom \
–enable-xml \
–enable-fpm \
–with-libdir=lib64

 

php装好之后需要修改php.ini为以下值,以满足zabbix安装需要

max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone PRC

nginx编译参数

./configure –prefix=/usr/local/nginx –add-module=/usr/local/src/nginx_upstream_check_module-master –with-http_stub_status_module –with-http_ssl_module –with-http_realip_module –with-http_sub_module –with-http_gzip_static_module –with-http_flv_module –with-http_dav_module –with-http_spdy_module –with-pcre –with-debug

 
mysql安装略过 安装zabbix
注意:zabbix只使用普通用户运行,如果在root环境下运行zabbix,那么zabbix将会主动使用zabbix用户来运行。

groupadd zabbix&&useradd -g zabbix zabbix
cd /usr/local/src/
wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.5/zabbix-2.2.5.tar.gz
tar -zxvf zabbix-2.2.5.tar.gz
cd /usr/local/src/zabbix-2.2.5
./configure –prefix=/usr/local/zabbix/ –enable-server –enable-agent –with-mysql –with-net-snmp –with-libcurl –with-libxml2
make&&make install

 

复制前端文件到主目录

cp -r /usr/local/src/zabbix-2.2.5/frontends/php/* /usr/local/nginx/html/zabbix/

 

修改nginx虚拟主机配置

server {
        listen       80;
        server_name  zabbix.abc.com;
        access_log  /usr/local/nginx/logs/zabbix.abc.com.log  main;

        index         index.html index.htm index.php;
        root         /usr/local/nginx/html/zabbix;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location ~ ^(.+.php)(.*)$ {
                fastcgi_split_path_info ^(.+.php)(.*)$;
                include fastcgi.conf;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param  PATH_INFO          $fastcgi_path_info;
        }
}

 
访问http://zabbix.abc.com开始配置

安装zabbix客户端

groupadd zabbix&&useradd -g zabbix zabbix
cd /usr/loca/src/
wget http://www.zabbix.com/downloads/2.2.5/zabbix_agents_2.2.5.linux2_6.amd64.tar.gz
mkdir /usr/local/zabbix_agent
tar -zxvf zabbix_agents_2.2.5.linux2_6.amd64.tar.gz -C /usr/local/zabbix_agent/
cd /usr/local/zabbix_agent/&&mkdir logs
chown -R zabbix:zabbix/usr/local/zabbix_agent

 

修改客户端配置文件

# vi /usr/local/zabbix_agent/conf/zabbix_agentd.conf

LogFile=/usr/local/zabbix_agent/logs/zabbix_agentd.log
Server=192.168.0.1
ServerActive=192.168.0.1
Hostname=Zabbix server

 

注意:Server和ServerActive都是指定zabbixserver的IP地址,Server是用来允许192.168.0.1来客户端取数据。而serverActive的192.168.0.1的意思是,客户端主动提交数据给服务器端 启动客户端

/usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.conf

检查是否正常启动

netstat -nlp|grep 10050

 

写一个客户端启动脚本链接到/etc/init.d/目录下

# more /etc/init.d/zabbix_agentd_srv
 
#!/bin/bash
# chkconfig: 345 20 80
# description: zabbix_agentd auto start-stop script.

case "$1" in

start)
echo "Starting zabbix_agentd ... "
/usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.conf
;;

stop)
echo "Stopping zabbix_agentd ... " 
/usr/bin/killall zabbix_agentd 
;;

restart)
$0 stop
sleep 2
$0 start
;;

*)
echo "Usage: $0 {start|stop|restart}" 
exit 1
esac