FreeBSD下nginx+fast-cgi+mysql+zend的实现

首先在安装所有软件之前新系统ports,然后 再进行下面的工作

1)安装mysql
#cd /usr/ports/databases/mysql51-server

#make WITH_CHARSET=utf8 WITH_XCHARSET=all  WITH_PROC_SCOPE_PTH=yes SKIP_DNS_CHECK=yes BUILD_OPTIMIZED=yes install clean //(utf8我选择了这个,情况自己定)
#cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf
#rehash
# mysql_install_db --user=mysql ##初始化mysql
#/usr/local/bin/mysqld_safe & ##启动mysql
#/usr/local/bin/mysqladmin -u root password ‘****’ ##修改root密码,newpass是你需要改的密码

2)安装php
# cd /usr/ports/lang/php52
# make config
[X] CLI        Build CLI version
[X] CGI        Build CGI version
[ ] APACHE     Build Apache module   //不安装这个
[ ] DEBUG      Enable debug
[X]] SUHOSIN Enable Suhosin protection system
[X] MULTIBYTE Enable zend multibyte support
[ ] IPV6       Enable ipv6 support
[ ] REDIRECT   Enable force-cgi-redirect support (CGI only)
[ ] DISCARD    Enable discard-path support (CGI only)
[X] FASTCGI    Enable fastcgi support (CGI only)
[X] PATHINFO   Enable path-info-check support (CGI only)
# make install clean
#cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini

3)安装php52-extensions
# cd /usr/ports/lang/php52-extensions/
# make config
Options for php52-extensions 1.0
————————————————-
[X] FTP        FTP support
[X] GD
[X] GETTEXT
[X] MBSTRING
[X] MYSQL
[ ] POSIX //去掉.
[ ] SQLITE //去掉.
[X] ZLIB

# make install clean

#rehash

5)安装nginx
#cd /usr/ports/www/nginx/
#make install clean
#rehash

/usr/ports/www/spawn-fcgi
make install clean
6)安装lighttpd
#cd /usr/ports/www/lighttpd/
#make install clean
#rehash

nginx+mysql开机后自动运行
#cat>>/etc/rc.conf
mysql_enable=”YES”
nginx_enable=”YES”
#
7)配置nginx
编辑nginx配置文件/usr/local/etc/nginx/nginx.conf
#user   nobody
删除前面的注释#,改成 user   www

location / {
root    /usr/local/www/nginx;
index    index.html index.htm;
}
在index.html前面添加一个index.php
location / {
root    /usr/local/www/nginx;
index    index.php index.html index.htm;
}

#location ~ \.php$ {
#    fastcgi_pass    127.0.0.1:9000;
#           fastcgi_index   index.php;
#           fastcgi_param     SCRIPT_FILENAME     /scripts$fastcgi_script.name;
#    include      fastcgi_params;
#}
将前面的#去掉,修改为
location ~ \.php$ {
fastcgi_pass    127.0.0.1:9000;
fastcgi_index   index.php;
fastcgi_param     SCRIPT_FILENAME     /usr/local/www/nginx$fastcgi_script_name;
include      fastcgi_params;
}

#为了使SCRIPT_FILENAME 有效,更改php.ini里面的cgi.fix_pathinfo=1;

这个地方非常重要,如果红色部分/usr/local/www/nginx不配置的话,如果执行php文件,就会出现No input file specified 错误提示。这个在网上查了半天才找到解决办法。切记切记!!
8)配置spawn-fcgi启动

/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www -f /usr/local/bin/php-cgi
参数说明:
-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等

/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www -f /usr/local/bin/php-cgi
或直接让它设置成开机服务启动:
#vi /etc/rc.local
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www -g www -C 25 -f /usr/local/bin/php-cgi
这样spawn-fcgi就能开机自启动了

9)启动Nginx服务

#nginx

完成了,测试了phpinfo()

解决Attempting to fetch from [url]ftp://ftp.gwdg.de/pub/misc/mysql/Downloads/MySQL-5.1/
etc/rc.conf中添加
vsftpd_enable="YES"

你可能感兴趣的:(FreeBSD下nginx+fast-cgi+mysql+zend的实现)