Home  >  Article  >  php教程  >  ubuntu下安装 nginx + php + memcached

ubuntu下安装 nginx + php + memcached

WBOY
WBOYOriginal
2016-06-13 09:35:161829browse

1,安装nginx

sudo apt-get install nginx

所有的配置文件都在/etc/nginx下,虚拟主机配置在/etc/nginx/sites-available下 

程序文件在/usr/sbin/nginx 

日志放在了/var/log/nginx中 

并已经在/etc/init.d/下创建了启动脚本nginx 

默认的虚拟主机的目录设置在了/var/www/nginx-default

  启动nginx

sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx reload

 

2,安装php

sudo apt-get install php5-cli php5-cgi php5-mysql

3,安装FastCgi

<span> apt-get install php5-cgi</span>

也可以再安装spawn-fcgi,spawn-fcgi是fastcgi的管理程序,从Lighthttpd独立出来的项目。实际运营中可以使用php-fpm(php的fastcgi php manager). php 5.3.3中自带php-fpm,但我现在的版本是php 5.3.2.

采用spawn-fcgi执行

sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid

参数意义:

* -f 指定调用FastCGI的进程的执行程序位置,根据系统上所装的PHP的情况具体设置 
* -a 绑定到地址addr 
* -p 绑定到端口port 
* -s 绑定到unix socket的路径path 
* -C 指定产生的FastCGI的进程数,默认为5(仅用于PHP) 
* -P 指定产生的进程的PID文件路径 
* -u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,Ubuntu下可以使用www-data,其他的根据情况配置,如nobody、apache等

重启fcgi

php-cgi: 先杀死进程

sudo killall -HUP php5-cgi

再启动fcgi

4,配置nginx支持php

修改nginx的配置文件:/etc/nginx/sites-available/default 修改主机名:

server_name localhost;

修改index的一行修改为:

index index.php index.html index.htm;

去掉下面部分的注释用于支持 php 脚本:

location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
}

重新启动nginx:

/etc/init.d/nginx stop
/etc/init.d/nginx start

启动fastcgi php:

sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid

6,安装memcached服务端

sudo apt-get install memcached

  启动memcached服务

memcached -d -m 128 -p 11111 -u root

  参数说明:

-p 监听的端口
-l 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25-n 最小分配空间,key+value+flags默认是48
-h 显示帮助

  查看服务是否启动

ps aux | grep memcached

  

7,安装memcached php扩展

sudo apt-get install php5-memcached

 安装完成后,需要重启nginx和fcgi,才能使memcached生效。

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn