[rhel5使用yum源]
[rhel5下安装使用php5.2]
[PHP大量Session的散列及过期回收]
[centos 5 上安装php 组件]
[debian php+mysql+nginx+redis最新安装源]
[php编译时错误处理之iconv]
[rhel5使用yum源]
1、删除原有的rpm包本机已经安装的yum包:
yum-security-1.1.16-13.el5_4.1
yum-rhn-plugin-0.5.4-17.el5
yum-metadata-parser-1.1.2-3.el5
yum-3.2.22-33.el5
yum-updatesd-0.9-2.el5
将其卸载:
rpm -e yum-updatesd
rpm -e yum-rhn-plugin --nodeps
rpm -e yum-security
rpm -e yum-metadata-parser --nodeps
rpm -e yum --nodeps
2、下载相关软件包
http://centos.ustc.edu.cn/centos/5/os/x86_64/CentOS/yum-3.2.22-37.el5.centos.noarch.rpm
http://centos.ustc.edu.cn/centos/5/os/x86_64/CentOS/yum-fastestmirror-1.1.16-16.el5.centos.noarch.rpm
http://centos.ustc.edu.cn/centos/5/os/x86_64/CentOS/yum-metadata-parser-1.1.2-3.el5.centos.x86_64.rpm
http://centos.ustc.edu.cn/centos/5/os/x86_64/CentOS/yum-utils-1.1.16-16.el5.centos.noarch.rpm
3、安装
rpm -ivh --force yum-metadata-parser-1.1.2-3.el5.centos.x86_64.rpm
rpm -ivh --nodeps yum-fastestmirror-1.1.16-16.el5.centos.noarch.rpm
rpm -ivh --nodeps yum-3.2.22-37.el5.centos.noarch.rpm
rpm -ivh yum-utils-1.1.16-16.el5.centos.noarch.rpm
注意:请根据机器上的相关包来实际进行操作。
4、修改源
具体修改过程请参考本站另一篇文章。
cd /etc/yum.repos.d/
rm -fv ./*
vim CentOS-Base.repo
5、更新
yum update
6、安装时出现的问题
GPG key retrieval failed: [Errno 14] HTTP Error 404: Not Found
这是没有gpg验证时出现的问题,需要导入其发行的key
rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
即可解决问题。如使用'rpmforge'源:
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
其实在安装后它会在'/etc/yum.repos.d'目录生成其源库文件。
注意:第三方的yum源有其gpg key,注意在使用时导入,否则的话会出现如下的一些错误:
You could try using --skip-broken to work around the problem
You could try running:
package-cleanup --problems
package-cleanup --dupes
rpm -Va --nofiles --nodigest
当然也可以使用如下的指令来进行安装:'yum --nogpgcheck install xxx'。
查看系统中的gpg pub key:
rpm -qa gpg-pubkey*
[rhel5下安装使用php5.2]
注意:这里只讲解使用yum来安装的过程。
1、utterramblings源
安装相应的GPG key
# rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
新建一个repo
# /etc/yum.repos.d/utterramblings.repo
[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
#yum install php
安装出来的就是 php5.2
注意:这个源里没有包含php-fpm,如果对它的需求的话可将其更新为其它源。
2、CentALT源
rpm -ivh http://centos.alt.ru/repository/centos/5/x86_64/centalt-release-5-3.noarch.rpm
[CentALT]
name=CentALT Packages for Enterprise Linux 5 - $basearch
baseurl=http://centos.alt.ru/repository/centos/5/$basearch/
enabled=1
gpgcheck=0
执行:
yum update
yum install nginx php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php php-eaccelerator
系统自动会选择php5.2.17 相关包和模块。
注意:由于有mysql等相关的依赖,会对其它程序产生一定的影响。
3、相关问题
3.1 apache安装出错的解决办法
httpd-devel-2.2.3-53.el5.centos.3.i386 from update has depsolving problems
--> Missing Dependency: httpd = 2.2.3-53.el5.centos.3 is needed by package httpd-devel-2.2.3-53.el5.centos.3.i386 (update)
Error: Missing Dependency: httpd = 2.2.3-53.el5.centos.3 is needed by package httpd-devel-2.2.3-53.el5.centos.3.i386 (update)
You could try using --skip-broken to work around the problem
You could try running:
package-cleanup --problems
package-cleanup --dupes
rpm -Va --nofiles --nodigest
解决办法:升级openssl与openssh
# rpm -Uvh ftp://ftp.pbone.net/mirror/atrpms.net/el5-x86_64/atrpms/stable/libedit0-3.0-1.20090722cvs.el5.x86_64.rpm
# yum --nogpgcheck update -y openssh* openssl*
# ssh -V
会输出openssh的版本信息,可以查看到其是否已升级。这个操作可以通过ssh终端进行操作,不用担心连接会中断。
3.2 apc.shm_size now uses M/G suffixes 的解决
前几天在web服务器上装了APC的最新版3.14版(2010-08-05发布的),在php的错误日志中看到如下的提示:
[27-Oct-2010 17:30:01] PHP Warning: PHP Startup: apc.shm_size now uses M/G suffixes, please update your ini files in Unknown on line 0
原来是在php.ini中我设置了apc的缓存大小,这样设置的:apc.shm_size=128
而实际上需要在后面加上M或者G,于是修改为:apc.shm_size=128M
[PHP大量Session的散列及过期回收]
业务访问量比较大,因为程序的需要,session的过期时间设置的是2小时,导致/tmp下堆积了几十万的session文件,进而导致内核占用的cpu急剧上升。因为session的读写涉及到大量小文件的随机读写,并且是集中在一个目录下,iowait也急剧升高。
首先考虑将session放入内存中
最简单的办法莫过于将/tmp挂载为tmpfs文件系统,也就是内存中。
第二步,将session存储到不通的目录中
php本身支持session的多级散列
在php.ini中,将
;session.save_path = /tmp
改为
session.save_path = "2;/tmp/session"
表示将session存储到 /tmp/session这个文件夹中,并且是用2及散列。保存退出,等第三步结束后重启php
第三步,创建session存储文件夹
php并不会自动去创建这些文件夹,这里提供了一些创建文件夹的脚本。下面这个脚本也好用:
I="0 1 2 3 4 5 6 7 8 9 a b c d e f"
for acm in $I;
do
for x in $I;
do
mkdir -p /tmp/session/$acm/$x;
done;
done
chown -R www-data:www-data /tmp/session
chmod -R 1777 /tmp/session
因为/tmp是用的内存,服务器重启后,里面的所有文件都会丢失,所以,需要把上面的脚本加入到 /etc/rc.local中,并且要放在启动php之前.
第四步,session的回收
session在经过session.gc_maxlifetime后会过期,但并不会马上被删除,时间长了以后会造成/tmp空间占用很大。下面这个命令可以删除过期的session,我这里定义的过期时间是2小时。
find /tmp/session -amin +120 -exec rm -rf {} \;
放入cron中,每小时执行一次。
[centos 5 上安装php 组件]
1、memcached.so
系统信息如下:
CentOS release 5.8
CPU = 64-bit, OS = 64-bit
Compiler GNU CC version 4.1.2 20080704 (Red Hat 4.1.2-48)
PHP = 5.3
注意:之前已安装了libmemcached-1.0及php和php的扩展
1.1、通过'pecl'进行安装,
Install the PECL Memcached extension.
Lets install the new PECL memcached extension in your web server. This new extension depends on libmemcached. You can grab the latest distribution of libmemcached from https://launchpad.net/libmemcached and compile it in your own machine. Make sure you have the dependencies met.
wget http://launchpad.net/libmemcached/1.0/0.34/+download/libmemcached-0.34.tar.gz
tar -zxvf libmemcached-0.34.tar.gz
cd libmemcached-0.34
./configure
make && make install
Considering everything went fine, lets install the PECL memcached extension
pecl install memcached
If everything goes fine, you should see the output similar like this
Build process completed successfully
Installing '/usr/lib/php5/20060613/memcached.so'
install ok: channel://pecl.php.net/memcached-1.0.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=memcached.so" to php.ini
Make sure that memcached.so is placed in your PHP extension_dir folder (here /usr/lib/php5/20060613). Add the line “extension=memcached.so” in your php.ini and restart your web server.
但是安装的过程中会报错,处理如下:
1.2、安装libmemcached
安装时出现了如下的错误提示:
In file included from ./libmemcached/common.h:72,
from ./libmemcached/csl/common.h:40,
from libmemcached/csl/context.cc:38:
./libmemcached-1.0/memcached.h:46:27: error: tr1/cinttypes: No such file or directory
make[1]: *** [libmemcached/csl/libmemcached_libmemcached_la-context.lo] Error 1
make[1]: Leaving directory `/export/home/build/sles-packages/memcached/libmemcached/libmemcached-1.0.8'
make: *** [all] Error 2
error: Bad exit status from /var/tmp/rpm-tmp.22791 (%build)
----
The header file tr1/cinttypes is not part of the distribution compiler development package (gcc/g++ 4.1.2):
----
In file included from ./libmemcached/common.h:72,
from ./libmemcached/csl/common.h:40,
from libmemcached/csl/context.cc:38:
./libmemcached-1.0/memcached.h:46:27: error: tr1/cinttypes: No such file or directory
make[1]: *** [libmemcached/csl/libmemcached_libmemcached_la-context.lo] Error 1
make[1]: Leaving directory `/sf/libmemcached-1.0.9'
make: *** [all] Error 2
处理如下:
# yum install gcc44 gcc44-c++ libstdc++44-devel
# export CC=/usr/bin/gcc44
# export CXX=/usr/bin/g++44
重新编译安装libmemcached-1.0.9
# ./configure --prefix=/usr/local/libmemcached --with-memcached
# make
# make install
至此,安装libmemcached成功。现在可以来安装'memcached.so'扩展。
pecl install memcached
......
----------------------------------------------------------------------
Libraries have been installed in:
/tmp/pear/temp/pear-build-rootfDhZ6q/memcached-2.1.0/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootfDhZ6q/install-memcached-2.1.0" install
Installing shared extensions: /tmp/pear/temp/pear-build-rootfDhZ6q/install-memcached-2.1.0/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
running: find "/tmp/pear/temp/pear-build-rootfDhZ6q/install-memcached-2.1.0" | xargs ls -dils
20840555 4 drwxr-xr-x 3 root root 4096 Sep 17 16:56 /tmp/pear/temp/pear-build-rootfDhZ6q/install-memcached-2.1.0
20840585 4 drwxr-xr-x 3 root root 4096 Sep 17 16:56 /tmp/pear/temp/pear-build-rootfDhZ6q/install-memcached-2.1.0/usr
20840586 4 drwxr-xr-x 3 root root 4096 Sep 17 16:56 /tmp/pear/temp/pear-build-rootfDhZ6q/install-memcached-2.1.0/usr/local
20840587 4 drwxr-xr-x 3 root root 4096 Sep 17 16:56 /tmp/pear/temp/pear-build-rootfDhZ6q/install-memcached-2.1.0/usr/local/php
20840588 4 drwxr-xr-x 3 root root 4096 Sep 17 16:56 /tmp/pear/temp/pear-build-rootfDhZ6q/install-memcached-2.1.0/usr/local/php/lib
20840589 4 drwxr-xr-x 3 root root 4096 Sep 17 16:56 /tmp/pear/temp/pear-build-rootfDhZ6q/install-memcached-2.1.0/usr/local/php/lib/php
20840590 4 drwxr-xr-x 3 root root 4096 Sep 17 16:56 /tmp/pear/temp/pear-build-rootfDhZ6q/install-memcached-2.1.0/usr/local/php/lib/php/extensions
20840591 4 drwxr-xr-x 2 root root 4096 Sep 17 16:56 /tmp/pear/temp/pear-build-rootfDhZ6q/install-memcached-2.1.0/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626
20840584 232 -rwxr-xr-x 1 root root 231202 Sep 17 16:56 /tmp/pear/temp/pear-build-rootfDhZ6q/install-memcached-2.1.0/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/memcached.so
Build process completed successfully
Installing '/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/memcached.so'
install ok: channel://pecl.php.net/memcached-2.1.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=memcached.so" to php.ini
将它加入到php.ini文件中。
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20090626"
extension=memcached.so
1.3、memcahce.so
wget http://pecl.php.net/get/memcache-2.1.0.tgz
tar zfvx memcache-2.1.0.tgz
cd memcache-2.1.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
安装比之于memcached有简单一些。
2、redis.so
phpredis项目的主页:https://github.com/owlient/phpredis 到这里下载最新的代码。
将其解压后,进行如下操作安装:
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make && make install
然后'make install'将生成的.so文件拷贝到php扩展的目录下。
#make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
[debian php+mysql+nginx+redis最新安装源]
dotdeb.org上有许多最新稳定包,最新的mysql 5.1的包,还有最新的php5.4.x,以及php-fpm。
Dotdeb is a repository containing packages to turn your Debian boxes into powerful, stable and up-to-date LAMP servers :
* PHP 5.3,
* useful PHP extensions : APC, imagick, Pinba, xcache, Xdebug, XHprof…
* MySQL 5.5 and 5.1,
* Percona toolkit,
* Nginx,
* Passenger,
* Redis…
Dotdeb supports :
* both Debian 6.0 “Squeeze” and Debian 5.0 “Lenny“
* both amd64 and i386 architectures
The packages from Dotdeb should work on Ubuntu, but no additional support will be provided.
首先编辑sources.list来加入dotdeb的源:
vim /etc/apt/sources.list
deb http://packages.dotdeb.org squeeze all
deb-src http://packages.dotdeb.org squeeze all
(Optional) if you want to install PHP 5.4 on Debian 6.0 “Squeeze”, add these two lines too :
deb http://packages.dotdeb.org squeeze-php54 all
deb-src http://packages.dotdeb.org squeeze-php54 all
然后把lenny源临时替换为sid源,apt-get update用apt-get install nginx安装最新稳定版。安装完成以后在恢复lenny源。
After many requests from several users and after many months of promise, the Dotdeb repositories are GPG-signed. Yes, you can now get rid of the annoying “WARNING: The following packages cannot be authenticated!” message!
Waiting for a dotdeb-keyring package, you just have to get the key and add it to your trusted keys’ keyring :
gpg --keyserver keys.gnupg.net --recv-key 89DF5277
gpg -a --export 89DF5277 | apt-key add -
或者
wget http://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg | apt-key add -
旧版本的源:
http://archives.dotdeb.org/
我们安装一些php5支持组件,按照自己的需要添加:
apt-get install php5-mysql php5-sqlite php5-gd php5-xsl php5-xmlrpc php5-memcache php5-mcrypt php5-curl php5-apc
安装mysql 5.1:
apt-get install mysql-server-5.1
安装memcached缓存支持:
apt-get install memcached
最后安装我们需要的php-fpm:
apt-get install php5-fpm
[php编译时错误处理之iconv]
选项为:
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv=/usr/local/libiconv --with-zlib --enable-mbstring --enable-xml --with-gd --with-jpeg-dir=/usr/local/jpeg --with-png-dir --with-freetype-dir=/usr/local/freetype --with-curl --enable-mbstring --with-mcrypt --enable-soap --enable-sockets --with-ldap --with-gettext --enable-zip
php编译时报iconv相关的错误:
undefined reference to `libiconv_open'
collect2: ld returned 1 exit status
编辑Makefile在'EXTRA_LIBS'行末加上:
EXTRA_LIBS = ..... -lcrypt
在最後加上 -liconv,例如:
EXTRA_LIBS = ..... -lcrypt -liconv
在键入'make‘继续即可。
另一种办法
make ZEND_EXTRA_LIBS='-liconv'
这个错误的原因可能php找不到iconv库文件,所以我们需要下载安装它。
#wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
#tar -zxvf libiconv-1.14.tar.gz
#cd libiconv-1.14
# ./configure --prefix=/usr/local/libiconv
# make
# make install
完成之后在编译php的./configure命令加上–with-iconv=/usr/local/libiconv指向iconv位置。即可解决问题