Apache+Fastcgi模块+APC经典配置推荐

前言 * FastCGI是一个程序接口,它能加速公共网关接口(CGI),CGI是一种用最常见的方式使Web服务器调用应用程序的Web应用程序。按一个FastCGI工具来看,用户要求进入一个网站并使用一个专门的应用软件的话,使用FastCGI能够快3到30倍。FastCGI是Web服务器的一种插件。

一、安装apache fastcgi模块:

下载地址:http://down.51cto.com/data/139939(51cto下载中心) tar-zxvfmod_fastcgi-current.tar.gz cdmod_fastcgi cpMakefile.AP2Makefile viMakefile修改top_dir=/usr/local/apache2#你的apache安装路径或者直接编(apache2.0已经安装) make makeinstall(这里采用apache而不采用nginx的原因是:虽然nginx有很多优点,但是对于大部分中小型网站来说,apache经过优化可以满足访问要求。)

二、安装MYSQL

tar-zxvfmysql-5.0.75.tar.gz//解压 cdmysql-5.0.75 ./configure--prefix=/usr/local/mysql--with-charset=gbk--with-extra-charsets=allmake makeinstall groupaddmysql//创建组mysql useradd-gmysqlmysql//创建mysql用户,把mysql加入到mysql组 cd/usr/local/mysql/ cpshare/mysql/my-medium.cnf/etc/my.cnf cpshare/mysql/mysql.server/etc/init.d/mysqld (以上是把mysql加入系统服务) chown-Rmysql.mysql/usr/local/mysql /usr/local/mysql/bin/mysql_install_db--user=mysql//初始化数据库 chown-Rmysql.mysql/usr/local/mysql/var /usr/local/mysql/bin/mysqld_safe--user=mysql //启动数据库(或者servicemysqldrestart)

三、安装php-fpm在安装PHP-FPM编译的时候会报找不到libevent,可以执行

yum-yinstalllibevent* wgethttp://www.monkey.org/~provos/libevent-1.4.12-stable.tar.gz tarzxvflibevent-1.4.12-stable.tar.gz cdlibevent-1.4.12 ./configure--prefix=/usr/local/libenent mak makeinstall
tar-jxvfphp-5.3.3.tar.bz2 cdphp-5.3.3 ./configure\ --prefix=/usr/local/php5--with-config-file-path=/usr/local/php5/etc\ --with-mysql=/usr/local/mysql/--with-mysqli=/usr/local/mysql/bin/mysql_config\ --with-zlib--with-curl--with-jpeg-dir--with-freetype-dir--with-png-dir\ --with-libxml-dir=/usr/--with-gd--with-openssl\ --with-openssl--with-ldap--with-ldap-sasl--with-xmlrpc--without-pear\ --enable-xml--enable-gd-native-ttf\ --enable-ctype--enable-calendar--enable-inline-optimization\ --enable-magic-quotes--with-bz2--enable-mbstring\ --enable-fpm--enable-safe-mode--enable-bcmath--enable-shmop\ --enable-sysvsem--enable-mbregex--enable-mbstring--enable-pcntl\ --enable-zip--enable-ftp--enable-sockets--enable-soap--with-libevent-dir=/usr/local/libevent/ make makeinstall cpsapi/fpm/init.d.php-fpm/etc/init.d/php-fpm chmod+x/etc/init.d/php-fpm cp-rsapi/fpm/php-fpm.conf/usr/local/php5/etc/

启动php-fpm/etc/init.d/php-fpm start此时启动应该会报错,说php-fpm.conf配置文件中很多选项没有打开,只要按照它的提示打开就OK。四、修改apache,让apache支持php-fpmvi httpd.conf

增加:LoadModulefastcgi_modulemodules/mod_fastcgi.so 有的话不用添加。 在vhosts.conf文件的项目中加入以下(如果不引用vhosts.conf的话可以把下面的语句加入http.conf的最后) ScriptAlias/cgi-bin/ /usr/local/php5/bin/ FastCgiExternalServer/usr/local/php5/bin/php-fpm-host127.0.0.1:9000 AddTypeapplication/x-httpd-php.php AddHandlerphp5-fastcgi.php Actionphp5-fastcgi/cgi-bin/php-fpm  Directory /usr/local/php5/bin/ Options-IndexesFollowSymLinks+ExecCGI Orderallow,deny Allowfromall  /Directory #Actionphp5-fastcgi/cgi-bin/php-fpm中的php-fpm一定要和FastCgiExternalServer中的文件名一样.而且/cgi-bin/和前面的ScriptAlias的路径也要一样,两句放一块就是说上面的映射也就是所有的.php文件都由/cgi-bin/php-fpm处理 否則會出錯的. 加完以上的,安装完成了。但是php-fpm.conf配置文件需要优化(常见优化见后期给出) 注:在增加了apc.so后总是出现linuxWarning:PHPStartup:Unabletoloaddynamiclibrary 后怎么更改都不行,后重新编译php-5.3.3,并加上 --with-libevent-dir=/usr/local/libevent参数,一切OK!最好不要用系统默认的

五、安装php-apc的步骤:

PHP APC提供两种缓存功能,即缓存Opcode(目标文件),我们称之为apc_compiler_cache。同时它还提供一些接口用于PHP开发人员将用户数据驻留在内存中,我们称之为apc_user_cache。我们这里主要讨论php-apc的配置。

/usr/local/php5/bin/phpize exportPHP_PREFIX= /usr/local/php5/ ./configure--enable-apc--enable-apc-mmap--with-apxs=/usr/local/httpd-2.2.14/bin/apxs--with-php-config=$PHP_PREFIX/bin/php-config

php.ini添加如下语句

extension_dir= /usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626 extension=apc.so [APC] apc.enabled=1apc.shm_segments=1apc.shm_size=64Mapc.optimization=1apc.num_files_hint=0apc.ttl=7200apc.user_ttl=7200apc.gc_ttl=3600apc.cache_by_default=on

【注意*】

php5.3.3默认没有把php.ini文件里面的short_open_tag = Off设置为short_open_tag = On

所以我们需要把short_open_tag = Off设置为On;否则的话,访问php测试页面和php页面不显示的问题。(安装php-apc后,网站就无法显示,无法读取php变成空白页面)

最后测试,可以访问apc.php测试效果。(欲了解更多APC优化知识,可以参看http://www.perfgeeks.com/?p=298)

由于水平有限 O( _ )O~ ,写的不详细地方的请多指教。

无论如何,没有人有办法把自己抑或他人的刺拔掉。那是一碰便痛的软肋,

Apache+Fastcgi模块+APC经典配置推荐

相关文章:

你感兴趣的文章:

标签云: