ubuntu安装 LNMP+redis
一、更新软件源
1、修改软件源为163的源
sudo vim /etc/apt/sources.list
替换源为163的源:
deb http://mirrors.163.com/ubuntu/ intrepid main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ intrepid-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ intrepid-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ intrepid-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ intrepid-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ intrepid main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ intrepid-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ intrepid-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ intrepid-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ intrepid-backports main restricted universe multiverse
2、更新
sudo apt-get update
二、安装nginx
1、安装
sudo apt-get install nginx
2、启动
sudo /etc/init.d/nginx start
三、安装mysql
1、安装
sudo apt-get install mysql-server
2、修改mysql权限
mysql -u root -p12345 grant all on *.* to root@'%' identified by '12345'; flush privileges;
3、修改配置文件
sudo vim /etc/mysql/my.cnf
如果是mysql5.6 则为:
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
将bind-address = 127.0.0.1前面加上#注释掉,这样就可以远程连接数据库了。
通过命令 netstat -an|grep 3306 查看3306端口绑定情况
四、安装php
sudo apt-get install php5-cli php5-cgi php5-mysql php5-fpm php5-curl php-gettext php5-gd php5-mcrypt php5-dev php-pear libpcre3-dev libssh2-php php5-xdebug
五、配置nginx vhost
1、修改配置文件
修改配置文件 sudo vi /etc/nginx/sites-enabled/default 把里面server的listen 80和location ~\.php${的注释打开,并设置里面的内容为: fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/redis$fastcgi_script_name; include /etc/nginx/fastcgi_params; root /usr/share/nginx/html/redis;
2、重启服务
sudo service php5-fpm restart 或者 sudo /etc/init.d/php5-fpm restart sudo service nginx restart 或者 sudo /etc/init.d/nginx restart
3、测试访问
此时在win7宿主机下配置hosts IP www.redis.cc,在浏览器下访问 http://www.redis.cc/info.php
六、安装redis和phpredis扩展
1、安装redis
sudo apt-get install -y redis-server
2、安装phpredis扩展
sudo apt-get install php5-redis
3、测试
开启redis-server服务
sudo /etc/init.d/redis-server start
打开redis-cli
127.0.0.1:6379> set name yhp OK 127.0.0.1:6379> get name "yhp"
编写php验证扩展
<?php $redis = new redis(); $redis->connect('127.0.0.1', 6379); $redis->set('key', 'yhp'); echo $redis->get('key'); ?>
注意事项:
1、访问PHP文件,提示502
编辑 /etc/php5/fpm/pool.d/www.conf 将 listen = /var/run/php5-fpm.sock 修改为:listen = 127.0.0.1:9000