Techyou labs
真正的爱应该超越生命的长度,心灵的宽度,灵魂的深度
常用标签
您正在查看:标签 php5 下的文章

Nginx+Apache(suexec+fcgid)+PHP5.3.x+Mysql5.1.x+Pureftpd+Quota服务器部署笔记
首选32bit centos
源码包全部放在/usr/src/source_package下
1:初始化环境

#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 mhash mhash-devel libmcrypt libmcrypt-devel libc-client libc-client-devel

2:安装libevent

#wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz#tar xf libevent-1.4.14b-stable.tar.gz#cd libevent-1.4.14b-stable #./configure --enable-shared#make && make install

3:安装pcre

#wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz#tar xf pcre-8.10.tar.gz#cd pcre-8.10/#./configure --enable-shared --enable-utf8 --enable-unicode-properties#make && make install

4:安装libunwind

#wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99.tar.gz#tar xf libunwind-0.99.tar.gz#cd libunwind-0.99#./configure --enable-shared#make && make install

5:安装google-perftools

#wget http://google-perftools.googlecode.com/files/google-perftools-1.6.tar.gz#tar xf google-perftools-1.6.tar.gz#cd google-perftools-1.6#./configure --enable-shared##注:64bit 必须加上--enable-frame-pointers#make && make install

6:安装nginx.

#wget http://labs.frickle.com/files/ngx_cache_purge-1.0.tar.gz#tar zxvf ngx_cache_purge-1.0.tar.gz#wget http://nginx.org/download/nginx-0.8.50.tar.gz#tar zxvf nginx-0.8.50.tar.gz#cd nginx-0.8.50/#cd ../#useradd -d /dev/null -s /sbin/nologin -c "Nginx Runner" -r www-data#mkdir -p /zh/nginx#mkdir -p /tmp/nginx/client/cache#mkdir -p /tmp/nginx/proxy/cache#mkdir -p /tmp/nginx/fastcgi/cache

如想提速,可以将缓存目录划到/dev/shm下

#./configure --prefix=/zh/nginx --user=www-data --group=www-data --with-rtsig_module --with-select_module --with-poll_module --with-ipv6 --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_gzip_static_module -–with-file-aio --with-http_stub_status_module --http-client-body-temp-path=/tmp/nginx/client --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --with-google_perftools_module --add-module=/usr/src/source_package/ngx_cache_purge-1.0#make && make install

如需要无缝升级:

#cp -r --force objs/nginx /zh/nginx/sbin#/etc/init.d/nginx restart

7:Mysql5.1、PHP5.3.x安装编译mysql

#./configure --prefix=/usr/local/mysqld --enable-assembler --with-charset=utf8 --with-extra-charsets=all --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=max-no-ndb --enable-shared --with-tcp-port=3306 --with-mysqld-user=mysqld --with-low-memory --with-mysqlmanager

安装并初始化环境

# make # make install# cp support-files/my-medium.cnf /usr/local/mysqld/etc/my.cnf

更改目录权限

# chown -R mysqld /usr/local/mysqld # chown -R mysqld /var/mysqldata # chown -R mysqld:mysqld /usr/local/mysqld # chown -R mysqld:mysqld /var/mysqldata   # chmod 711 /usr/local/mysqld -R# chmod 755 /usr/local/mysqld/lib/ -R# chmod 700 /var/mysqldata -R

初始化数据库

# /usr/local/mysqld/bin/mysql_install_db --user=mysqld --datadir=/var/mysqldata --basedir=/usr/local/mysqld --skip-name-resolve --defaults-file=/usr/local/mysqld/etc/my.cnf

php编译:

#./configure --prefix=/zh/php5 --enable--mod-charset --enable-roxen-zts --with-libxml-dir=/usr --with-layout=GUN --with-config-file-path=/zh/php5/etc --with-config-file-scan-dir=/home/*/etc --with-openssl --with-zlib --enable-sigchild --enable-bcmath --enable-calendar --with-curl --with-curlwrappers --enable-exif --enable-ftp --disable-rpath --with-gd --with-jpeg-dir --with-png-dir --enable-gd-native-ttf --with-gettext --with-mhash --with-imagick --with-imap --with-imap-ssl --enable-mbstring --with-mcrypt --with-mysql=mysqlnd --enable-mbregex --with-mysql-sock --with-mysqli --with-pdo-mysql --with-pdo-sqlite --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-sysvsem --with-xmlrpc --enable-zip --without-pear --enable-shmop --enable-pcntl --with-libevent=shared --with-kerberos --enable-phar --enable-session --enable-simplexml --enable-snmp --enable-sqlite3 --enable-tidy --enable-tokenizer --enable-xml --enable-xmlreader --enable-xmlrpc --enable-xmlwriter --enable-xsl --enable-fastcgi --enable-cgi --enable-shared#make#make install

