我爱linux

我是一个linux运维从业者,这个网站记录一些平时调试linux相关文档及生活随笔

Archive for the ‘php’ tag

Debian 6(Squeeze)编译搭建shopex或ecshop环境

without comments

Debian 6(Squeeze)编译搭建shopex或ecshop环境 Nginx+php5.2.x+Mysql+ZendOptimizer

shopex环境目前只支持php5.2.x,是因为它只支持Zend Optimizer,高版本的Zend Guard是不支持的, 而debian 6 默认安装php是5.3.x,这个版本的php是不支持Zend Optimizer,只支持Zend Guard.所以很矛盾呀,要想使用shopex系统,要么使用debian5 ,但又纠结于想用更高版本的debian6 ,所以我们这里讲述如何在debian6 系统上手动编译安装 支

shopex环境的搭建。真是没办法,老实说不愿破坏debian自带的软件包管理系统

一、安装nginx

添加nginx源 vi /etc/apt/sources.list

deb http://nginx.org/packages/debian/ squeeze nginx
deb-src http://nginx.org/packages/debian/ squeeze nginx

apt-get update
apt-get install nginx

这样我们就能升级到最新稳定版本的nginx,截至目前是1.0.10

二、安装mysql-server及编译所需库文件

apt-get install mysql-server libmysqlclient15-dev

三、编译安装php5.2.x

准备php编译所需的依赖包

aptitude install libgd2-noxpm-dev libxml2-dev libcurl3-dev libmhash-dev libmcrypt-dev libxslt-dev libpspell-dev libbz2-dev libglobus-openssl-dev

安装编译环境

apt-get install build-essential

下载php3.2.17
wget http://am.php.net/distributions/php-5.2.17.tar.gz

下载php-fpm补丁
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
gzip -d php-5.2.17-fpm-0.5.14.diff.gz

tar zvxf php-5.2.17.tar.gz

cd php-5.2.17
patch -p1 < ../php-5.2.17-fpm-0.5.14.diff

./configure –prefix=/usr/local/php5 –with-iconv –with-zlib –enable-xml –enable-fastcgi –enable-fpm –with-curl –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-mhash –enable-sockets –with-xmlrpc –enable-zip –with-mysql –with-mysqli –enable-ftp –with-jpeg-dir –with-freetype-dir –with-png-dir –enable-bcmath –enable-calendar –enable-exif –with-openssl –with-bz2

make
make install

cp php.ini-dist /usr/local/php5/lib/php.ini

vi /usr/local/php5/etc/php-fpm.conf

去掉前面的注释

<value name=”user”>nobody</value>
<value name=”group”>nogroup</value>

ln -s /usr/local/php5/sbin/php-fpm /etc/init.d/php-fpm

/etc/init.d/php-fpm start

修改默认主机的配置:

vi /etc/nginx/conf.d/default.conf

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}

注意:/usr/share/nginx/html$fastcgi_script_name; 前面的目录是默认主目录的位置,请根据你自己的实际情况修改,默认从nginx.org源安装的nginx最新版本,默认主目录

是/usr/share/nginx/html

/etc/init.d/nginx restart

好了,写个info文件,测试一下nginx+php+mysql是否完美结合了:)

四、安装ZendOptimizer

下载ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz,这是ZendOptimizer的最后一个版本了,也是shopex和ecshop能支持的ZendOptimizer,更高的版本是ZendGuardLoader,

但目前shopex等都不支持呀,非常让人纠结,要不今天我们也不会写这篇文章指导大家搭建合适的环境。

make /usr/local/zend
把解压后的so文件,拷贝到刚才建立的目录
vi /usr/local/php5/lib/php.ini
增加:
zend_extension= /usr/local/zend/ZendOptimizer.so

重启一下 php-fpm 应该马上生效了

自此,shopex或者ecshop的安装环境已经搭建成功。

后续:

五、加入memcache支持

aptitude install memcached

apt-get install m4 autoconf

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

cd memcache-2.2.6

/usr/local/php5/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519

./configure –enable-memcache –with-php-config=/usr/local/php5/bin/php-config –with-zlib-dir
make
make install

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

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

增加下面4句

extension_dir = “/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/”
extension = memcache.so
memcache.chunk_size = 32768
memcache.hash_strategy = consistent

一般教程都是只加上面2句,建议把下面2句也加上,修改一下默认的一些参数,使memcache的使用性能更加有效率

六、加入eAccelerator支持

wget http://cdnetworks-kr-1.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.zip
unzip eaccelerator-0.9.6.1.zip
cd eaccelerator-0.9.6.1

/usr/local/php5/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519

./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php5/bin/php-config
make
make install

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

extension=”eaccelerator.so”
eaccelerator.shm_size=”32″
eaccelerator.cache_dir=”/var/cache/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=”"
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”3600″
eaccelerator.shm_prune_period=”3600″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
eaccelerator.keys = “disk_only”
eaccelerator.session = “disk_only”
eaccelerator.content = “disk_only”

