系統為CentOS6.8 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 net-tools --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
yum -y install zlib zlib-devel gd gd-devel
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-openssl-opt="enable-tlsext" --with-stream --with-stream_ssl_module --with-http_v2_module
注意:--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
附:CentOS 7 nginx啟動腳本
vi /usr/lib/systemd/system/nginx.service #編輯啟動文件添加下面內容
############################################################
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
############################################################
:wq! #保存退出
systemctl enable nginx #設置開機啟動
systemctl start nginx.service #啟動
當然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
若mysql 是yum安裝的:mysql參數可以這樣 --with-mysql=/usr --with-mysqli=/usr/bin/mysql_config
php5.3 以后就不需要指定myslq的安裝路徑和myslq的庫了,因為php自己有一個mysql的客戶端,直接--with-mysql=myslqnd --with-mysqli=myslqnd --with-pdo-mysql=mysqlnd 就ok了
配置完后會有警告提示:
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.
–enable-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 –help查看參數,看具體應用如何去除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,使用 –without-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
問題出來了,是找不到 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 –enable-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;
}
nginx-php配置例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
server {
listen 80;
server_name foo.com;
root /path;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}
}
|
這里做一個WEB服務器(WEB的搭建上面已經配置完成),phpMyAdmin管理Mysql數據庫,用戶通過FTP更新網站