UBUNTU下NGINX,PHP-FPM,MYSQL,REDIS安装指导

Ubuntu (11.10) 下Nginx, PHP FPM, MySQL, Redis安装指导

1, 通过apt-get快速安装nginx, mysql server, php5-fpm, php-mysql, php-apc

sudo apt-get install nginx mysql-server php5-mysql php5-fpm php-apc

创建nginx访问根目录,比如 /home/alex/data/www

cd ~
mkdir -p data/www/
sudo vi /etc/nginx/sites-avaible/default

; 加入以下配置
 20 server {
 21     listen 80;
 22     server_name localhost;
 23     root /home/alex/data/www;
 24     location / {
 25         index   index.html index.php;
 26     }
 27     location ~ \.php$ {
 28         fastcgi_pass    127.0.0.1:9000;
 29         fastcgi_param   SCRIPT_NAME $document_root$fastcgi_script_name;
 30         include         fastcgi_params;
 31     }
 32 }

2, 取消Nginx, PHP FPM, MySQL开机启动

sudo update-rc.d -f nginx remove
sudo update-rc.d -f php5-fpm remove
sudo vi /etc/init/mysql.conf
; 注掉/etc/init/mysql.conf文件的以下三行
#start on (net-device-up
#          and local-filesystems
#     and runlevel [2345])

3, 安装redis

cd /tmp
wget http://redis.googlecode.com/files/redis-2.4.8.tar.gz
tar -zxf redis-2.4.8.tar.gz
cd redis-2.4.8
make
sudo make install
; redis将默认安装到/usr/local/bin下面
wget https://github.com/ijonas/dotfiles/raw/master/etc/init.d/redis-server
wget https://github.com/ijonas/dotfiles/raw/master/etc/redis.conf
sudo mv redis-server /etc/init.d/redis-server
sudo chmod +x /etc/init.d/redis-server
sudo mv redis.conf /etc/redis.conf
sudo vi /etc/redis.conf
; 把/etc/redis.conf文件的 daemonize no 改成 daemonize yes

4, 安装phpredis extension
先下载phpredis源码 https://github.com/nicolasff/phpredis/zipball/master
解压zip包,并移动到/tmp下

cd /tmp/nicolasff-phpredis-c18dcca
phpize
./configure
sudo make && make install
; redis.so文件被自动放到PHP的extension目录,我的是:/usr/lib/php5/20090626/
sudo vi /etc/php5/fpm/conf.d/redis.ini
; 在redis.ini里面加入 extension=redis.so,以启用redis extension

使用redis保存session数据

sudo vi /etc/php5/fpm/php.ini
; 修改php.ini的以下配置项
; session.save_handler = redis
; session.save_path = "tcp://127.0.0.1:6379?timeout=2"

5, 启动服务

sudo /etc/init.d/redis-server start
sudo /etc/init.d/php5-fpm start
sudo /etc/init.d/mysql start
sudo /etc/init.d/nginx start

6, 下载phpmyadmin和phpredisadmin,并放到/home/alex/data/www,通过chrome/firefox打开已验证以上服务正常启动

7, 通过两个简单的php脚本验证redis保存session数据正常工作

你可能感兴趣的:(mysql,nginx,server,php5-fpm,php-mysql,php-apc)