安装eAccelerator、Memcache、suhosin扩展:

1:memcache#/zh/php5/bin/phpize#./configure --with-php-config=/zh/php5/bin/php-config --enable-shared --enable-memcache#make && make install2:eaccelerator#/zh/php5/bin/phpize#./configure --with-php-config=/zh/php5/bin/php-config --enable-shared --enable-eaccelerator --with-gnu-ld#make && make install3:suhosin#/zh/php5/bin/phpize#./configure --with-php-config=/zh/php5/bin/php-config --enable-shared --enable-suhosin#make && make install

添加至php.ini

5:Apache(suexec+mod_fcgid)安装

http://blog.37hi.com/archives/229/

http://blog.37hi.com/archives/221/

6:为Apache安装mod_rpaf模块获取真实IP

tar -xf mod_rpaf-0.6.tar.gzcd mod_rpaf-0.6/usr/local/apache2/bin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c

编辑httpd.conf文件添加:

#rpaf_moduleLoadModule rpaf_module modules/mod_rpaf-2.0.so#Mod_rpaf settingsRPAFenable OnRPAFproxy_ips 127.0.0.1 [your_ips]RPAFsethostname OnRPAFheader X-Forwarded-For#rpaf_module end

[your_ips]请修改为你本机所监听web服务的ip.多个IP用空格空开.

7:pureftpd安装。

8:简单优化

9:编写web控制端。

拖了两天,今晚终于有点时间来写下篇了。可是,对着电脑,却有点不知道从何说起。或许,就照着ZEND FRAMEWORK来说吧。当然,我会把握要点,记得这篇文章是以zend framework为例来阐述我对面向对象方式编程的认识,而不是一篇zend framework的入门手册,并且,这也不会是一个面向对象的入门教程,而是我对面向对象的理解。
一、统一入口文件
在很多人眼里,php仍然不能算是“完全”面向对象的,理由就是面向对象应该是所有程序要全部对象化,而PHP还留有一个入口文件。但这种学术上的争论,和我们其实是没什么关系的。我们只需要知道,作为一个完全面向对象的应用,除了index.php之外,所有程序都应该是以类的方式编写的。
在zend framework中,用到了rewrite技术,rewrite不仅利用伪静态功能吸引搜索引擎收录,还可以禁止index以为的PHP文件直接运行从而避免安全隐患。在joomla中,rewrite是可以在后台中选择的,即使是面向过程的项目,discuz 和phpwind也都提供了rewrite的选项,而在zend framework中,说起来可能会让很多zf的初学者呕血,其实用或者不用rewrite,是根本不需要配置的,只不过是链接的URL地址不同罢了。很奇怪的,似乎所有资料上都没有提及这一点,其实,我们完全可以在IIS下和绝大多数支持PHP的虚拟主机上使用zend framework而不必担心rewrite的问题。
当然了,我个人对rewrite技术还是非常拥护的,对我而言,这项技术至少有三个好处:1、用伪静态方式增加搜索引擎搜录;2、保护重要文件及危险文件不被运行和下载;3、用PHP生成图片文件时,其URL地址和真实的图片地址格式完全相同。
所以,一个好的面向对象程序,应该要统一入口文件,并用rewrite功能限制不合规范的其它php文件的使用。
二、MVC模式
MVC模式是一种非常经典的编程方式。我在本文的上篇就已经提过,如果纯粹追求执行效率,每个程序页面一个文件,才是最为高效的。但是人力有其极限,所以终究需要把文件切割开来,并按一定规律对文件进行归类。如果你做PHP足够久,应该见过各种五花八门的切割和文件归类方式,而其中,升华为模式并为主流所接受的,只有MVC。
如果说程序和页面分开,也就是view视图独立,已经为大家所公认,那么控制器和模型是不是要分开,很多人还是有不同意见的。一开始我也觉得,小项目里不需要这么讲究,但是不久之后就发现模型的好处了。模型在功能上很大程度与面向过程项目中的函数库相似,函数库的好处,我在本文上篇一开始久已经说过,这些理由同样适合与模型,功能总是应该被细分为函数的,MODEL只不过是对这些函数进行统一归类而已。模型与函数库的最主要区别,在于我们通常为每个数据表建立一个模型,这样,每个模型中的方法不至于过多,方法的命名也可以得到统一。比如函数库中,删除文章命名为delArticle(),删除图片命名为 delPicture(),删除用户命名为delUser(),而用模型一分开,统一都叫del()是不是整洁多了?
所以,无论项目大小,只要用到数据库,那么使用MODEL总是值得的。

