系統爲CentOS6.8 x64服務器版精簡安裝。php
準備工做html
部署安裝目錄 node
/usr/local/* python
/var/lib/*mysql
/var/lib64/*linux
下載源文件nginx
#cd /usr/local/src c++
wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.28.tar.gzgit
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.10.tar.gzgithub
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
三、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
安裝其餘擴展
一、安裝 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
二、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"
三、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"
保存退出
以上參數只修改了緩存和擴展庫的的路徑,其餘相關參數可自行參考修改
四、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"
五、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
六、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/ 目錄下,再編譯。經過了~~
看到這,想來你是明白了
七、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依賴時麻煩
遇到錯誤:
一、
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
二、
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/
三、
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
八、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便可
九、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
十、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
十一、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 進入
十二、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更新網站