もう半年位悩んでいましたWordPressが物凄く遅い件に関して
今回解決する方法を試してみました。
PHPアクセラレータを導入して高速化を図る。
と言う方法です。
PHPアクセラレータと言っても
何種類かあるようなのでその中のAPCと言うものを利用しPHPの処理を最適化します。
コマンドphpizeを実行して以下の様に表示されれば恐らく
php5-develが入っています。
[root@localhost root]# phpize Cannot find config.m4. Make sure that you run '/usr/bin/phpize' in the top level source directory of the module
こんな風に表示されていない場合はphp5-develが入っていない可能性があります。
インストールしましょう。
#apt-get install php5-devel
APC
ここからダウンロードするAPCのURLを確認します。
今回はAPC-3.0.19.tgzを使用しました。
コマンドwgetでファイルを/rootへダウンロードします。
[root@localhost root]# wget http://pecl.php.net/get/APC-3.0.19.tgz --14:15:28-- http://pecl.php.net/get/APC-3.0.19.tgz => `APC-3.0.19.tgz' pecl.php.net をDNSに問いあわせています... 216.92.131.66 pecl.php.net|216.92.131.66|:80 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... 200 OK 長さ: 115,735 (113K) [application/octet-stream] 100%[========================================>] 115,735 80.27K/s 14:15:30 (80.04 KB/s) - `APC-3.0.19.tgz' を保存しました [115735/115735]
/rootにダウンロードされた事を確認し解凍します。
[root@localhost root]# ls APC-3.0.19.tgz bkup.sh~* rootkit.sh* Desktop/ domain.sh~* rootkit.sh~* Maildir/ ftp.sh* rpm/ OCN/ install.log upgrade-log Xrootenv.0 install.log.syslog user.txt* anaconda-ks.cfg mod_layout-50-vine-by_orbit.tar.gz webalizer.sh* backup.sh* mysql.sql* webalizer.sh~* backup.sh~* mysql_bkup.sh* bkup.sh* postfix-2.2.10-10vl4.src.rpm [root@localhost root]# tar xzvf APC-3.0.19.tgz package.xml APC-3.0.19/tests/apc_001.phpt APC-3.0.19/tests/apc_002.phpt APC-3.0.19/tests/apc_003.phpt APC-3.0.19/tests/skipif.inc APC-3.0.19/arch/i386/atomic.h APC-3.0.19/arch/x86_64/atomic.h APC-3.0.19/arch/atomic.h APC-3.0.19/CHANGELOG APC-3.0.19/INSTALL APC-3.0.19/LICENSE APC-3.0.19/NOTICE APC-3.0.19/TODO APC-3.0.19/TECHNOTES.txt APC-3.0.19/apc.c APC-3.0.19/apc.dsp APC-3.0.19/apc.h APC-3.0.19/apc_cache.c APC-3.0.19/apc_cache.h APC-3.0.19/apc_compile.c APC-3.0.19/apc_compile.h APC-3.0.19/apc_debug.c APC-3.0.19/apc_debug.h APC-3.0.19/apc_fcntl.c APC-3.0.19/apc_fcntl.h APC-3.0.19/apc_futex.c APC-3.0.19/apc_futex.h APC-3.0.19/apc_globals.h APC-3.0.19/apc_lock.h APC-3.0.19/apc_main.c APC-3.0.19/apc_main.h APC-3.0.19/apc_mmap.c APC-3.0.19/apc_php.h APC-3.0.19/apc_pthreadmutex.c APC-3.0.19/apc_pthreadmutex.h APC-3.0.19/apc_sem.c APC-3.0.19/apc_sem.h APC-3.0.19/apc_shm.c APC-3.0.19/apc_shm.h APC-3.0.19/apc_sma.c APC-3.0.19/apc_sma.h APC-3.0.19/apc_pool.c APC-3.0.19/apc_pool.h APC-3.0.19/apc_spin.c APC-3.0.19/apc_spin.h APC-3.0.19/apc_stack.c APC-3.0.19/apc_stack.h APC-3.0.19/apc_zend.c APC-3.0.19/apc_zend.h APC-3.0.19/apc_signal.c APC-3.0.19/apc_signal.h APC-3.0.19/config.m4 APC-3.0.19/php_apc.c APC-3.0.19/php_apc.h APC-3.0.19/pgsql_s_lock.c APC-3.0.19/pgsql_s_lock.h APC-3.0.19/apc_fcntl_win32.c APC-3.0.19/apc_rfc1867.c APC-3.0.19/apc.php
解凍したAPCのディレクトリに移動し
コマンドphpizeを実行し
コンパイルしてインストールします。
[root@localhost root]# cd APC-3.0.19 [root@localhost APC-3.0.19]# phpize Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519 [root@localhost APC-3.0.19]# ./configure --enable-apc checking for egrep... grep -E checking for a sed that does not truncate output... /bin/sed checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ANSI C... none needed checking how to run the C preprocessor... gcc -E checking for icc... no checking whether gcc and cc understand -c and -o together... yes checking for system library directory... lib checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking target system type... i686-pc-linux-gnu checking for PHP prefix... /usr (長いので省略) (pthread_mutexattr_setpshared), your system may not support shared mutex's. configure: WARNING: It doesn't appear that pthread mutex's are supported on your system checking Checking whether we should use spin locks... no checking for sigaction... yes checking for union semun... no checking whether we should enable valgrind support... no checking for shm_open in -lrt... yes checking for ld used by gcc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for /usr/bin/ld option to reload object files... -r checking for BSD-compatible nm... /usr/bin/nm -B checking whether ln -s works... yes checking how to recognise dependent libraries... pass_all checking dlfcn.h usability... yes checking dlfcn.h presence... yes checking for dlfcn.h... yes checking for g77... no checking for f77... no checking for xlf... no checking for frt... no checking for pgf77... no checking for fort77... no checking for fl32... no checking for af77... no checking for f90... no checking for xlf90... no checking for pgf90... no checking for epcf90... no checking for f95... no checking for fort... no checking for xlf95... no checking for ifc... no checking for efc... no checking for pgf95... no checking for lf95... no checking for gfortran... no checking whether we are using the GNU Fortran 77 compiler... no checking whether accepts -g... no checking the maximum length of command line arguments... 32768 checking command to parse /usr/bin/nm -B output from gcc object... ok checking for objdir... .libs checking for ar... ar checking for ranlib... ranlib checking for strip... strip checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -fPIC checking if gcc PIC flag -fPIC works... yes checking if gcc static flag -static works... yes checking if gcc supports -c -o file.o... yes checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... no configure: creating libtool appending configuration tag "CXX" to libtool appending configuration tag "F77" to libtool configure: creating ./config.status config.status: creating config.h [root@localhost APC-3.0.19]# make (長いので省略) cp ./.libs/apc.so /root/APC-3.0.19/modules/apc.so cp ./.libs/apc.lai /root/APC-3.0.19/modules/apc.la PATH="$PATH:/sbin" ldconfig -n /root/APC-3.0.19/modules ---------------------------------------------------------------------- Libraries have been installed in: /root/APC-3.0.19/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'. [root@localhost APC-3.0.19]# make install Installing shared extensions: /usr/lib/php5/
/usr/lib/php5/内にapc.soが作成されている事を確認。
[root@localhost APC-3.0.19]# ls /usr/lib/php5/ apc.so* build/ mysql.so* pdo.so* pdo_sqlite.so* bin/ mcrypt.so* mysqli.so* pdo_mysql.so*
/rootへ戻りphp.iniを編集します。
[root@localhost root]# vi /etc/php5/php.ini 下記を最下部に追記 extension=apc.so
Apache2を再起動
[root@localhost root]# /etc/rc.d/init.d/apache2 restart httpdを停止中: [ OK ] httpdを起動中: [ OK ] [root@localhost root]#
これでPHPで書かれたプログラム(WordPress等)を高速処理できます。
0 Comments.