CentOS6.3 x64+Nginx1.3.8/Apache-httpd 2.4.3+PHP5.4.8(php-fpm)+MySQL5.5.28+CoreSeek4.1源码编译安装
系统为CentOS6.3 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
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://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
最小化安装(minimal)需安装的基本软件
yum install -y bind-utils traceroute wget man sudo ntp ntpdate screen patch make gcc gcc-c++ flex bison zip unzip ftp --skip-broken
安装相关库
配置yum只安装64位软件,即过滤掉 i386, i686 的软件包
# vi /etc/yum.conf 在[main]最后添加如下内容
exclude=*.i?86
如果想删除系统上已经安装的 i386/i686 包:
# yum remove \*.i\?86 -y
yum -y install kernel-devel-* gcc kernel-headers-* --skip-broken
yum -y install yum-fastestmirror --skip-broken
yum -y install patch make gcc gcc-c++ flex bison --skip-broken
yum -y install libtool libtool-libs kernel-devel autoconf --skip-broken
yum -y install libjpeg libjpeg-devel libpng libpng-devel gd-devel --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 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
/lib
/lib64
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
编辑完ld.so.conf,执行
# ldconfig
使动态库生效
安装pcre
#cd /usr/local/src
tar -zxvf pcre-8.31.tar.gz
cd pcre-8.31
./configure; 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)完后,再把它复制回原处,因为很多软件都依赖它,编译时也需要用到。
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.31
注意:--with-pcre=/usr/local/src/pcre-8.31指向的是源码包解压的路径,而不是安装的路径,否则会报错
make && make install
/usr/local/nginx/sbin/nginx #启动nginx
添加ngxin到系统服务,设置nginx开启启动
vi /etc/rc.d/init.d/nginx #编辑启动文件添加下面内容
=======================================================
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
=======================================================
:wq! #保存退出
chmod 755 /etc/rc.d/init.d/nginx #赋予文件执行权限
chkconfig nginx on #设置开机启动
/etc/rc.d/init.d/nginx restart #重启
service nginx restart
当然Nginx也可以用yum安装
添加nginx yum repository库
vi /etc/yum.repos.d/nginx.repo #新建nginx yum库,并添加下面的内容
=======================================================
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
=======================================================
wq #保存退出
yum -y install nginx #yum安装nginx,这里安装的为nginx官网稳定版,不一定是最新版
编译安装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=/etc/ -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -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] 加入以下两行
datadir = /var/lib/mysqldb
socket=/tmp/mysql.sock)
./scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysqldb #生成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,再重复以上步骤
vi /etc/profile #把mysql服务加入系统环境变量,以后可直接用mysql、mysqladmin、mysqldump等命令:在最后添加下面这一行
export PATH=$PATH:/usr/local/mysql/bin
:wq! #保存退出
下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
shutdown -r now #需要重启系统,等待系统重新启动之后继续在终端命令行下面操作
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: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;
编译安装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 --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 --enable-trace-avrs
配置完后会有警告提示:
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/
ls -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
一、重新安装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
二、去除 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.soextension =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-mysqlmake &&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
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
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
#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
系统运维 温馨提醒:
找到:;date.timezone =
修改为:date.timezone = PRC #设置时区
找到:expose_php = On
修改为:expose_php = OFF #禁止显示php版本的信息,新建环境时先打开,便于排错,=设置好后再关闭
找到:short_open_tag = Off
修改为:short_open_tag = ON #支持php短标签
把PHP配置文件中 Date区改成如下
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Asia/Shanghai" #当时也可以设置成上面的参数 PRC
; 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
# cd ext/phar
# wget http://pear.php.net/go-pear.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
(
# /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
(
# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
)
cd ..
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
(
# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
)
cd ..
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
(
# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
)
cd ..
5、ImageMagick
ImageMagick是一套功能强大、稳定而且免费的工具集和开发包,可以用来读、写和处理超过89种基本格式的图片文件,包括流行的TIFF, JPEG, GIF, PNG, PDF以及PhotoCD等格式。利用ImageMagick,你可以根据web应用程序的需要动态生成图片, 还可以对一个(或一组)图片进行改变大小、旋转、锐化、减色或增加特效等操作,并将操作的结果以相同格式或其它格式保存。对图片的操作,即可以通过命令行进行,也可以用C/C++、Perl、Java、PHP、Python或Ruby编程来完成。同时ImageMagick提供了一个高质量的2D工具包,部分支持SVG。
wget ftp://mirror.aarnet.edu.au/pub/imagemagick/ImageMagick-6.7.0-10.tar.gz
tar zxvf ImageMagick-6.7.0-10.tar.gz
cd ImageMagick-6.7.0-10
./configure
make
make install
cd ..
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
make
make install
(
# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
Installing header files: /usr/local/php/include/php/
)
cd ../
7、ZendOptimizer-3.3.9安装
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
8、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
# /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>、测试连接
$conn=mssql_connect("egServer70","sa",xaj!@34);
//test
if($conn)
{
echo "ok";
} else
{
echo "no";
}
?>
这里做一个WEB服务器(WEB的搭建上面已经配置完成),phpMyAdmin管理Mysql数据库,用户通过FTP更新网站