CentOS6.6 x64+Nginx1.3.8/Apache-httpd 2.4.3+PHP5.4.8(php-fpm)+MySQL5.5.28+CoreSeek4.1源码编译安装

系统为CentOS6.6 x64服务器版精简安装。

准备工作

  部署安装目录 

  /usr/local/* 

  /var/lib/*

    /var/lib64/*



下载源文件

#cd /usr/local/src 

wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.28.tar.gz

wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.10.tar.gz

wget http://www.nginx.org/download/nginx-1.3.8.tar.gz

wget http://cl1.php.net/distributions/php-5.4.8.tar.gz

wget http://acelnmp.googlecode.com/files/eaccelerator-0.9.6.1.tar.bz2

wget http://google-perftools.googlecode.com/files/google-perftools-1.8.3.tar.gz

wget http://mynginx.googlecode.com/files/ImageMagick.tar.gz

wget http://lnmpp.googlecode.com/files/imagick-2.3.0.tgz

wget http://mozbuildtools.googlecode.com/files/libiconv-1.13.1.tar.gz

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz        http://www.gnu.org/software/libiconv/

wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz

wget http://vps.googlecode.com/files/memcache-2.2.5.tgz

wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz

wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

wget http://sourceforge.net/projects/pcre/files/pcre/8.31/pcre-8.31.tar.gz

wget http://vps.googlecode.com/files/PDO_MYSQL-1.0.2.tgz

wget http://nchc.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.5.2.2/phpMyAdmin-3.5.2.2-all-languages.tar.gz

php myadmin官网:http://www.phpmyadmin.net/home_page/index.php

wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.3.tar.gz

wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.4.tar.gz

apache下载http://httpd.apache.org/download

wget http://mirror.bit.edu.cn/apache/apr/apr-1.4.6.tar.gz                 #Apache库文件

wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.4.1.tar.gz          #Apache库文件

wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz

wget http://museum.php.net/php5/php-5.2.17.tar.gz

wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz                          #官网http://php-fpm.org/downloads/

wget http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.gz              #XCache,官网http://xcache.lighttpd.net

wget http://down1.chinaunix.net/distfiles/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz

wget http://www.openssl.org/source/openssl-1.0.1i.tar.gz                  #openssl-1.0.1i

wget http://pecl.php.net/get/imagick-3.1.2.tgz


最小化安装(minimal)需安装的基本软件


yum install -y bind-utils traceroute wget man sudo ntp ntpdate screen patch make gcc gcc-c++ flex bison zip unzip ftp --skip-broken 


安装相关库

配置yum只安装64位软件,即过滤掉 i386, i686 的软件包

# vi /etc/yum.conf      在[main]最后添加如下内容

exclude=*.i?86 


如果想删除系统上已经安装的 i386/i686 包:


# yum remove \*.i\?86 -y                       #不建议,容易出现问题


yum -y install kernel-devel-* gcc kernel-headers-* --skip-broken

yum -y install yum-fastestmirror --skip-broken

yum -y install patch make gcc gcc-c++ flex bison --skip-broken

yum -y install libtool libtool-libs kernel-devel autoconf --skip-broken

yum -y install libjpeg libjpeg-devel libpng libpng-devel gd-devel libtiff libtiff-devel tcl-devel ghostscript-devel fontconfig-devel libwmf-devel jasper jasper-devel --skip-broken

yum -y install freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel --skip-broken

yum -y install glib2 glib2-devel bzip2 diff* --skip-broken

yum -y install bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs --skip-broken 

yum -y install e2fsprogs-devel krb5 krb5-devel libidn libidn-devel --skip-broken

yum -y install openssl openssl-devel vim-minimal --skip-broken

yum -y install cmake --skip-broken

yum -y install openldap openldap-devel --skip-broken


yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel  freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel  glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel  e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl  openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers  make  --skip-broken

yum -y update


(也可用

yum -y install make apr* autoconf automake gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch --skip-broken

)

关联动态库 

# vi /etc/ld.so.conf                         添加如下内容

include /etc/ld.so.conf.d/*.conf

/usr/local/lib

/usr/local/lib64

/lib

/lib64

/usr/lib

/usr/lib64


编辑完ld.so.conf,执行 

# ldconfig 

使动态库生效


安装pcre

#cd /usr/local/src

tar -zxvf pcre-8.35.tar.gz

cd pcre-8.35

./configure --enable-jit; make; make install

注:如果想卸载系统原来的PCRE,请先备份PCRE库libpcrecpp.so.0、libpcre.so.0.0.1,

可以用rpm -ql pcre查找它的路径

]# rpm -ql pcre

/lib64/libpcre.so.0

/lib64/libpcre.so.0.0.1

/usr/bin/pcregrep

/usr/bin/pcretest

/usr/lib64/libpcrecpp.so.0

/usr/lib64/libpcrecpp.so.0.0.0

/usr/lib64/libpcreposix.so.0

/usr/lib64/libpcreposix.so.0.0.0

/usr/share/doc/pcre-7.8

/usr/share/doc/pcre-7.8/AUTHORS

/usr/share/doc/pcre-7.8/COPYING

/usr/share/doc/pcre-7.8/ChangeLog

/usr/share/doc/pcre-7.8/LICENCE

/usr/share/doc/pcre-7.8/NEWS

/usr/share/doc/pcre-7.8/README

/usr/share/man/man1/pcre-config.1.gz

/usr/share/man/man1/pcregrep.1.gz

/usr/share/man/man1/pcretest.1.gz

最后yum -y remove pcre (或rpm -e pcre --nodeps)完后,再把它复制回原处,因为很多软件都依赖它,编译时也需要用到。


OpenSSLl-1.0.1i安装

cd /usr/local/src

tar -zxvf openssl-1.0.1i.tar.gz 

cd openssl-1.0.1i

 ./config; make; make install


I、LNMP

编译安装Nginx

添加一个不能登录且没有主目录的用户Nginx

#useradd nginx -M -s /sbin/nologin                     #此命令会同时添加一个组nginx,且用户nginx自动加入该组

cd /usr/local/src

tar -zxvf nginx-1.3.15.tar.gz; cd nginx-1.3.15

./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35 --with-http_realip_module --with-http_image_filter_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1i


注意:--with-pcre=/usr/local/src/pcre-8.35指向的是源码包解压的路径,而不是安装的路径,否则会报错

若是使用源码安装的 openssl(./configure;make;make install),则在后面加上  --with-openssl=/usr/local/src/openssl-1.0.1i    即openssl源码解压出来的路径

添加 --with-openssl-opt="enable-tlsext" 这个参数可支持 同一个IP上配置多个HTTPS主机


make && make install

/usr/local/nginx/sbin/nginx                      #启动nginx


添加ngxin到系统服务,设置nginx开启启动

vi /etc/rc.d/init.d/nginx                    #编辑启动文件添加下面内容

=======================================================

#!/bin/bash

# nginx Startup script for the Nginx HTTP Server

# it is v.0.0.2 version.

# chkconfig: - 85 15

# description: Nginx is a high-performance web and proxy server.

# It has a lot of features, but it's not for everyone.

# processname: nginx

# pidfile: /var/run/nginx.pid

# config: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx

nginx_config=/usr/local/nginx/conf/nginx.conf

nginx_pid=/usr/local/nginx/logs/nginx.pid

RETVAL=0

prog="nginx"

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "${NETWORKING}" = "no" ] && exit 0

[ -x $nginxd ] || exit 0

# Start nginx daemons functions.

start() {

if [ -e $nginx_pid ];then

echo "nginx already running...."

exit 1

fi

echo -n $"Starting $prog: "

daemon $nginxd -c ${nginx_config}

RETVAL=$?

echo

[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx

return $RETVAL

}

# Stop nginx daemons functions.

stop() {

echo -n $"Stopping $prog: "

killproc $nginxd

RETVAL=$?

echo

[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid

}

reload() {

echo -n $"Reloading $prog: "

#kill -HUP `cat ${nginx_pid}`

killproc $nginxd -HUP

RETVAL=$?

echo

}

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

reload)

reload

;;

restart)

stop

start

;; 


status)

status $prog

RETVAL=$?

;;

*)

echo $"Usage: $prog {start|stop|restart|reload|status|help}"

exit 1

esac

exit $RETVAL

=======================================================

:wq!              #保存退出

chmod 755 /etc/rc.d/init.d/nginx              #赋予文件执行权限

chkconfig nginx on                   #设置开机启动

/etc/rc.d/init.d/nginx restart                   #重启

service nginx restart


当然Nginx也可以用yum安装

添加nginx yum repository库

vi  /etc/yum.repos.d/nginx.repo           #新建nginx yum库,并添加下面的内容

=======================================================

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

gpgcheck=0

enabled=1

=======================================================

wq       #保存退出

yum -y install nginx                    #yum安装nginx,这里安装的为nginx官网稳定版,不一定是最新版


nginx.conf  调优配置:

在http {} 里添加

        fastcgi_connect_timeout 60;

        fastcgi_send_timeout 180;

        fastcgi_read_timeout 180;

        fastcgi_buffers 4 256k;

        fastcgi_buffer_size 128k;

        fastcgi_busy_buffers_size 256k;

        fastcgi_temp_file_write_size 256k;

        fastcgi_intercept_errors on;

        client_max_body_size 200M;        #最大上传文件大小

        gzip  on;

为不让nginx.conf的配置文件变得臃肿庞大,把各个虚拟主机的配置单独使用各自文件

vi /var/local/nginx/conf/nginx.conf #在到数第二添加一行如下内容(;号不能少),指定包含虚拟主机配置文件:

include /usr/local/nginx/conf/conf.d/*.conf;

vi /usr/local/nginx/conf/fastcgi_params #在最后添加如下内容,省去每个虚拟主机配置都要指定fastcgi_param SCRIPT_FILENAME文件。

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param  PHP_VALUE  "open_basedir=$document_root:/tmp/";            #这句的意思是限制

nginx访问在 本虚拟主机目录下,禁止跨目录

把Nginx主配置文件/usr/local/nginx/conf/nginx.conf中的下面一行注释掉,即在前面加一 #

#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

cd /var/local/nginx/conf

mkdir conf.d

在/var/local/nginx/conf/conf.d  下建立,xx.conf虚拟主机配置文件即可


编译安装MySQL

创建用户和用户组与赋予数据存放目录权限

# useradd mysql -M -s /sbin/nologin

#mkdir /var/lib/mysqldb                这里最好不要跟用mysql.rpm包安装的数据库目录 /var/lib/mysql 相同,以免造成麻烦

#chown -R mysql.mysql  /var/lib/mysqldb

cd /usr/local/src; tar -zxvf mysql-5.6.10.tar.gz; cd mysql-5.6.10

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysqldb -DSYSCONFDIR=/usr/local/mysql/etc/  -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_READLINE=on

make ; make install

cd /usr/local/mysql

cp ./support-files/my-huge.cnf /etc/my.cnf      #拷贝配置文件

(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可。

   如果是mysql-5.6.10,不需要操作此步,也就是不需要复制配置文件到 /etc/my.cnf,且这个版本/usr/local/mysql/support-files/目录下也只有my-default.cnf,即mysql-5.6.10版本的数据库配置文件是  /usr/local/mysql/my.cnf )


vi /etc/my.cnf               #编辑配置文件,在 [mysqld] 部分增加下面一行。注意:mysql-5.6.10把这一步留下面做

datadir = /var/lib/mysqldb                 #添加MySQL数据库路径

:wq!#保存退出    


(注意:mysql-5.6.10版本

vi  ./support-files/my-default.cnf            #在[mysqld] 加入以下两行

#bind-address=127.0.0.1

#port=32106

datadir=/var/lib/mysqldb

socket=/tmp/mysql.sock

skip-name-resolve

#忘记密码启用下面这行,skip-grant-tables

#skip-grant-tables


./scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysqldb           #生成mysql系统数据库,在/usr/local/mysql执行

(注意:mysql-5.6.10版本的执行完此命令后,会在/usr/local/mysql生成my.cnf文件,此时再修改 


vi /usr/local/mysql/my.cnf                #编辑配置文件,


在 [mysqld] 部分增加下面一行。


datadir = /var/lib/mysqldb                 #添加MySQL数据库路径)


cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld           #把Mysql加入系统启动

chmod 755 /etc/init.d/mysqld             #增加执行权限

chkconfig mysqld on                  #加入开机启动

vi /etc/rc.d/init.d/mysqld            #(编辑,其实这两个目录在./configure配置时就已经指定了,也可以不再此指定了,如果启动mysqld时出现


/etc/init.d/mysqld: line 46: /usr/local/mysql: is a directory

/etc/init.d/mysqld: line 47: /var/lib/mysqldb: is a directory

就不要加指定这两个目录)

basedir = /usr/local/mysql         #MySQL程序安装路径

datadir = /var/lib/mysqldb      #MySQl数据库存放目录

service mysqld start                    #启动,也可以执行 /usr/local/mysql/bin/mysqld_safe &  来启动,这种方式也可以让它随机启动,即vi /etc/rc.local 加入一行 /usr/local/mysql/bin/mysqld_safe &即可。


如果不行,请再重复  ./scripts/mysql_install_db --user=mysql      到此的步骤,mysql-5.6.10版本的请先删除 ./my.cnf,再重复以上步骤


配置库文件搜索路径


# echo "/usr/local/mysql/lib" >> /etc/ld.so.conf 

# ldconfig 

#echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile 

#source /etc/profile 


下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。


ln -s /usr/local/mysql/lib /usr/lib/mysql

ln -s /usr/local/mysql/include/mysql /usr/include/mysql


mysql_secure_installation              #设置Mysql密码

###################################################################


Enter current password for root (enter for none):                #直接回车,mysql root初始密码为空

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n] Y                      #是否设置root密码

New password:                                         #输入root要设置的新密码

Re-enter new password:                          #再次输入新密码

Password updated successfully!

Reloading privilege tables..

 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.


Remove anonymous users? [Y/n] Y        #是否删除mysql匿名anonymous用户


 ... Success!


Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.


Disallow root login remotely? [Y/n] Y          #是否禁止root远程登录

 ... Success!


By default, MySQL comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.


Remove test database and access to it? [Y/n] Y      #是否删除 test 数据库

 - Dropping test database...

 ... Success!


 - Removing privileges on test database...

 ... Success!


Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.


Reload privilege tables now? [Y/n] Y           #是否马上重载特权表

 ... Success!


Cleaning up...


All done!  If you've completed all of the above steps, your MySQL

installation should now be secure.


Thanks for using MySQL!

###################################################################


或者直接修改密码/usr/local/mysql/bin/mysqladmin -u root -p password "123456" #修改密码

mysql>UPDATE mysql.user SET Password = PASSWORD('newpwd') WHERE User = 'root';(生新设置密码)

mysql>flush privileges;(刷新权限)service mysqld restart #重启

到此,mysql安装完成!


 


问题1:

Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/Serv1-01.pid).

Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

查看日志 /var/lib/mysql/localhost.err

Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist


最终解决方法如下:

在mysql的安装目录下,我的是/usr/local/mysql

./scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysqldb

原因是重装的时候数据目录不一致导致

然后再次启动,OK

实在不行就在   /usr/local/mysql/support-files/my-default.cnf  文件的  [mysqld]  添加下面这行,再执行./scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysqldb

datadir = /var/lib/mysqldb  


问题2:Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysqldb/CentOS7.pid).

 mysql5.6.19

报这个错时,跟问题1很像,但却不是一样的,这里时候可以尝试用安全模式启动

/usr/local/mysql/bin/mysqld_safe &

然后会报错:

[1] 10593

[root@CentOS7 mysql]# 140831 13:10:13 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.

touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory

chmod: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory

touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory

chown: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory

140831 13:10:13 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysqldb

/usr/local/mysql/bin/mysqld_safe: line 129: /var/log/mariadb/mariadb.log: No such file or directory

/usr/local/mysql/bin/mysqld_safe: line 166: /var/log/mariadb/mariadb.log: No such file or directory

touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory

chown: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory

chmod: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory

140831 13:10:13 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended

/usr/local/mysql/bin/mysqld_safe: line 129: /var/log/mariadb/mariadb.log: No such file or directory


大致意思是说:无法创建日志文件

解决方法:mkdir /var/log/mariadb;touch /var/log/mariadb/mariadb.log;chown -R mysql:mysql /var/log/mariadb


问题3:Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 

解决方法:vi my.cnf   在 [mysqld]   一加下面这行

socket=/tmp/mysql.sock


允许root远程登录

在本机先使用root用户登录mysql: 

mysql -u root -p"youpassword" 

进行授权操作: 

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION; 

重载授权表: 

FLUSH PRIVILEGES; 

退出mysql数据库: 

exit


更新mysql用户密码:

>update mysql.user set password=password('新密码') where User="test" and Host="localhost"; 

删除mysql用户及权限

mysql>Delete FROM user Where User='test' and Host='localhost'; 

 mysql>flush privileges;

 mysql>drop database testDB; //删除用户的数据库

删除账户及权限:>drop user 用户名@'%';

        >drop user 用户名@ localhost;


调优设置,vi   my.conf

#调优

#指定MySQL可能的连接数量

back_log = 512

#缓冲innodb池大小

innodb_buffer_pool_size = 2048M

innodb_log_file_size = 512M

innodb_log_buffer_size =16M

thread_stack = 256K

sort_buffer_size = 38M

read_buffer_size = 4M

join_buffer_size = 8M

thread_cache_size = 64

query_cache_size = 64M

query_cache_type = 1

query_cache_limit = 1048576

tmp_table_size = 256M

max_connections = 768

max_connect_errors = 10000000

#断开超过10秒的连接,(需同时添加两条)

wait_timeout  = 30

interactive_timeout = 30

#该参数取值为服务器逻辑CPU数量x2

thread_concurrency = 16


问题4: mysql DNS反解:skip-name-resolve

错误日志有类似警告:

120119 16:26:04 [Warning]IP address '192.168.1.10'could notbe resolved: Name orservice notknown

120119 16:26:04 [Warning]IP address '192.168.1.14'could notbe resolved: Name orservice notknown

120119 16:26:04 [Warning]IP address '192.168.1.17'could notbe resolved: Name orservice notknown


通过show processlist发现大量类似如下的连接:

|592|unauthenticated user|192.168.1.10:35320|NULL|Connect||login|NULL|

|593|unauthenticated user|192.168.1.14:35321|NULL|Connect||login|NULL|

|594|unauthenticated user|192.168.1.17:35322|NULL|Connect||login|NULL|

skip-name-resolve 参数的作用:不再进行反解析(ip不反解成域名),这样可以加快数据库的反应时间。


修改配置文件添加并需要重启:

[mysqld]

skip-name-resolve


编译安装PHP

cp -frp /usr/lib64/libldap* /usr/lib/

cp -frp /usr/local/mysql/lib/libmysqlclient.so.* /usr/lib/

#ldconfig -v

假设wget都下载在/usr/local/src


libiconv安装

由于历史原因,国际化的文字常常由于语言或者国家的原因使用不同的编码。随着互联网时代的到来,通过互联网进行文字交流也逐渐增多:浏览外国的网站,这个时候字符编码的转换变得尤为重要。这带来了一个问题,就是许多字符在某一种编码方式中没有。为了解决这种混乱,Unicode的编码方式被建立。 Unicode是一种超级编码包含了所有这些编码的字符集,因此一些新的文本格式像XML的默认编码方式就是Unicode. 但是很多老式的计算机还在使用当地的传统的字符编码方式。而一些程序,例如邮件程序和浏览器必须能在这些不同的用户编码之间作转换。其他的一些程序则内置支持Unicode,以顺利支持国际化的处理,但是仍然有在Unicode和其他的传统编码之间转换的需求。GNU的00libiconv就是为这两种应用设计的编码转换库。0libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换。

cd /usr/local/src

tar -zxvf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local

make ; make install


cd /usr/local/src

tar -zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure; make; make install            (安装的目录在/usr/local下 ,/lib目录就可以看到)


#cd ../; tar -zxvf mhash-0.9.9.9.tar.gz; cd mhash-0.9.9.9; ./configure; make; make install

(安装mhash, 安装在/usr/local下, bin目录下看到命令)


#cd ../; tar zxvf mcrypt-2.6.8.tar.gz; cd mcrypt-2.6.8; export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH; ./configure; make; make install

(安装完后/usr/local/bin 下就可以看到mcrypt decrypt命令了)


#cd /usr/local/src;  tar -zxvf php-5.4.13.tar.gz; cd php-5.4.13

 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap=shared --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap  --enable-pdo=shared --with-pdo-mysql=shared --enable-mssql=shared --with-sqlite=shared --with-pdo-sqlite=shared


配置完后会有警告提示:

configure: WARNING: unrecognized options: --enable-discard-path, --enable-safe-mode, --enable-fastcgi, --enable-force-cgi-redirect

没事的,略过


make ; make install    (make ZEND_EXTRA_LIBS='-liconv' ; make install        若无liconv环境时可用此命令)


错误提示1 .../sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

make: *** [ext/phar/phar.php] Error 127

32位系统

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/

64位系统

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/


php-fpm启动报错:

Starting php_fpm /usr/local/webserver/php/bin/php-cgi: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory failed。

报错信息指示libmysqlclient.so.16没有找到。

进入/usr/local/mysql/lib/ 目录查看,呵呵,还真没有,只有一个libmysqlclient.so.16.0.0 。于是我建立了一个软件链接来指向libmysqlclient.so.16。

cd /usr/local/mysql/lib/

ln -s libmysqlclient.so.16 libmysqlclient.so.16.0.0

再次启动php-fpm,问题解决了。


听有些网友说问题仍然存在,那可以试试其它网友的解决方案,在/usr/lib/下建立个软链接:

ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/

如果不行,往下看

export LD_LIBRARY_PATH=”/usr/local/mysq/lib:$LD_LIBRARY_PATH”

加上这句后在去安装编译就ok了。


1.找到libmysqlclient.so.16所在的目录

2.将该目录加入到/etc/ld.so.conf的第一行

3.ldconfig

更新库所在位置

/usr/local/mydns/sbin/named -4 -n 1 -S 52428


错误提示2 

/usr/local/src/php-5.4.8/sapi/cli/php: error while loading shared libraries: libmcrypt.so.4: cannot 

open shared object file: No such file or directory

make: *** [ext/phar/phar.phar] Error 127

方法:

find / name=libmcrypt.so.4 |grep libmcrypt.so.4

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/

ldconfig


错误提示3

chmod: cannot access `ext/phar/phar.phar': No such file or directory

make: [ext/phar/phar.phar] Error 1 (ignored)

...

cp: cannot stat `ext/phar/phar.phar': No such file or directory 

方法:

在/usr/local/src/php-5.4.8/ext/phar下创建一个软链接,或把文件复制到该目录下

ln -s  /usr/local/src/php-5.4.8/ext/phar/phar/phar.php /usr/local/src/php-5.4.8/ext/phar/phar.phar


或 cp -p /usr/local/src/php-5.4.8/ext/phar/phar/phar.php /usr/local/src/php-5.4.8/ext/phar/phar.phar

也可以在对php进行configure的时候,在./configure的后面加上 --without-pear 参数


如果出现:

configure: error: Cannot find ldap libraries in /usr/lib.

解决办法: 

cp -frp /usr/lib64/libldap* /usr/lib/

configure: warning: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.

�Cenable-re2c-cgoto Enable -g flag to re2c to use computed goto gcc extension

configure: warning: lemonversions supported for regeneration of libsqlite parsers: 1.0 (found: none). 

yum install sqlite-devel  或在编译时加上   --without-sqlite

####################################################

make ZEND_EXTRA_LIBS='-liconv' 

make install

#########################


问题4:

PEAR package PHP_Archive not installed: generated phar will require PHP’s phar extension be enabled.

解决方法:当前php目录

下载:wget http://pear.php.net/go-pear.phar

执行:/opt/webserver/php/bin/php go-pear.phar

可以选择all,或其他 


问题5:

configure: error: cannot compute sizeof (char *), 77 See `config.log' for more details.

解决方法:vi /etc/ld.so.conf   添加如下内容,即libiconv.so.2所在的目录

/usr/local/lib


问题6:make: *** [sapi/fpm/php-fpm] 错误 1

1)、重新安装libiconv

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz

tar -zxvf libiconv-1.13.1.tar.gz cd libiconv- 1.13.1 ./configure

make

make install


2)、去除 iconv模块再编译应用:

使用./configure �Chelp查看参数,看具体应用如何去除iconv编译,例如下面是 opencc 的无 iconv的编译方法: opencc: ./configure CFLAGS=-liconv 再如php编译时,可在make时通过zend扩展参数去除libiconv的编译选项 make ZEND_EXTRA_LIBS='-liconv' make install


3、iconv重复安装在不同目录,造成include文件iconv.h等重复 通过 find / -name "iconv.h" 如果查找到2个以上返回结果,说明 iconv重复安装了,卸载多余的版本即可正常编译。


本人用第三种方法,确实有不同的版本,

删除一个就OK。


问题7:

/usr/local/src/php-5.3.10/ext/xmlrpc/libxmlrpc/encodings.c:73: undefined reference to `libiconv_open' /usr/local/src/php-5.3.10/ext/xmlrpc/libxmlrpc/encodings.c:81: undefined reference to `libiconv' /usr/local/src/php-5.3.10/ext/xmlrpc/libxmlrpc/encodings.c:101: undefined reference to `libiconv_close' collect2: ld returned 1 exit status make: *** [sapi/fpm/php-fpm] 错误

解决方法:

表面看,是libiconv安装问题,重装libiconv之后问题依旧,网上看有人舍弃libiconv,使用 �Cwithout-iconv,我觉的不可取,这样是回避问题。 找了n久,终于找到bug所在: 在执行完 ./configure … 之后,修改下 Makefile,找到其中的

EXTRA_LIBS = -lcrypt -lz -lcrypt -lrt -lmysqlclient -lmcrypt -lldap -llber -lfreetype -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lcurl -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lidn -lssl -lcrypto -lz -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt

 在最后面添加 -liconv ,修改后如下

EXTRA_LIBS = -lcrypt -lz -lcrypt -lrt -lmysqlclient -lmcrypt -lldap -llber -lfreetype -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lcurl -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lidn -lssl -lcrypto -lz -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -liconv


问题8:PHP Warning: PHP Startup:Invalidlibrary (maybe nota PHP library)'pdo_mysql.so' inUnknownon line 0

首先phpize:

cd ext/pdophpizemake &&make installcd ../pdo_mysqlphpizemake &&make install

php.ini相应修改:

extension=pdo.so

extension=pdo_mysql.so


结果不能识别:

PHP Warning: PHP Startup:Invalidlibrary (maybe nota PHP library)'pdo.so' inUnknownon line 0PHP Warning: PHP Startup:Invalidlibrary (maybe nota PHP library)'pdo_mysql.so' inUnknownon line 0

无奈只好./configure附加上--enable-pdo --with-pdo-mysql从头编译:

./configure --with-openssl=/usr/--with-apxs2=/usr/local/apache2/bin/apxs --with-mysql-dir=/usr/--with-libdir=/lib64 --with-mysql --with-curl --enable-sockets --enable-xml --enable-mbstring --with-gd --enable-memcache --enable-soap --enable-zip --with-jpeg-dir=/usr/lib64 --enable-pdo --with-pdo-mysql

make &&make install

通了!  然后再重新安装pdo、pdo_mysql等


问题9:configure: error: cannot compute sizeof (char *), See `config.log' for more details.

先查看日志  vi config.log 

查找关键字   sizeof

wKioL1WgyZDBL7_dAAHpOO94dps860.jpg

 问题出来了,是找不到 libmcrypt.so.4 

解决方法:ln -s /usr/local/lib/libmcrypt.so.4  /usr/local/lib64/libmcrypt.so.4 


问题10:编译php的时候会出现下面错误

checking for mysql_config... not found

configure: error: Unable to find your mysql installation

解决方法:

ln -s /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config


问题11:configure: error: Cannot find MySQL header files under

解决方法:

cp -p /usr/local/mysql/bin/mysql_config /usr/bin     或   ln -s /usr/local/mysql/bin/mysql_config /usr/bin


问题12:

/usr/local/src/php-5.2.17/sapi/cli/php: error while loading shared libraries: libmhash.so.2: cannot open shared object file: No such file or directory

make[1]: *** [install-pear-installer] Error 127

make: *** [install-pear] Error 2

解决方法:ln -s /usr/local/lib/libmhash.so.2 /usr/local/lib64/         

ldconfig


问题13:configure: error: libpng.(a|so) not found.          configure: error: libjpeg.(a|so) not found.

解决方法:find  / libpng |grep  libpng

ln -s /usr/lib64/libpng* /usr/lib

ln -s /usr/lib64/libjpe* /usr/lib


问题14:/lib64/liblber-2.4.so.2: could not read symbols: Invalid operation

配置的时候 参数为 --with-ldap=shared

make test 


cp /usr/local/src/php-5.4.13/php.ini-development /usr/local/php/etc/php.ini

如果是生产环境则cp /usr/local/src/php-5.4.13/php.ini-production /usr/local/php/etc/php.ini

rm -rf /etc/php.ini                 #删除系统自带配置文件或改名

ln -s /usr/local/php/etc/php.ini /etc/php.ini                #添加软链接

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf    #拷贝模板文件为php-fpm配置文件

vi /usr/local/php/etc/php-fpm.conf             #编辑

[global]

pid = run/php-fpm.pid #取消前面的分号

[www]

user = nginx          #设置php-fpm运行账号为nginx

group = nginx      #设置php-fpm运行组为nginx

error_log = log/php-fpm.log        #启用错误日志

log_level = notice                   #此行以下的参数可按默认的,也可按下面的参数进行调整

emergency_restart_threshold = 0

emergency_restart_interval = 0

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 500

pm.max_children = 45

pm.max_children = 


php-fpm添加系统服务并设置开机启动

cp /usr/local/src/php-5.4.13/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm     #拷贝php-fpm到启动目录

chmod +x /etc/rc.d/init.d/php-fpm          #添加执行权限

chkconfig php-fpm on           #设置开机启动


vi /usr/local/php/etc/php.ini        #编辑PHP配置文件

找到:disable_functions =

修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname


disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname,fsockopen,opendir,readdir


#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

fsockopen函数:php发包函数,强烈建议您修改php.ini文件,关闭这个函数,95%以上的程序是不需要这个函数的,个别程序如淘宝客、Ucenter、部分  API程序等才需要使用这个函数。如果关闭这个函数,发包程序彻底失效,极大的增强了服务器的安全级别

opendir,readdir函数:浏览读取目录用。禁用此函数后,像phpsps这样的木马就浏览不了目录了。但,同样需要PHP后台管理浏览目录


系统运维 温馨提醒:

找到:;date.timezone =

修改为:date.timezone = "Asia/Shanghai"          #设置时区

找到:expose_php = On

修改为:expose_php = OFF              #禁止显示php版本的信息,新建环境时先打开,便于排错,=设置好后再关闭

找到:short_open_tag = Off

修改为:short_open_tag = ON         #支持php短标签

修改 upload_max_filesize = 2M 为 upload_max_filesize = 200M         #允许上传的最大大小,单位M

修改 post_max_size = 8M         为 post_max_size = 200M                 #表单上允许的文件最大大小,单位M



把PHP配置文件中 Date区改成如下

[Date]

; Defines the default timezone used by the date functions

; http://php.net/date.timezone

date.timezone = "Asia/Shanghai"                 

; http://php.net/date.default-latitude

date.default_latitude = 31.5167

; http://php.net/date.default-longitude

date.default_longitude = 121.4500


service php-fpm start    #启动php-fpm,也可以用非服务的方式启动,用/usr/local/php/sbin/php-fpm &     (+ &表示后台运行)


问题:


启动时提示如下错误

Starting php-fpm /usr/local/php/sbin/php-fpm: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory failed

解决方法:在/etc/ld.so.conf最后加一行/usr/local/lib,运行ldconfig,再运行重启nginx 就可以了,前提是需要编译安装了libiconv,libiconv的安装参照前文。 

PHP安装扩展pdo_mysql    (根据需要求安装,可选。这里也可以在php ./configure  预编译时加上参数--with-pdo-mysql=DIR,DIR表示mysql的安装路径,这里需要换成你的自己的mysql安装路径)


这里用PHP中的phpize工具可以帮助我们轻松的扩展PHP而不需要重新编译PHP

#cd ./ext/pdo                       #   ./为php源码路径,如我的路径为/usr/local/usr/php-5.4.13/,把它替换相应的路径就行了

执行/usr/local/php/bin/phpize         #PHP的安装目录为/usr/local/php

/usr/local/php/bin/phpize                #运行显示如下

]# /usr/local/php/bin/phpize

Configuring for:

PHP Api Version:         20100412

Zend Module Api No:      20100525

Zend Extension Api No:   220100525


./configure --with-php-config=/usr/local/php/bin/php-config --enable-pdo=shared

make; make install; make test

如果成功,则在make install完成后就会出现如下内容

#Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

Installing header files: /usr/local/php/include/php/

Installing PDO headers: /usr/local/php/include/php/ext/pdo/


在php配置文件的 Dynamic Extensions 区域中添加

vi /usr/local/php/etc/php.ini

extension = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/pdo.so"

#cd ./ext/pdo_mysql

执行/usr/local/php/bin/phpize

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql

make; make install

成功则出现

Build complete.

Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

最后测试  (这个版本的PHP源码文件中缺少测试扩展文件  /usr/local/usr/php-5.4.8/ext/pdo_mysql/ext/pdo/tests,不过不影响正常使用,想要通过这个测试,可以 mkdir -p /usr/local/usr/php-5.4.8/ext/pdo_mysql/ext/pdo ; cp -R  /usr/local/usr/php-5.4.8/ext/pdo/tests /usr/local/usr/php-5.4.8/ext/pdo_mysql/ext/pdo )

#make test


在php配置文件的 Dynamic Extensions 中添加

extension = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/pdo_mysql.so"

上面两个 extension 扩展也可以合成一条,为规范建议放到 Paths and Directories 

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525"

extension=pdo.so

extension=pdo_mysql.so


安装其他扩展

1、安装 pear

[root@test php-5.3.6]# cd ext/phar

[root@test phar]# wget http://pear.php.net/go-pear.phar

[root@test phar]# /usr/local/php/bin/php go-pear.phar

Below is a suggested file layout for your new PEAR installation.  To

change individual locations, type the number in front of the

directory.  Type 'all' to change all of them or simply press Enter to

accept these locations.

 1. Installation base ($prefix)                   : /usr/local/php

 2. Temporary directory for processing            : /tmp/pear/install

 3. Temporary directory for downloads             : /tmp/pear/install

 4. Binaries directory                            : /usr/local/php/bin

 5. PHP code directory ($php_dir)                 : /usr/local/php/lib/php

 6. Documentation directory                       : /usr/local/php/docs

 7. Data directory                                : /usr/local/php/data

 8. User-modifiable configuration files directory : /usr/local/php/cfg

 9. Public Web Files directory                    : /usr/local/php/www

10. Tests directory                               : /usr/local/php/tests

11. Name of configuration file                    : /usr/local/php/etc/pear.conf

1-11, 'all' or Enter to continue: 

Beginning install...

Configuration written to /usr/local/php/etc/pear.conf...

Initialized registry...

Preparing to install...

installing phar:///usr/local/src/php-5.3.6/ext/phar/go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.7.tar...

installing phar:///usr/local/src/php-5.3.6/ext/phar/go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.3.0.tar...

installing phar:///usr/local/src/php-5.3.6/ext/phar/go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.9.3.tar...

installing phar:///usr/local/src/php-5.3.6/ext/phar/go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.4.tar...

installing phar:///usr/local/src/php-5.3.6/ext/phar/go-pear.phar/PEAR/go-pear-tarballs/XML_Util-1.2.1.tar...

install ok: channel://pear.php.net/Archive_Tar-1.3.7

install ok: channel://pear.php.net/Console_Getopt-1.3.0

install ok: channel://pear.php.net/Structures_Graph-1.0.4

install ok: channel://pear.php.net/XML_Util-1.2.1

install ok: channel://pear.php.net/PEAR-1.9.3

PEAR: Optional feature webinstaller available (PEAR's web-based installer)

PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)

PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)

PEAR: To install optional features use "pear install pear/PEAR#featurename"

The 'pear' command is now at your service at /usr/local/php/bin/pear


2、Memcache扩展

Memcache是danga.com的一个开源项目,它是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的Hash表,能够用来存储各种格式的数据。可以类比于MySQL这样的服务,而PHP扩展的Memcache实际上是连接Memcache的方式。 

cd /usr/local/src 

wget http://pecl.php.net/get/memcache-2.2.6.tgz

tar xvf memcache-2.2.6.tgz

cd memcache-2.2.6

/usr/local/php/bin/phpize

(

[root@test memcache-2.2.6]# /usr/local/php/bin/phpize          

Configuring for:

PHP Api Version:         20090626

Zend Module Api No:      20090626

Zend Extension Api No:   220090626

)

./configure --with-php-config=/usr/local/php/bin/php-config

make

make install


(

[root@test memcache-2.2.6]# make install

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

)


修改php.ini ,添加扩展库文件的目录及扩展库

vi /usr/local/php/etc/php.ini    找到“   ; extension_dir = "./"  ”  这一行,在此行下面添加:

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"

extension = "memcache.so"


3、eaccelerator加速器

eaccelerator是一个自由开放源码PHP加速器,优化和动态内容缓存,提高了性能php脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。 它还有对脚本起优化作用,以加快其执行效率。使您的PHP程序代码执效率能提高1-10倍;

wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2

tar jxvf eaccelerator-0.9.6.1.tar.bz2

cd eaccelerator-0.9.6.1/

/usr/local/php/bin/phpize

./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config

make

make install

[root@test eaccelerator-0.9.6.1]# make install

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/


配置eaccelerator 加速PHP 

mkdir -p /usr/local/php/eaccelerator_cache_dir 建立加速缓存目录

chmod 777 /usr/local/php/eaccelerator_cache_dir


vi /usr/local/php/etc/php.ini  在文件末尾添加如下

[eaccelerator]

zend_extension = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"

eaccelerator.shm_size = "16"

eaccelerator.cache_dir = "/usr/local/php/eaccelerator_cache_dir"

eaccelerator.enable = "1"

eaccelerator.optimizer = "1"

eaccelerator.check_mtime = "1"

eaccelerator.debug = "0"

eaccelerator.filter = ""

eaccelerator.shm_max = "0"

eaccelerator.shm_ttl = "0"

eaccelerator.shm_prune_period = "0"

eaccelerator.shm_only = "0"

eaccelerator.compress = "1"

eaccelerator.compress_level = "9"

保存退出

以上参数只修改了缓存和扩展库的的路径,其他相关参数可自行参考修改


4、PDO_MYSQL:

PDO_MYSQL is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to MySQL 3.x, 4.x and 5.x databases.http://pecl.php.net/package/PDO_MYSQL

PDO_MYSQL是一个驱动程序,它实现了PHP数据对象(PDO)的接口,以实现从PHP访问MySQL的3.x,4.x和5.x的数据库。

wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

tar zxvf PDO_MYSQL-1.0.2.tgz

cd PDO_MYSQL-1.0.2

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/var/mysqldata/mysql.sock


(

checking for re2c... no

configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.

)

make

make install

(

[root@test PDO_MYSQL-1.0.2]# make install

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

)


修改php.ini ,添加扩展库文件的目录及扩展库

vi /usr/local/php/etc/php.ini    找到“   ; extension_dir = "./"  ”  这一行,在此行下面添加:

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"

extension = "pdo_mysql.so"


5、ImageMagick

ImageMagick是一套功能强大、稳定而且免费的工具集和开发包,可以用来读、写和处理超过89种基本格式的图片文件,包括流行的TIFF, JPEG, GIF, PNG, PDF以及PhotoCD等格式。利用ImageMagick,你可以根据web应用程序的需要动态生成图片, 还可以对一个(或一组)图片进行改变大小、旋转、锐化、减色或增加特效等操作,并将操作的结果以相同格式或其它格式保存。对图片的操作,即可以通过命令行进行,也可以用C/C++、Perl、Java、PHP、Python或Ruby编程来完成。同时ImageMagick提供了一个高质量的2D工具包,部分支持SVG。

yum -y install perl-ExtUtils-MakeMaker

wget ftp://mirror.aarnet.edu.au/pub/imagemagick/ImageMagick-6.7.0-10.tar.gz        

#官网 http://www.imagemagick.org/download/

tar zxvf ImageMagick-6.7.0-10.tar.gz

cd ImageMagick-6.7.0-10

ln -s  /usr/lib64/libtiff.so /usr/lib

ln -s  /usr/lib64/libpng.so /usr/lib

ln -s  /usr/lib64/libjpeg.so /usr/lib

./configure --prefix=/usr/local/imagemagick

make; make install

vi /etc/ld.so.conf 加入一行:

/usr/local/imagemagick/lib

ldconfig -v

cd ..

参考官方安装说明 :

http://www.imagemagick.org/script/advanced-unix-installation.php   

验证configuration情况:identify -list configure  验证支持的图片格式:identify -list format 

http://wenku.baidu.com/link?url=1yeJdHxdpUkOXr0UzYCsVCqjBtyr0BOV3x1pXUN6_UdhMW5Wb9Aa8cNlHxBGPZcZZ_f3BctE65hSBWW4nI18b5PsnPdMHIMGvYlG5mCaAqC


6、imagick

    一个可以供PHP调用ImageMagick功能的PHP扩展。使用这个扩展可以使PHP具备和ImageMagick相同的功能。Imagick(PHP的原生函数库)是一个功能强大的图像处理库,Imagick是PHP下针对ImageMagick这个强大软件包的API接口。Imagick依赖于ImageMagick。[注意顺序]

wget http://pecl.php.net/get/imagick-3.1.0b1.tgz

tar -zxvf imagick-3.1.0b1.tgz 

cd imagick-3.1.0b1

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick

make; make install

(

[root@test imagick-3.1.0b1]# make install

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

Installing header files:          /usr/local/php/include/php/

)

修改php.ini ,添加扩展库文件的目录及扩展库

vi /usr/local/php/etc/php.ini    找到“   ; extension_dir = "./"  ”  这一行,在此行下面添加:

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"

extension = "imagick.so"


安装imagick时Cannot locate header file MagickWand.h错误的解决

环境如下:

php5.4.13

ImageMagick-6.8.3-10

imagick-3.0.1

可是出错了一个问题.就是死说找不到MagickWand.h:

checking for MagickWand.h header file... configure: error: Cannot locate header file MagickWand.h

可是我明明正确安装了ImageMagick的呀.GOOGLE了半天,也解决不了这个问题.后面对照另一个服务器上的ImageMagick才发现,原来ImageMagick 6.8这个版后的目录结构变了,旧版本头文件是放在/usr/local/include/ImageMagick目录的,而ImageMagick 6.8则是放在/usr/local/include/ImageMagick-6

添加软连接

命令如下:

ln -s /usr/local/include/ImageMagick-6 /usr/local/include/ImageMagick

make && make && install

编译通过!

php 编译安装imagick报错 wand/MagickWand.h:没有那个文件或目录

在包含自 /soft/imagick-3.1.0RC2/imagick_file.c:21 的文件中:

/soft/imagick-3.1.0RC2/php_imagick.h:49:31: 错误:wand/MagickWand.h:没有那个文件或目录

In file included from /soft/imagick-3.1.0RC2/php_imagick_file.h:24,

                 from /soft/imagick-3.1.0RC2/imagick_file.c:22:

/soft/imagick-3.1.0RC2/php_imagick_defs.h:72: 错误:expected specifier-qualifier-list before ‘MagickWand’

/soft/imagick-3.1.0RC2/php_imagick_defs.h:80: 错误:expected specifier-qualifier-list before ‘DrawingWand’

/soft/imagick-3.1.0RC2/php_imagick_defs.h:86: 错误:expected specifier-qualifier

解决方法:

export PKG_CONFIG_PATH=/usr/local/imagemagick/lib/pkgconfig


问题:

诡异的问题,驾驭开源软件需要耐心呐~

今天帮朋友给装一LNMP环境 

CentOS6 64bit  

其中, 在编译安装PHP5扩展模块:

 imagick    ImageMagick 

下载地址:http://pecl.php.net/package/imagick

tar xvzf imagick-3.1.0RC2.tgz 

cd imagick-3.1.0RC2/  

/usr/local/webserver/php/bin/phpize  

./configure --with-php-config=/usr/local/webserver/php/bin/php-config  

make; make install  

(#注: 出现大量的报错信息:

/root/soft/imagick-3.1.0RC2/php_imagick.h:49:31: error: wand/MagickWand.h: No such file or directory

In file included from /root/soft/imagick-3.1.0RC2/php_imagick_file.h:24,

                 from /root/soft/imagick-3.1.0RC2/imagick_file.c:22:


/root/soft/imagick-3.1.0RC2/php_imagick_defs.h:72: error: expected specifier-qualifier-list before ‘MagickWand’

... ...

/root/soft/imagick-3.1.0RC2/imagick_file.c:318: error: ‘php_imagick_object’ has no member named ‘magick_wand’

/root/soft/imagick-3.1.0RC2/imagick_file.c:326: error: ‘MagickFalse’ undeclared (first use in this function)

make: *** [imagick_file.lo] Error 1

很是困惑,根据错误提示:

/root/soft/imagick-3.1.0RC2/php_imagick.h:49:31: error: wand/MagickWand.h: No such file or directory

感觉或许是64位系统,安装脚本按照32位系统的目录来寻找,所以找不到所需要的库文件......

于是,我将 /usr/local/include/ImageMagick/   目录下的 wand、magick 子目录都copy到 imagick-3.1.0RC2/ 目录下,再编译。通过了~~

看到这,想来你是明白了


7、zbar扩展

官网 http://zbar.sourceforge.net/

wget http://nchc.dl.sourceforge.net/project/zbar/zbar/0.10/zbar-0.10.tar.bz2

yum -y install gtk+ qt4

export PKG_CONFIG_PATH=/usr/local/imagemagick/lib/pkgconfig/

tar -jxvf zbar-0.10.tar.bz2; cd zbar-0.10; ./configure --disable-video --without-gtk --without-qt; make; make install

#这里建议 zbar安装的目录最好默认,若使用 prefix指定了安装目录,则在安装 php-zbarcode扩展时寻找 zbar依赖时麻烦

遇到错误:

1、

checking for linux/videodev.h... no

configure: error: in `/usr/local/src/zbar-0.10':

configure: error: test for video support failed!

rebuild your kernel to include video4linux support or

configure --disable-video to skip building video support.

See `config.log' for more details.

[root@CentOS7 zbar-0.10]# find / videodev.h |grep videodev.h

find: ‘videodev.h’: No such file or directory

解决:配置时添加   --disable-video


2、

checking for MAGICK... no

configure: error: in `/usr/local/src/zbar-0.10':

configure: error: Unable to find ImageMagick >= 6.2.6:

No package 'MagickWand' found

* Ensure that you installed any "development" packages for ImageMagick.

* Consider adjusting the PKG_CONFIG_PATH environment variable if you

  installed software in a non-standard prefix.

* You may set the environment variables MAGICK_CFLAGS and MAGICK_LIBS

  to avoid the need to call pkg-config.

  See the pkg-config man page for more details.

* To avoid using ImageMagick altogether you may add the --without-imagemagick

  flag to the configure command; the zbarimg program will not be built.

See `config.log' for more details.

解决方法:

export PKG_CONFIG_PATH=/usr/local/imagemagick/lib/pkgconfig/


3、

checking for python extension module directory... ${exec_prefix}/lib64/python2.7/site-packages

checking for PYGTK... configure: error: Package requirements (pygtk-2.0) were not met:

No package 'pygtk-2.0' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you

installed software in a non-standard prefix.

Alternatively, you may set the environment variables PYGTK_CFLAGS

and PYGTK_LIBS to avoid the need to call pkg-config.

See the pkg-config man page for more details.

解决方法:添加 --without-gtk --without-qt


8、php-zbarcode

此扩展模块依赖 ZBar 、ImageMagick模块,所以要先安装 ZBar 、ImageMagick模块

从https://github.com/mkoppanen/php-zbarcode 下载源源

unzip  php-zbarcode-master.zip; cd php-zbarcode-master; /usr/local/php/bin/phpize; ./configure --with-php-config=/usr/local/php/bin/php-config --with-zbarcode-imagemagick-dir=/usr/local/imagemagick/; make; make install

php.ini文件中添加如下扩展

extension = zbarcode.so

重启php-fpm即可


9、ZendOptimizer-3.3.9安装

php5.4扩展ZendOptimizer请参见  http://hi.baidu.com/hanxiao2100/item/6fd8632b0a55280c77272c12

cd /usr/local/src; tar -zxvf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz; cp /usr/local/src/ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/5_2_x_comp/ZendOptimizer.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ZendOptimizer.so;

修改php.ini在最后加入

[Zend]

zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"

保存即可,运行usr/local/php/bin/php -v    有with Zend Optimizer v3.3.9,说明成功,最重 service php-fpm restart 重启php-fcgi


10、php zip扩展

cd /usr/local/src/php-5.4.8/ext/zip

/usr/local/php/bin/phpize

./configure --prefix=/usr/bin/zip --with-php-config=/usr/local/php/bin/php-config

make; make install

安装完之后,屏幕上会提示zip.so的位置。然后将其记录下来,如:/usr/local/php5.2/lib/php/extensions/no-debug-non-zts-20060613/zip.so


使用root权限修改php.ini(通常可能会在/usr/local/lib/文件夹下,不过视当初安装php而定,可以通过phpinfo()来查看):

编辑 php.ini文件

extension = /usr/local/php5.2/lib/php/extensions/no-debug-non-zts-20060613/zip.so

然后同样在php.ini文件中,将 

zlib.output_compression = Off    改成

zlib.output_compression = On 

php.ini中不能禁用函数proc_open

disable_functions =           此行不包含 proc_open


11、XCache组件

cd /usr/local/src

tar zxvf xcache-3.1.0.tar.gz

cd xcache-3.1.0

/usr/local/php/bin/phpize

./configure -with-php-config=/usr/local/php/bin/php-config -enable-xcache -enable-xcache-coverager -enable-inline-optimization -disable-debug

make; make install


vi /usr/local/php/etc/php.ini

在文件末尾添加:

extension = "xcache.so" ;#你的安装路径

xcache.admin.auth = On

xcache.admin.user = "xcache"

xcache.admin.pass = "5f4dcc3b5aa765d61d8327deb882cf99"  ;#password  is password

xcache.size        = 32M

xcache.shm_scheme  = "mmap"

;cpu number (cat /proc/cpuinfo |grep -c processor)

xcache.count        = 4

xcache.slots        = 8K

xcache.ttl          = 0

xcache.gc_interval  = 0

xcache.var_size    = 16M

xcache.var_count    = 1

xcache.var_slots    = 8K

xcache.var_ttl      = 0

xcache.var_maxttl  = 0

xcache.var_gc_interval =    300

xcache.test        = Off

xcache.readonly_protection = Off

xcache.mmap_path    =  "/dev/zero"

xcache.coredump_directory =  ""

xcache.cacher      = On

xcache.stat        = On

xcache.optimizer    = Off

[xcache.coverager]

xcache.coverager    = On

xcache.coveragedump_directory = ""


另一例:

wget http://xcache.lighttpd.net/pub/Releases/1.3.0/xcache-1.3.0.tar.gz

/usr/local/php5/bin/phpize

./configure �Cenable-xcache --enable-xcache-coverager --with-php-config=/usr/local/php/bin/php-config --enable-inline-optimization --disable-debug

make && make install

/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/xcache.so

vi /usr/local/php5/lib/php.ini

[xcache-common] 

zend_extension = /usr/local/php/lib/php/extensions/xcache.so 

[xcache.admin] 

; Change xcache.admin.user to your preferred login name 

xcache.admin.user = "admin" 

; Change xcache.admin.pass to the MD5 fingerprint of your password 

; Use md5 -s "your_secret_password" to find the fingerprint 

xcache.admin.pass = "e10adc3949ba59abbe56e057f20f883e" 

[xcache]

xcache.cacher = On

xcache.shm_scheme = "mmap"

;XCache的内存缓存大小,小内存VPS建议设为16M,普通网站建议设置为64MB,如果是IDC服务器,可以设置成256MB 

xcache.size = 64M

; cpu number (cat /proc/cpuinfo |grep -c processor)

xcache.count = 2

xcache.slots = 8k

xcache.ttl = 0

xcache.gc_interval = 0

xcache.var_size = 2M

; cpu number (cat /proc/cpuinfo |grep -c processor)

xcache.var_count = 2

xcache.var_slots = 8K

xcache.var_ttl = 0

xcache.var_maxttl = 0

xcache.var_gc_interval = 300

xcache.readonly_protection = Off

xcache.mmap_path = "/dev/zero" 

重启PHP模块

正常load之后,

在phpinfo显出的信息内

Zend这快应该会加上XCache的内容

This program makes use of the Zend Scripting Language Engine:

Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

with XCache v1.2.1, Copyright (c) 2005-2007, by mOo


配置解释

[xcache-common]

extension=xcache.so

[xcache.admin]

xcache.admin.enable_auth = On

xcache.admin.user = "xcache"

xcache.admin.pass = "21232f297a57a5a743894a0e4a801fc3"

[xcache]

xcache.shm_scheme ="mmap"      ;决定 XCache 如何从系统分配共享内存

xcache.size=60M                            ;0 禁止, 非 0 则启用缓存器. 请注意您系统所允许的 mmap 最大值.

xcache.count =1                            ;指定将 cache 切分成多少块

xcache.slots =8K                            ;只是作为 hash 槽个数的参考值, 您可以放心地缓冲超过这个个数的项目.

xcache.ttl=0                                   ;设置缓冲项目的 Ttl (Time To Live) 值, 0=永不过期.

xcache.gc_interval =0                    ;检查过期项目, 回收内存空间的间隔.

;xcache.cacher=on                   ;使用/不使用 opcode 缓存器. xcache.size = 0 时无效.

;xcache.stat=on                       ;使用 stat() 发现检查脚本更新.

;设置为On,则每次回去检查文件是否修改,如果修改会将修改过的文件重新编译然后存进opcode缓存来替代旧的opcode缓存,为Off则不进行检查直接使用旧的opcode缓存,注意这时候如果修改文件则响应不会马上发生改变,除非重启服务器。

xcache.var_size=4M

xcache.var_count =1               ;//同xcache.count,不过是变量缓存的个数

xcache.var_slots =8K

xcache.var_ttl=0

xcache.var_maxttl=0

xcache.var_gc_interval =300      ;垃圾回收间隔时间

xcache.test =Off

xcache.readonly_protection = On    ;如果启用了将会略微降低性能, 但是会提高一定的安全系数. 这个选项对于 xcache.mmap_path = /dev/zero 无效.

xcache.mmap_path ="/tmp/xcache" 

xcache.coredump_directory =""

[xcache.coverager]

xcache.coverager=On ;启用代码覆盖信息采集到启用后 xcache.coveragedump_directory 设置以及xcache_coverager_start/stop/get/clean()才可以使用(启用后会对降低影响)

xcache.coveragedump_directory=""

xcache.coverager_autostart=on  ;每个页面请求自动调用 xcache_coverager_start

拷贝htdocs到WWW目录

cp -R htdocs  /var/www/webroot

cd /var/www/webroot

cp config.example.php config.php

在文件末尾添加:

$_SERVER["PHP_AUTH_USER"] = "xcache";

$_SERVER["PHP_AUTH_PW"] = "password"


打开浏览器访问http://10.0.0.17/htdocs,输入帐号xcache 密码password 进入


12、php mssql扩展

1>、安装FreeTDS 

http://www.freetds.org

wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-0.91.83.tar.gz

tar -zxvf freetds-0.91.83.tar.gz

cd freetds-0.91.83

 ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib 

make && make install

yum -y install unixODBC*

在/etc/profile

中加入export PATH="$PATH:/usr/local/freetds/bin"

#echo "/usr/local/freetds/lib" >> /etc/ld.so.conf

source /etc/profile

#ldconfig

cd /usr/local/src/php-5.4.13/ext/mssql 

/usr/local/php/bin/phpize 

./configure --with-php-config=/usr/local/php/bin/php-config --with-mssql=/usr/local/freetds

make &&  make install

在 php.ini  中的  Dynamic Extensions 加入下面这行

extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/mssql.so


2>配置freetds.conf

vi /usr/local/freetds/etc/freetds.conf

输入以下内容:

#   $Id: freetds.conf,v 1.12 2007-12-25 06:02:36 jklowden Exp $

#

# This file is installed by FreeTDS if no file by the same

# name is found in the installation directory.

#

# For information about the layout of this file and its settings,

# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database

# server specific section

[global]

        # TDS protocol version

;       tds version = 4.2

        # Whether to write a TDSDUMP file for diagnostic purposes

        # (setting this to /tmp is insecure on a multi-user system)

;       dump file = /tmp/freetds.log

;       debug flags = 0xffff

        # Command and connection timeouts

;       timeout = 10

;       connect timeout = 10

        # If you get out-of-memory errors, it may mean that your client

        # is trying to allocate a huge buffer for a TEXT field.

        # Try setting 'text size' to a more reasonable limit

        text size = 64512

# A typical Sybase server


[egServer50]

        host = symachine.domain.com

        port = 5000

        tds version = 5.0

# A typical Microsoft server


[egServer70]

        #host = ntmachine.domain.com

        host = 192.168.0.63

        port = 1433

        tds version = 8.0


3>、重启php并验证扩展模块加载是否成功

service php-fpm restart

[root@mssql]# /usr/local/php/bin/php -m 

[PHP Modules] 

bcmath 

ctype 

curl 

date 

dom 

eAccelerator 

filter 

gd 

hash 

iconv 

imagick 

json 

libxml 

mbstring 

mcrypt 

memcache 

memcached 

mssql 

mysql 

mysqli 

openssl 

pcre 

PDO 

pdo_sqlite 

posix 

Reflection 

session 

shmop 

SimpleXML 

soap 

sphinx 

SPL 

SQLite 

standard 

sysvsem 

tokenizer 

xhprof 

xml 

xmlreader 

xmlwriter 

zip 

zlib   

[Zend Modules] eAccelerator


4>、测试连接   在网站目录下建立   sql.php  ,内容如下

<?php

$conn=mssql_connect("egServer70","sql_user",sql_password);

       //test

           if($conn)

       {

       echo "ok";

       } else

          

           {

           echo "no";

           }

?>


最后访问测试 http://ServerIP/sql.php  如果显示 OK  表示连接成功


问题:PHP中用freetds连接到mssql中文乱码问题

解决:

在PHP平台上用freetds连接到mssql数据库时出现了乱码问题。具体是用freetds连接调用一个mssql的存储过程,但是返回的结果却出现了乱码,PHP端是UTF-8。刚开始以为是mssql的编码问题,因为在mssql中就是GB2312的。后来查了一下资料发现可以修改freetds的配置文件来解决这个问题。在Freetds的配置文件中  添加 client charset = GB2312 一行。

vi /usr/local/freetds/etc/freetds.conf

#   $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $

#

# This file is installed by FreeTDS if no file by the same 

# name is found in the installation directory.  

#

# For information about the layout of this file and its settings, 

# see the freetds.conf manpage "man freetds.conf".  

# Global settings are overridden by those in a database

# server specific section

[global]

        # TDS protocol version

;       tds version = 4.2

        # Whether to write a TDSDUMP file for diagnostic purposes

        # (setting this to /tmp is insecure on a multi-user system)

;       dump file = /tmp/freetds.log

;       debug flags = 0xffff

        # Command and connection timeouts

;       timeout = 10

;       connect timeout = 10

        # If you get out-of-memory errors, it may mean that your client

        # is trying to allocate a huge buffer for a TEXT field.  

        # Try setting 'text size' to a more reasonable limit 

        text size = 64512

        client charset = GB2312


# A typical Sybase server

[egServer50]

        host = symachine.domain.com

        port = 5000

        tds version = 5.0


# A typical Microsoft server

[egServer70]

        host = ntmachine.domain.com

        port = 1433

        tds version = 7.0


如果设置成GB2312不行的话,可以试试GBK、cp936。记住,不要以为要满足PHP端需求设置成UTF-8,这样我试过是不行的。重启PHP-FPM和nginx,问题解决

注意, client charset 必需大于或等于服务端数据库使用的字符集.

例如,服务端数据库是 MS SQL Server 2000, 字符集是 GB2312.

那么 client charset 可以设置为 GB2312(等于), GB18030(大于),UTF-8(大于)

但不能设为ISO-8859-1(小于), Shift_JIS(不等于).

由于 UTF-8 是所由字符集的超集,因此设置为 UTF-8 总是可行的.

此外, FreeTDS的client charset不能设置为 UTF16. 这时目前该软件设计的局限,

其官方网站称,在未来版本中可能会增加对client charset UTF16的支持.


关于字符集:

FreeTDS能够自动识别服务器端的charset. 因此 FreeTDS 需要用户设定客户端的

charset. 这也就是客户端应用程序期待从FreeTDS获得的数据所应该使用的charset.

一旦client charset设定, FreeTDS将实现从 server charset <--> client charset

的转换.

如果有两个客户应用程序都要访问同一个 MS SQLServer, 但很不幸,这两个客户程序所

接受的字符集分别是 UTF-8 和 GB2312. 那么解决的办法是在FreeTDS.conf中设置

两组DataSource,它们的服务器设置相同,但client charset分别设为 UTF-8和GB2312. 在 

odbc.ini中也设置两组不同的DSN 分别指向这两组DataSource. 而最终两个客户程序

各自使用与之相应的DSN即可.

[sql1]

host = 192.168.0.5    ; MS SQL Server 的 IP 或者域名

port = 1433

tds version = 8.0

client charset = UTF-8  ; 客户端软件可识别的字符集.


[sql1]

host = 192.168.0.6    ; MS SQL Server 的 IP 或者域名

port = 1433

tds version = 8.0

client charset = GB2312  ; 客户端软件可识别的字符集.


法二:配置php的php.ini中关于mssql设置

在对mssql进行配置的相关内容中有如下这么一条:

; Specify client character set.

; If empty or not set the client charset from freetds.comf is used

; This is only used when compiled with FreeTDS

;mssql.charset = "ISO-8859-1"

从说明中可以看到这个是专门针对FreeTDS的,如果freetds.comf为空或者没有设置client charset时,可以在这块起用mssql.charset这个进行设置。因为SQLServer的编码是GBK,所以我将变量设置为GBK,如下:

mssql.charset = "GBK"

然后在将SQLServer中的数据进行读取、显示、插入到Mysql中的时候,使用下面的 charset_convert 函数对其进行转码

functioncharset_convert($string,$input='GBK',$output='UTF-8'){if(function_exists('mb_convert_encoding')){$output=mb_convert_encoding($string,$output,$input);}elseif(function_exists('iconv')){$output=iconv($input,$output,$string);}else{exit('charset_convert() needs mb_convert_encoding or iconv function support.');}      return$output;}

service php-fpm restart 即可以正常显示了。


旧版php安装,这里以php5.2.17(php-fpm)为例

cd /usr/local/src

tar -zxvf php-5.2.17.tar.gz

gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1                        #给php源码打上PHP-FPM补丁

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap  --enable-pdo=shared --with-pdo-mysql=shared --enable-mssql=shared --with-sqlite=shared --with-pdo-sqlite=shared


接下来的安装就跟php5.4的是一样的了

修改 /usr/local/php/etc/php-fpm.conf  取消以下两个注释,并把用户与组改成 nginx 用户

<!--    <value name="user">nobody</value>                               -->

                        Unix group of processes

                <!--    <value name="group">nobody</value>              -->

php-fpm添加系统服务并设置开机启动

cp /usr/local/src/php-5.2.17/sapi/cgi/fpm/init.d/php-fpm.in /etc/rc.d/init.d/php-fpm     #拷贝php-fpm到启动目录

vi /etc/rc.d/init.d/php-fpm

#! /bin/sh

php_fpm_BIN=@prefix@/bin/php-cgi

php_fpm_CONF=@php_fpm_conf_path@

php_fpm_PID=@php_fpm_pid_path@


改成

#! /bin/sh

### BEGIN INIT INFO

# Provides:          php-fpm

# Required-Start:    $remote_fs $network

# Required-Stop:     $remote_fs $network

# Default-Start:     2 3 4 5

# Default-Stop:      0 1 6

# Short-Description: starts php-fpm

# Description:       starts the PHP FastCGI Process Manager daemon

### END INIT INFO

prefix=/usr/local/php

exec_prefix=${prefix}

php_fpm_BIN=${exec_prefix}/bin/php-cgi

php_fpm_CONF=${prefix}/etc/php-fpm.conf

php_fpm_PID=${prefix}/logs/php-fpm.pid


chmod +x /etc/rc.d/init.d/php-fpm          #添加执行权限

chkconfig php-fpm on           #设置开机启动


cp php.ini-recommended  /usr/local/php5.2/etc/php.ini       #php.ini配置文件

service php-fpm start             #启动服务

/usr/local/php/sbin/php-fpm start    #启动php-fpm服务,也可以用此命令

最后注意:

安装pdo、pdo_mysql  = 扩展在配置 php.ini时,应这样

echo "/usr/local/php/sbin/php-fpm start"  >> /etc/rc.local

extension_dir=/usr/local/php5.2/lib/php/extensions/no-debug-non-zts-20060613

extension=pdo.so

extension=pdo_mysql.so

extension=mssql.so

要不有可能报

]# /usr/local/php5.2/bin/php -v             或 /usr/local/php/sbin/php-fpm start  启动php-fpm

PHP Warning:  PHP Startup: Unable to load dynamic library './/usr/local/php5.2/lib/php/extensions/no-debug-non-zts-20060613/pdo.so' - .//usr/local/php5.2/lib/php/extensions/no-debug-non-zts-20060613/pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0


PHP 5.2.17 (cli) (built: Apr 25 2013 20:38:04)

Copyright (c) 1997-2010 The PHP Group

Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies


/usr/local/php/sbin/php-fpm 启动 php-fpm命令过长  可把它添加到别名到系统环境 

vi /etc/profile

alias 'php-fpm=/usr/local/php/sbin/php-fpm'

然后 source /etc/profile 让它生效,此时 php-fpm 命令相当于 /usr/local/php/sbin/php-fpm

php-fpm start | stop |restart  可 启动 | 停止 | 重启 php-fpm


Linux上安装多版本php

(安装时注意--prefix、--with-config-file-path及安装扩展时注意指定路径的正确性),如  

php5.2.17安装于   /usr/local/php5.2    设置php-fpm端口9000

php5.3.24安装于   /usr/local/php5.3    设置php-fpm端口9003

php5.4.x安装于   /usr/local/php5.4    设置php-fpm端口9004


php-fpm端口在  php安装目录下的 etc/php-fpm 中 listen 参数指定,如

listen = 127.0.0.1:9000

然后nginx中可以针对不同虚拟主机使用不同版本的php,这里主要通过 nginx.conf 中Server {location ~ \.php$ {fastcgi_pass   127.0.0.1:9004;}}指定不同端口来使用不同版本php

        location ~ \.php$ {

            root           /var/webSite/win1;

            #fastcgi_pass   127.0.0.1:9000;

            #fastcgi_pass   127.0.0.1:9003;

            fastcgi_pass   127.0.0.1:9004;

            fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

            include        fastcgi_params;

        }


这里做一个WEB服务器(WEB的搭建上面已经配置完成),phpMyAdmin管理Mysql数据库,用户通过FTP更新网站


web架构研究

http://lnmp.in/


你可能感兴趣的:(centos6.6)