CentOSでphpでmemcache。
memcached
yum -y install memcached chkconfig memcached on service memcached start
php-pecl-memcache
yum -y install php-pecl-memcache
コード。
<?php $memcache = new Memcache; $memcache->connect('localhost', 11211) or die("接続できませんでした。"); echo("接続しました。"); $memcache->close(); ?>
これだけだと繋がらなかった。
phpのエラーログを出してみる。
vi /etc/php.ini
以下を追記。
error_log=php_errors.logこんなログが出てた。
[04-May-2012 03:12:48] PHP Notice: Memcache::connect(): Server localhost (tcp 11211, udp 0) failed with: Permission denied (13) in /var/www/html/memcache_test.php on line 4Permission deniedだとう…。
[04-May-2012 03:12:48] PHP Warning: Memcache::connect(): Can't connect to localhost:11211, Permission denied (13) in /var/www/html/memcache_test.php on line 4
SELinuxの設定
ググったところ、SELinuxの設定じゃね?ていう海外サイトの記事を見つけたので、
早速見てみる。
getsebool -a | grep mem allow_execmem --> on allow_nsplugin_execmem --> on allow_xserver_execmem --> off httpd_can_network_memcache --> off httpd_execmem --> off
httpd_can_network_memcache コレかーー!!
setsebool -P httpd_can_network_memcache true
解決。