若干年前,PHP5由面向过程转变为面向对象语言,在各个技术论坛上掀起了滔天大浪,很多人断言PHP自取灭亡,但不久之后尘埃落定,大部分人由不支持转向支持,PHP也由4.0时代被人戏称为小孩子的玩具,摇身一变而成为仅次于java和c的第三大语言。身处整个争论过程,我自以为对面向对象有了完整的认识,并逐渐开始全面采用面向对象方式编程,2008年以后,甚至开始只在zend framework框架下编写程序。
但最近数月的工作经历让我开始反省,我开始重新思索那个当年最著名的问题:“如果真的完全面向对象,我们何不直接使用JAVA?我们为什么需要两个 JAVA呢?”是的,用PHP,理由之一,就是我们不一定要面向对象。一切编程技术和编程理念都只是手段,用最短的时间达成客户需求,才是我们的目的所在,抛开这一目的而空谈任何技术,都无疑是错误的,一个很典型的例子,开源的论坛程序中,所有PHPER人人都推崇PHPBB,而对DISUCZ的代码技术含量嗤之以鼻,可是,真正建论坛的时候,我们谁用PHPBB了?国内的大半论坛,都是DISCUZ的。近两年多时间,我都拘泥于面向对象,而浪费了大量的时间,这是我犯下的一个严重错误。
所以,我决定重新梳理一下我对PHP编程的认识,以后在项目选型时可以选择更合适的架构而不是唯技术是从。欢迎大家拍砖。
一、函数的作用
时至今日,任何一个非计算机专业的朋友也都该学过一门计算机语言,在国内,通常是basic,如果足够幸运,也可能是C,分支语句和循环语句是其中的必修内容,而如果函数学得不好,估计马马虎虎,也就过去了。哪怕世上没有函数这种东西,程序一样可以完成所有的功能(天可怜见,最近几个月,我刚刚见识了这样一个项目)。
那么,我们要函数什么用呢?无数教科书告诉我们,是为了可复用性。是的,一个函数写完之后,下次用到同样功能,直接调用就可以了,不用再重新写一遍了,这是函数发明的本意和基本功能。可是,如果我们预计一个功能不那么常用,是不是就该不用函数了呢?不是的,哪怕是采用面向过程的编程方式,我们仍然要尽可能的使用函数,并尽可能的细分功能,为每个功能写一个独立的函数。采用函数编程,有以下几个明显的优点:

September 16, 2010

PHP install FAQ
2010-04-23 18:38

1.
Error: Configure: error: xml2-config not found. Please check your libxml2 installation.
Fix: yum install libxml2 libxml2-devel
# aptitude install libxml2-dev (For ubuntu)

2.
Error: configure: error: Cannot find OpenSSL’s
Fix: yum install openssl openssl-devel

3.
Error: Configure: error: Please reinstall the BZip2 distribution
Fix: yum install bzip2 bzip2-devel

安装编译所需要的库:

apt-get install libxml2-dev libmcrypt-dev libssl-dev libldap2-dev libmhash-dev libmysqlclient-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libsasl2-dev

安装libevent

cd ~/src
wget http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz
tar xf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
./configure --enable-shared
make
make install

ulimit -SHn 65535

安装pcre

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.00.tar.gz
tar zxvf pcre-8.00.tar.gz
cd pcre-8.00/
./configure
make && make install

安装libunwind#否则无法安装Google-perftools

cd /libunwind-0.99
./configure --enableshared
make
make install

安装google-perftools#mysql和nginx需要(64位必须加--enable-frame-pointers)

wget http://google-perftools.googlecode.com/files/google-perftools-1.5.tar.gz
./configure --enableshared --enable-frame-pointers
make
make install

下载purge #清除缓存用的

wget http://labs.frickle.com/files/ngx_cache_purge-1.0.tar.gz
tar zxvf ngx_cache_purge-1.0.tar.gz

wget http://nginx.org/download/nginx-0.8.32.tar.gz
tar zxvf nginx-0.8.32.tar.gz
cd nginx-0.8.32/
cd ../
./configure --prefix=/zh/nginx --user=www-data --group=www-data --with-rtsig_module --with-select_module --with-poll_module --with-ipv6 --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --http-client-body-temp-path=/tmp/nginx/client --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --with-google_perftools_module --add-module=/home/web_package/ngx_cache_purge-1.0

启动nginx错误解决办法
1:error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory
解决方法,在/lib中创建一个symbol link到/usr/local/pcre/lib/libpcre.so.0
sudo ln -s /usr/local/pcre/lib/libpcre.so.0 /lib
2:error while loading shared libraries: libprofiler.so.0: cannot open shared object file: No such file or directory

安装ImageMagick

cd ~/src
apt-get build-dep imagemagick
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
tar xf ImageMagick.tar.gz
cd ImageMagick-6.5.8-6/
./configure
make
aptitude install libperl-dev
make install

