Home > Backend Development > PHP Tutorial > Tutorial on installing nginx + php + memcached_PHP under ubuntu

Tutorial on installing nginx + php + memcached_PHP under ubuntu

WBOY
Release: 2016-07-13 10:29:52
Original
796 people have browsed it

1, install nginx

sudo apt-get install nginx
Copy after login

All configuration files are under /etc/nginx, and the virtual host configuration is under /etc/nginx/sites-available

The program file is in /usr/sbin/nginx

The log is placed in /var/log/nginx

And the startup script nginx has been created under /etc/init.d/

The default virtual host directory is set to /var/www/nginx-default

Start nginx

sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx reload
Copy after login

2, install php

sudo apt-get install php5-cli php5-cgi php5-mysql
Copy after login

3. Install FastCgi

<span> apt-get install php5-cgi</span>
Copy after login

You can also install spawn-fcgi. spawn-fcgi is a fastcgi management program and is an independent project from Lighthttpd. In actual operations, you can use php-fpm (php's fastcgi php manager). php-fpm comes with php 5.3.3, but my current version is php 5.3.2.

Use spawn-fcgi to execute

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
Copy after login
Copy after login

Parameter meaning:

* -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等
Copy after login

Restart fcgi

php-cgi: kill the process first

sudo killall -HUP php5-cgi
Copy after login

Restart fcgi

4, configure nginx to support php

Modify nginx configuration file: /etc/nginx/sites-available/default Modify host name:

server_name localhost;
Copy after login

The line that modifies index is changed to:

index index.php index.html index.htm;
Copy after login

Remove the comments below to support php scripts:

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;
}
Copy after login

Restart nginx:

/etc/init.d/nginx stop
/etc/init.d/nginx start
Copy after login

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
Copy after login
Copy after login

6. Install memcached server

sudo apt-get install memcached
Copy after login

Start the memcached service

memcached -d -m 128 -p 11111 -u root
Copy after login

Parameter description:

-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 显示帮助
Copy after login

Check whether the service is started

ps aux | grep memcached
Copy after login

 

7, install memcached php extension

sudo apt-get install php5-memcached
Copy after login

After the installation is completed, nginx and fcgi need to be restarted to make memcached take effect.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/769341.htmlTechArticle1, install nginx sudo apt-get install nginx All configuration files are under /etc/nginx, virtual host The program files configured under /etc/nginx/sites-available are in /usr/sbin/nginx. The logs are placed...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template