1, install nginx
sudo apt-get install nginx
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
2, install php
sudo apt-get install php5-cli php5-cgi php5-mysql
3. Install FastCgi
<span> apt-get install php5-cgi</span>
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
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等
Restart fcgi
php-cgi: kill the process first
sudo killall -HUP php5-cgi
Restart fcgi
4, configure nginx to support php
Modify nginx configuration file: /etc/nginx/sites-available/default Modify host name:
server_name localhost;
The line that modifies index is changed to:
index index.php index.html index.htm;
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; }
Restart nginx:
/etc/init.d/nginx stop /etc/init.d/nginx start
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. Install memcached server
sudo apt-get install memcached
Start the memcached service
memcached -d -m 128 -p 11111 -u root
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 显示帮助
Check whether the service is started
ps aux | grep memcached
7, install memcached php extension
sudo apt-get install php5-memcached
After the installation is completed, nginx and fcgi need to be restarted to make memcached take effect.