保存

make /var/cache/eaccelerator
chmod -R 777 /var/cache/eaccelerator

因为之前安装memcache,已经加了extension_dir = “/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/”,所以安装eaccelerator就不加这句了,如果实际操作

中没装memcache,那就需要在php.ini中加入这句,或者直接指定eaccelerator.so的绝对路径

重启一下 php-fpm 应该马上生效了

Written by zhangweibo

十二月 10th, 2011 at 5:03 上午

Debian 6(Squeeze)安装 Nginx + PHP5 + Spawn-fcgi + MySQL(二)

without comments

之前,给大家讲了Debian 6(Squeeze)安装 Nginx + PHP5 + PHP-FPM + MySQL(一),但因为要修改源,所以可能有些同学不大愿意,这里我们讲一下不修改源的情况下,怎么实现nginx的php环境

1:安装 MySQL 5

apt-get install mysql-server mysql-client

在弹出的页面输入2次密码

修改mysql配置文件,去掉innodb,这样可以节省不少内存
vi /etc/mysql/my.cnf

增加下面语句
skip-innodb

保存后,mysql重启一下就生效

2:安装Nginx + PHP5

apt-get install php5-cgi php5-mysql php5-gd php5-imagick php5-mcrypt php5-memcache memcached nginx

安装成功后,rcconf 把多余的服务x11-common去掉

mkdir /var/www
chown www-data:www-data /var/www

修改memcache的端口和内存大小
vi /etc/memcached.conf

vi /etc/php5/cgi/php.ini
修改下面这句
cgi.fix_pathinfo=1

3:安装Spawn-fcgi
Spawn-fcgi和php-fpm都能很好的实现nginx的php环境,其实对一些小规模的网站来说,Spawn-fcgi也是能很好的工作的,不见得非要php-fpm。

apt-get install spawn-fcgi

4:配置spawn-fcgi
系统启动的时候,自动加载spawn-fcgi
vi /etc/rc.local
增加下面语句
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid -C 4

这个我们是用了 -c 4 代表启动4个php5-cgi进程,大家可以根据自己的需要启动相应的进程数,我的256M的vps,我默认启用3-4个就能满足要求了。

5:配置nginx:
修改nginx的配置文件
vi /etc/nginx/nginx.conf
修改以下字段
worker_processes 4;
在我256M的vps上,我修改成4-6个,满足一般网站的访问绰绰有余

接着
vi /etc/nginx/sites-available/default

添加:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
}

保存后,重启nginx
/etc/init.d/nginx restart
写一个测试php页面

如果能正常显示那页面,那就大功告成

Written by zhangweibo

四月 24th, 2011 at 3:34 下午

Posted in debian,nginx,Php

Tagged with , , , , ,

debian下为PHP安装eAccelerator及配置

without comments

1:安装编译环境和php的 dev包

apt-get install build-essential php5-dev bzip2

2:下载并编译eAccelerator

cd /tmp
wget http://cdnetworks-kr-1.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.zip
unzip eaccelerator-0.9.6.1.zip
cd eaccelerator-0.9.6.1
phpize
./configure
make
make install

安装完毕

3:修改配置文件,有时候可能这个配置文件没有,那就直接创建1个

vi /etc/php5/conf.d/eaccelerator.ini
这里的配置文件路径,可能大家的服务器路径会有所不同,请大家选择自己的php的conf目录

extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/var/cache/eaccelerator"
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"

这里针对小内存vps提几个注意点:
默认配置文件有2个参数要重点注意
eaccelerator.shm_ttl="0"
当共享内存已满时,超过“shm_ttl”秒没有被访问过的脚本将被删除,默认值是“0”秒,表示从来不会删除。

eaccelerator.shm_prune_period="0"
当共享内存已满时,如果有一个新的脚本文件要加入共享内存,但此时共享内存已经用完,这样就会删除在“shm_prune_period”秒之前的未被访问过的脚本缓存,但有个前提就是这个新的脚本文件在“shm_prune_period” 秒之前被执行过。默认值为“0”,意思是不删除任何脚本缓存。

由于vps内存很有限,所以为了最大让缓存利用率提高,大家可以对这2个参数进行调整
eaccelerator.shm_ttl=”3600″
eaccelerator.shm_prune_period=”1800″

以上单位都是秒

4:创建cache目录
mkdir -p /var/cache/eaccelerator
chmod 0777 /var/cache/eaccelerator

ok。重启php-fpm和nginx eAccelerator就生效了

FAQ:
1:如果在编译过程中提示没有phpize这个命令?
解决办法:apti-get install php5-dev

至于eAccelerator的管理,请参考我的另外一篇文章
http://www.5ilinux.com/programming/php/15.html

Written by zhangweibo

四月 15th, 2011 at 1:21 下午

Posted in debian,Php

Tagged with , ,