apt-get build-dep php
wget http://cn2.php.net/get/php-5.3.1.tar.bz2/from/this/mirror
tar xf php-5.3.1.tar.bz2

#下载imagick

cd ~/src
wget http://pecl.php.net/get/imagick-2.3.0.tgz
tar xf imagick-2.3.0.tgz
cp -R imagick-2.3.0 php-5.3.1/ext/imagick
cd php-5.3.1
./buildconf --force

#下载php-fpm

apt-get install batch
wget http://launchpad.net/php-fpm/master/0.6/+download/php-fpm-0.6~5.3.1.tar.gz
$ tar -xzf php-fpm-0.6~5.3.1.tar.gz
$ php-fpm-0.6-5.3.1/generate-fpm-patch
$ patch -d php-5.3.1 -p1 $ cd php-5.3.1
$ ./buildconf --force

./configure --prefix=/zh/php5 --with-fpm --with-libxml-dir=/usr --with-fpm-bin=/zh/php5/fpm --with-fpm-conf=/zh/php5/etc --with-fpm-user=www-data --with-fpm-group=www-data --with-layout=GUN --with-config-file-path=/zh/php5/etc --with-config-file-scan-dir=/zh/php5/etc --with-openssl --with-zlib --enable-bcmath --enable-calendar --with-curl --with-curlwrappers --enable-exif --enable-ftp --disable-rpath --with-gd --with-jpeg-dir --with-png-dir --enable-gd-native-ttf --with-gettext --with-mhash --with-imagick --with-imap --with-imap-ssl --with-ldap --enable-mbstring --with-mcrypt --with-mysql=mysqlnd --enable-mbregex --with-mysql-sock --with-mysqli --with-pdo-mysql --with-pdo-sqlite --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-sysvsem --with-xmlrpc --enable-zip --without-pear --enable-shmop --enable-pcntl --with-libevent=shared --with-kerberos

make
make install

安装记录

molyx:/home/web_package/php-5.3.1# make install
Installing PHP SAPI module: fpm
Installing PHP CLI binary: /zh/php5/bin/
Installing PHP CLI man page: /zh/php5/man/man1/
Installing build environment: /zh/php5/lib/php/build/
Installing header files: /zh/php5/include/php/
Installing helper programs: /zh/php5/bin/
program: phpize
program: php-config
Installing man pages: /zh/php5/man/man1/
page: phpize.1
page: php-config.1
/home/web_package/php-5.3.1/build/shtool install -c ext/phar/phar.phar /zh/php5/bin
ln -s -f /zh/php5/bin/phar.phar /zh/php5/bin/phar

update-rc.d php-fpm defaults
sed -i "s/nobody/www-data/g" /etc/php-fpm.conf
/etc/init.d/php-fpm start

make install
cp php.ini-dist /zh/php5/etc/php.ini
ln -s /zh/php5/sbin/php-fpm /etc/init.d/php-fpm
update-rc.d -f php-fpm defaults

编译后的php安装在/opt/php下面,php的配置文件是/opt/php/lib/php.ini

和其他Linux下不同,在Debian下这时候启动php-fpm会失败,原因是在Debian下php-fpm的配置文件中必须指定运行时的用户才行。
优化php-fpm

编辑php-fpm的配置文件/etc/php-fpm.conf,

* 去掉display_errors参数的注释,修改参数值为1
* 去掉sendmail_path参数的注释
* 去掉user,group参数的注释
* 修改max_children参数的值为10

安装php加速器eAccelerator

tar jxf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3
apt-get install -y autoconf
/zh/php5/bin/phpize
./configure --with-php-config=/zh/php5/bin/php-config --enable-eaccelerator --enable-shared
make
make install
mkdir /tmp/php/eaccelerator_cache

然后重启php-fpm,在phpinfo()页面中应该能看到eaccelerator的信息了。

附录:
memcache模块安装:

/zh/php5/bin/phpize
./configure --enable-memcache --enable-shared --with-php-config=/zh/php5/bin/php-config
make
make install
Suhosin模块安装:
/zh/php5/bin/phpize
./configure --with-php-config=/zh/php5/bin/php-config --enable-shared --enable-suhosin
make
make install
extension_dir = "/zh/php5/lib/php/extensions/no-debug-non-zts-20090626"
;suhosin module
[suhosin]
extension=suhosin.so
;memcache module
[memcache]
extension=memcache.so
;eaccelerator module
[eaccelerator]
;zend_extension="/zh/php5/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/php/eaccelerator_cache"
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"

错误解决
1:utf8_mime2text() has new signature, but U8T_CANONICAL is missing
安装c-client
apt-get install libc-client-dev
2:configure: error: libevent.a could not be found. Stop.
使用参数--with-libevent=shared
3:This c-client library is built with Kerberos support.
添加 --with-kerberos to your configure line. Check config.log for details