freebsd ports安装 nginx+php+mysql+fastcgi配置记录

第一次安装,借鉴了网上很多安装教程,现在把自己的安装步骤记录下来以供日后分析使用:
开始准备工作,freebsd系统有ports包,所有使用程序都将通过此包安装:
第一步我是先安装mysql 数据库:
#cd /usr/ports/database/mysql51-server
#make install clean
然后等待自动编译安装过程
安装完成,配置并启动mysql:
#cd /usr/local/bin
#mysql_install_db  –user=mysql
#mysql_saft &   // 启动mysql
#mysqladmin -uroot password ‘密码’      //设置mysql密码
把mysql加入开机自启动
一般有两种方法,
#ee /etc/rc.conf
加上一行: mysql_enable=”YES”
不过我喜欢直接添加mysql-server.sh脚本到 /usr/local/etc/rc.d/
#cp  /usr/local/chare/mysql/mysql.server /usr/local/etc/rc.d/mysql-server.sh
OK, reboot 系统看看, mysql安装成功

第二布安装php:
#cd /usr/ports/lang/php5
#make config  配置安装文件选上  fastcgi
#make install clean
又是漫长的自编译安装过程。
完成切换:
#cd /usr/local/etc
#cp php.ini-dist php.ini    //复制php.ini配置文件
然后安装php5-extensions
#cd /usr/ports/lang/php5-extensions
#make config     //选中mysql的驱动
#make install clean
编译安装完成,然后再安装 ZendOptimizer
#cd /usr/ports/devel/ ZendOptimizer
#make install clean
编译安装完成,到此php算是安装完成
第三布 开始安装 nginx
#whereis nginx
nginx: /usr/ports/www/nginx
#cd /usr/ports/www/nginx
#make install clean
编译安装到完成
然后获得 spawn-fcgi 的支持
要得到spawn-fcgi就要安装lighttpd
#whereis lighttpd
#cd /usr/ports/www/lighttpd
#make install clean
安装到现在正式完成。
接下来配置nginx.conf
#ee /usr/local/etc/nginx/nginx.conf //配置

 

找到如下内容
#user nobody;
改成
user www; #去掉前面#号
—————-
找到如下内容
location / {
root   /usr/local/www/nginx;
index index.html index.htm;
}

改成
location / {
root   /usr/local/www/nginx; #这里是站点根目录,根据需要修改
index index.php index.html index.htm; #添加index.php
}
找到如下内容
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index index.php;
#    fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

改成
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root           html; #这行删掉似乎也没影响,查到的资料上有的有有的没有
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;
}
保存并退出
——————————————————————————————-
然后是启动测试:
#cd /usr/lcoal/bin
#spawn-fcgi -a 127.0.0.1 -p 9000 -u www -g www -C 3 -f /usr/local/bin/php-cgi
#nginx  //启动nginx
浏览http://localhost                            ok,成功!
然后在web目录编辑info.php测试环境:
#cd /usr/local/www/nginx
#touch info.php
#ee info.php
<?php
phpinfo();
?>
保存并退出,打开浏览器测试,出现系统环境参数,
大功告成!
主要如果网页打开出现404错误 ,返回检查nginx.conf配置 ,特别是蓝色字体部分,检查文件根路径配置是否正确。
安装 phpMyAdmin
——————————————————————————————————————–
添加系统自启动
#ee /etc/rc.conf
添加  nginx_enable=”YES”
保存退出!
添加spawn-fcgi启动:这里引用网上以为老大写的脚本
下载 http://bash.cyberciti.biz/dl/251.sh.zip解压得到 251.sh 改名为 fastcgi.sh
#cp fastcgi.sh /usr/local/etc/rc.d/fastcgi.sh
#chmod 755 /usr/lcoal/etc/rc.d/fastcgi.sh  //不添加权限脚本启动不了
OK! 这回是真正的大功告成,彻底完毕, reboot freebsd  , look look………
以上就是我个人初次安装的经验实录。
一下附上 fastcgi.sh脚本代码:

 

#!/bin/sh
# Shell Script to start / stop PHP FastCGI using lighttpd – spawn-fcgi binary file.
# ————————————————————————-
# Copyright (c) 2006 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# ————————————————————————-
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ————————————————————————-
PROVIDES=php-cgi
LIGHTTPD_FCGI=/usr/local/bin/spawn-fcgi
SERVER_IP=127.0.0.1
SERVER_PORT=9000
SERVER_USER=www
SERVER_GROUP=www
PHP_CGI=/usr/local/bin/php-cgi
PGREP=/bin/pgrep
KILLALL=/usr/bin/killall
### No editing below ####
cmd=$1
pcgi_start(){
echo “Starting $PROVIDES…”
$LIGHTTPD_FCGI -a $SERVER_IP -p $SERVER_PORT -u $SERVER_USER -g $SERVER_GROUP -f $PHP_CGI
}
pcgi_stop(){
echo “Killing $PROVIDES…”
$KILLALL $PROVIDES
}
pcgi_restart(){
pcgi_stop
pcgi_start
}
pcgi_status(){
$PGREP $PROVIDES > /dev/null
[ $? -eq 0  ] && echo “$PROVIDES running” || echo “$PROVIDES NOT running”
}
pcgi_help(){
echo “Usage: $0 {start|stop|restart|status}”
}
case ${cmd} in
[Ss][Tt][Aa][Rr][Tt]) pcgi_start;;
[Ss][Tt][Oo][Pp]) pcgi_stop;;
[Rr][Ee][Ss][Tt][Aa][Rr][Tt]) pcgi_restart;;
[Ss][Tt][Aa][Tt][Uu][Ss]) pcgi_status 0;;
*)      pcgi_help ;;
esac

猜你喜欢

转载自dn365.iteye.com/blog/747216