centos下nginx+postgresql+php+memcached+apc安装与配置
具体安装步骤如下:
具体安装软件包:
www.zhishiwu.com
01
nginx1.0.13
02
03
wget http://nginx.org/download/nginx-1.0.13.tar.gz
04
05
postgresql9.1.2
06
07
wget http://ftp.postgresql.org/pub/source/v9.1.2/postgresql-9.1.2.tar.gz
08
09
php5.3.10
10
11
wget http://cn2.php.net/get/php-5.3.10.tar.gz/from/ar.php.net/mirror
12
13
memcache 1.4.13
14
15
wget http://code.google.com/p/memcached/downloads/detail?name=memcached-1.4.13.tar.gz&can=2&q=
16
17
memcached php插件 memcache1.5
18
19
wget http://pecl.php.net/get/memcache-1.5.tgz
20
21
apc php插件 apc3.1.9
22
23
wget http://pecl.php.net/get/APC-3.1.9.tgz
1.升级系统包
yum update
关闭selinux
2.nginx安装:
安装pcre
yum install pcre*
解压编译:
1
tar –zxvf nginx-1.0.13.tar.gz
2
3
cd nginx-1.0.13
4
5
./configure --prefix=/usr/local/nginx --with-http_flv_module --with-http_stub_status_module --with-pcre
6 www.zhishiwu.com
7
make && make install
01
yum install jpeg*
02
03
yum install libjpeg*
04
05
yum install libpng*
06
07
yum install iconv*
08
09
yum install libiconv*
10
11
yum install freetype*
12
13
yum install gd*
更改配置文件:
vi /usr/local/nginx/conf/nginx.conf
去掉下面一段的注释:
www.zhishiwu.com
01
location ~ /.php$ {
02
03
root html;
04
05
fastcgi_pass 127.0.0.1:9000;
06
07
fastcgi_index index.php;
08
09
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
10
11
include fastcgi_params;
12
13
}
45行添加index.php
做好这两个操作后启动nginx /usr/local/nginx/sbin/nginx
3.postgresql安装
安装readline
yum install readline*
解压编译:
1
tar –zxvf postgresql-9.1.2.tar.gz
2
3
cd postgresql-9.1.2
4
5
./configure --prefix=/usr/local/postgresql
6
www.zhishiwu.com
7
make && make install
postgresql配置:
01
useradd postgre
02
03
mkdir /home/postgre/data
04
05
chown -R postgre:postgre/usr/local/postgresql/
06
07
chown -R postgre:postgre /home/postgre
08
09
su postgre
10
/usr/local/postgresql/bin/initdb --encoding=utf8 -D /home/postgre/data
4.php安装
安装所需软件包
www.zhishiwu.com
01
yum install jpeg*
02
03
yum install libjpeg*
04
05
yum install libpng*
06
07
yum install iconv*
08
09
yum install libiconv*
10
11
yum install freetype*
12
13
yum install gd*
解压编译
01
tar -zxvf php-5.3.10.tar.gz
02
03
cd php-5.3.10
04
05
./configure --prefix=/usr/local/php--with-pgsql=/usr/local/postgresql --with-
06
07
gd=/usr --with-jpeg-dir=/usr--with-png-dir=/usr --with-zlib --enable-mb
08
09
string --with-freetype-dir --with-iconv--enable-fpm
10
11
make && make install
复制php.ini
www.zhishiwu.com
1
cp php.ini-production /usr/local/php/lib/php.ini
2
3
cd /usr/local/php/etc/
4
5
mv php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
这个配置一般默认就可以启动
启动php-fpm
/usr/local/php/sbin/php-fpm
5.memcached安装
安装所需要的软件包:
yum install libevent*
解压编译:
1
tar -zxvf memcached-1.4.13.tar.gz
2
3
cd memcached-1.4.13
4
5
./configure --prefix=/usr/local/memcached
6
7
make && make install
6.memcachedphp插件安装
安装所需要的软件包
yum install autoconf
解压编译
www.zhishiwu.com
1
tar -zxvf memcache-1.5.tgz
2
3
cd memcache-1.5
4
5
/usr/local/php/bin/phpize
6
7
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
配置memcached与php.ini
/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
vim /usr/local/php/lib/php.ini
查找extension_dir
更改路径为/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
添加
extension=memcache.so
启动memcached:
/usr/local/memcached/bin/memcached -d m 20-u root -l localhost -p 11211
www.zhishiwu.com
启动说明:
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,
-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid
7.apc插件的安装
解压编译安装
1
tar -zxvf APC-3.1.9.tgz
2
3
cd APC-3.1.9
4
5
/usr/local/php/bin/phpize
6
7
./configure --enable-apc --enable-apc-mmap--with-php-config=/usr/local/php/bin/php-config
8
9
make && make install
配置php.ini
www.zhishiwu.com
ls/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
vim /usr/local/php/lib/php.ini
在extension=memcache.so下面添加extension=apc.so以及
apc.enabled = 1
apc.cache_by_default = on
apc.shm_segments = 1
apc.shm_size = 32
apc.ttl = 600
apc.user_ttl = 600
apc.num_files_hint = 0
apc.write_lock = On
检测是否安装成功
/usr/local/php/bin/php -m |grep apc
装完后 reboot
用phpinfo查看是否都已经加载
8.开机自动启动
www.zhishiwu.com
1
<b>echo"/usr/local/nginx/sbin/nginx" >>/etc/rc.local
2
3
echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local
4
5
echo"/usr/local/memcached/bin/memcached -d m 20 -u root -l localhost -p11211" >>/etc/rc.local</b>
9.防火墙设置
vim /etc/sysconfig/iptables
开启11211和80端口
10.测试脚本
www.zhishiwu.com
Phpinfo
1
<?php
2
3
phpinfo();
4
5
?>
memacache
01
<?php
02
03
$mem = new Memcache;
04
05
$mem->connect("192.168.10.99",11211);
06
07
$mem->set('key', 'This is a test!', 0,60);
08
09
$val = $mem->get('key');
10
11
echo $val;
12
13
?>