最新消息:

龙芯社区版的Debian系统安装Nginx+PHP+Mysql

未分类 admin 3509浏览 0评论

一、安装套件
执行以下命令,安装所需的补充软件包:

sudo apt-get intsall nginx
sudo apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-sqlite php5-xsl
sudo apt-get install spawn-fcgi

※ 以上安装PHP的包是辅助的,可选。
Nginx版本:

引用
$ sudo nginx -v
nginx version: nginx/0.7.67

二、修改配置文件
1、相关文件
该版本Nginx的相关文件是:

引用
● 所有的配置文件都在/etc/nginx下,独立的配置文件存放在/etc/nginx/sites-available目录下
● 程序文件在/usr/sbin/nginx
● 日志文件/var/log/nginx中
● 服务脚本/etc/init.d/nginx
● 默认的虚拟主机的目录设置在了/var/www/

此外,打包的Nginx已经把大部分的常用选项存放在/etc/nginx/sites-available/default文件中,我们要修改的也是该文件。

2、修改配置
修改/etc/nginx/sites-available/default,把以下配置打开或取消注释:

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

※ 注意:上述配置必须与安装的Nginx 相关文件一致。

三、启动服务
启动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

启动Nginx:

sudo /etc/init.d/nginx start

查看端口:

引用
$ netstat -ln|more
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp6       0      0 :::80                   :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN

※ 80端口是Nginx的,9000端口是spawn-fcgi 负责的。若之前启动了Apache,请先关闭。

四、测试
访问phpinfo页面:

ab压力测试:

引用
# ab -c 100 -n 1000 http://127.0.0.1/phpinfo.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software:        nginx/0.7.67
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /phpinfo.php
Document Length:        73259 bytes

Concurrency Level:      100
Time taken for tests:   29.305 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      73417000 bytes
HTML transferred:       73259000 bytes
Requests per second:    34.12 [#/sec] (mean)
Time per request:       2930.469 [ms] (mean)
Time per request:       29.305 [ms] (mean, across all concurrent requests)
Transfer rate:          2446.58 [Kbytes/sec] received

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0    3   8.5      0      33
Processing:   165 2792 491.1   2928    3038
Waiting:       74 2696 490.9   2832    2948
Total:        189 2795 484.0   2928    3038

Percentage of the requests served within a certain time (ms)
50%   2928
66%   2934
75%   2939
80%   2941
90%   2951
95%   2965
98%   3010
99%   3028
100%   3038 (longest request)

响应时间一般,似乎比Apache好些。(加载的模块比之前测试的要多)

转载请注明:爱开源 » 龙芯社区版的Debian系统安装Nginx+PHP+Mysql

您必须 登录 才能发表评论!