常见问题常见问题   搜索搜索   会员列表会员列表   团队团队   注册注册    个人资料个人资料   登录查看您的站内信件登录查看您的站内信件   登录登录 

[原创]FreeBSD7.0编译安装nginx+php+mysql.

 
发表新文章   回复文章    FreeBSD China -> 技术交流
阅读上一个主题 :: 阅读下一个主题  
作者 留言
scyzxp
道童


注册时间: 2005-04-12
文章: 317

文章发表于: Thu 2008-05-08 12:37:42    发表主题: [原创]FreeBSD7.0编译安装nginx+php+mysql. 引用并回复

环境
系统:FreeBSD7.0
软件:mysql-5.0.51a,nginx-0.6.30,lighttpd-1.4.19,php-5.2.6
所有软件都安装到/usr/local/vhost,如果需要请自行修改

声明,本文主要涉及内容不是用ports安装,请大家不要骂我。另:本人水平有限,如有错误之处,敬请指教


一、下载源代码
代码:
cd /usr/ports/databases/mysql50-server/
make fetch

cd /usr/ports/www/nginx-devel/
make fetch

cd /usr/ports/lang/php5
make fetch

cd /usr/ports/www/lighttpd
make fetch


二、编译安装
MySQL
代码:
cd /usr/ports/distfiles/
tar -jxf mysql-5.0.51a.tar.gz
cd mysql-5.0.51a
 ./configure --prefix=/usr/local/vhost/mysql --with-charset=utf8 --with-extra-charsets=all --with-big-tables --with-pthread
make &&make install


Nginx
代码:
cd /usr/ports/devel/pcre
make install clean

cd /usr/ports/distfiles/
tar -jxf nginx-0.6.30.tar.gz
cd nginx-0.6.30
./configure --prefix=/usr/local/vhost/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_sub_module
make &&make install


Lighttpd
(安装lighttpd是为了得到启动fastcgi进程)
代码:
cd /usr/ports/distfiles/
tar -jxf lighttpd-1.4.19.tar.bz2
cd lighttpd-1.4.19
./configure --prefix=/usr/local/vhost/lighttpd


Php
代码:
cd /usr/ports/textproc/libxml2
make install clean

cd /usr/ports/ftp/curl
make install clean

cd /usr/ports/graphics/jpeg
make install clean

cd /usr/ports/graphics/png
make install clean

cd /usr/ports/devel/gettext
make install clean

cd /usr/ports/distfiles/
tar -jxf php-5.2.6.tar.bz2
cd php-5.2.6
./configure --prefix=/usr/local/vhost/php --with-mysql=/usr/local/vhost/mysql -enable-fastcgi --enable-sockets --enable-ftp --enable-zip --enable-mbstring --enable-mbregex --enable-calendar --with-curl=/usr/local/clude --with-curlwrappers --disable-debug --enable-inline-optimization --with-zlib --with-gd --with-kerberos --with-gettext --enable-force-cgi-redirect --with-jpeg-dir=/usr/inlocal/clude --with-png-dir=/usr/local/include --with-bz2 --enable-pcntl --with-iconv
make && make install
cp php.ini-dist /usr/local/vhost/php/lib/php.ini

三、配置

MySQL
代码:
cd /usr/local/vhost/mysql
pw adduser mysql -d /dev/null -s /sbin/nologin
bin/mysql_install_db
cp share/mysql/mysql.server ./
chmod +x mysql.server
chown -R mysql ./


启动
代码:
/usr/local/vhost/mysql/mysql.server start


配置nginx
代码:
cd /usr/local/vhost/nginx/
pw adduser webuser -d /dev/null -s /sbin/nologin
cp /usr/local/vhost/lighttpd/bin/spawn-fcgi ./sbin/
rm -rf /usr/local/vhost/lighttpd


vi sbin/php.sh
代码:
#!/bin/sh
/usr/local/vhost/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 8 -u webuser -f /usr/local/vhost/php/bin/php-cgi


代码:
chmod +x sbin/php.sh


启动php for fast-cgi
代码:
sbin/php.sh


vi conf/enable_php
代码:
location ~ \.php$ {
   root           html;
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_index  index.php;
   fastcgi_param  SCRIPT_FILENAME  /usr/local/vhost/nginx/html$fastcgi_script_name;
   fastcgi_param  QUERY_STRING       $query_string;
   fastcgi_param  REQUEST_METHOD     $request_method;
   fastcgi_param  CONTENT_TYPE       $content_type;
   fastcgi_param  CONTENT_LENGTH     $content_length;

   fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
   fastcgi_param  REQUEST_URI        $request_uri;
   fastcgi_param  DOCUMENT_URI       $document_uri;
   fastcgi_param  DOCUMENT_ROOT      $document_root;
   fastcgi_param  SERVER_PROTOCOL    $server_protocol;

   fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
   fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

   fastcgi_param  REMOTE_ADDR        $remote_addr;
   fastcgi_param  REMOTE_PORT        $remote_port;
   fastcgi_param  SERVER_ADDR        $server_addr;
   fastcgi_param  SERVER_PORT        $server_port;
   fastcgi_param  SERVER_NAME        $server_name;

   # PHP only, required if PHP was built with --enable-force-cgi-redirect
   fastcgi_param  REDIRECT_STATUS    200;
}


vi conf/nginx.conf
代码:
user  webuser webuser;
worker_processes  1;

events {
    worker_connections  4096;
    use kqueue;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] $request '
    #                  '"$status" $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    client_header_timeout  3m;
    client_body_timeout    3m;
    send_timeout           3m;
    client_max_body_size  5m;

    client_header_buffer_size    1k;
    large_client_header_buffers  4 4k;

    gzip on;
    gzip_min_length  1100;
    gzip_buffers     4 8k;
    gzip_types       text/plain;

    output_buffers   1 32k;
    postpone_output  1460;

    sendfile         on;
    tcp_nopush       on;
    tcp_nodelay      on;
    send_lowat       12000;

    keepalive_timeout  75 20;


    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.php index.html index.htm;
        }

   if (-d $request_filename){
            rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
        }
   location /nginx_status {
       stub_status on;
          access_log   off;
   }

   include enable_php;
   error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }
}

测试配置文件
代码:
sbin/nginx -t
2008/05/08 11:50:19 [info] 3336#0: the configuration file /usr/local/vhost/nginx/conf/nginx.conf syntax is ok
2008/05/08 11:50:19 [info] 3336#0: the configuration file /usr/local/vhost/nginx/conf/nginx.conf was tested successfully


vi html/phpinfo.php
代码:
<?php
phpinfo();
?>


启动测试
代码:
/usr/local/vhost/nginx/sbin/nginx


在浏览器里输入
代码:
http://192.168.29.128/phpinfo.php


安装配置phpMyadmin
代码:
cd /usr/ports/databases/phpmyadmin/
make fetch

cd /usr/ports/distfiles
tar -jxf phpMyAdmin-2.11.6-all-languages.tar.bz2
mv phpMyAdmin-2.11.6-all-languages /usr/local/vhost/nginx/html/dbadmin


此时MySQL的root没有密码,如果一切正常可以用
http://192.168.29.128/dbadmin/index.php来管理MySQL了

_________________
-------------------------------
开源邮件技术社区
Tmail for FreeBSD技术支持社区
http://www.thismail.org
-------------------------------
返回页首
阅览会员资料 发送站内信件 MSN Messenger
kenbaby
道童


注册时间: 2005-03-19
文章: 300

文章发表于: Thu 2008-05-08 13:57:34    发表主题: 引用并回复

难道你没有修改fixpathinfo?
_________________
是男人就用8.0-CURRENT!
返回页首
阅览会员资料 发送站内信件 浏览发表者的主页
scyzxp
道童


注册时间: 2005-04-12
文章: 317

文章发表于: Thu 2008-05-08 13:58:48    发表主题: 引用并回复

kenbaby 写到:
难道你没有修改fixpathinfo?

找了一下好像说的是php的东东,我的全部是默认的

_________________
-------------------------------
开源邮件技术社区
Tmail for FreeBSD技术支持社区
http://www.thismail.org
-------------------------------
返回页首
阅览会员资料 发送站内信件 MSN Messenger
jonsen
半仙


注册时间: 2007-10-29
文章: 113

文章发表于: Sat 2008-05-10 23:12:23    发表主题: 引用并回复

不明白,为什么还要安装lighttpd?
nginx+php就可以运行的很好了。

_________________
国内第一个免费嵌入式智能DNS系统: http://fedns.isyi.com
免费在线服务器监控: http://monitor.isyi.com
返回页首
阅览会员资料 发送站内信件
lhmwzy
道童


注册时间: 2003-02-14
文章: 235

文章发表于: Sat 2008-05-10 23:53:18    发表主题: 引用并回复

jonsen 写到:
不明白,为什么还要安装lighttpd?
nginx+php就可以运行的很好了。


他是想用spawn-fcgi这个执行程序来展开php-fcgi进程
返回页首
阅览会员资料 发送站内信件
scyzxp
道童


注册时间: 2005-04-12
文章: 317

文章发表于: Sun 2008-05-11 00:18:11    发表主题: 引用并回复

lhmwzy 写到:
jonsen 写到:
不明白,为什么还要安装lighttpd?
nginx+php就可以运行的很好了。


他是想用spawn-fcgi这个执行程序来展开php-fcgi进程


老大说得没错

_________________
-------------------------------
开源邮件技术社区
Tmail for FreeBSD技术支持社区
http://www.thismail.org
-------------------------------
返回页首
阅览会员资料 发送站内信件 MSN Messenger
uingei
半仙


注册时间: 2004-05-27
文章: 166
来自: 昱城

文章发表于: Mon 2008-05-12 12:21:28    发表主题: 引用并回复

kenbaby 写到:
难道你没有修改fixpathinfo?


默认cgi.fix_pathinfo=1,应该不需要修改吧

虚拟主机用php-fcgi似乎不是很安全

_________________
群号码:9784513
返回页首
阅览会员资料 发送站内信件 MSN Messenger
kenbaby
道童


注册时间: 2005-03-19
文章: 300

文章发表于: Wed 2008-05-14 17:35:36    发表主题: 引用并回复

uingei 写到:
kenbaby 写到:
难道你没有修改fixpathinfo?


默认cgi.fix_pathinfo=1,应该不需要修改吧

虚拟主机用php-fcgi似乎不是很安全


你确定默认是cgi.fix_pathinfo=1?

_________________
是男人就用8.0-CURRENT!
返回页首
阅览会员资料 发送站内信件 浏览发表者的主页
ztjjf
半仙


注册时间: 2007-07-27
文章: 53

文章发表于: Thu 2008-05-15 14:50:20    发表主题: 引用并回复

http://www.freebsdchina.org/forum/viewtopic.php?p=221550#221550

我的出这个错了。 Embarassed
返回页首
阅览会员资料 发送站内信件
从以前的文章开始显示:   
发表新文章   回复文章    FreeBSD China -> 技术交流 论坛时间为 北京时间
1页/共1

 
转跳到:  
不能发布新主题
不能在这个论坛回复主题
不能在这个论坛编辑自己的文章
不能在这个论坛删除自己的文章
不能在这个论坛发表投票


Powered by phpBB 2022cc © 2003 Opensource Steps; © 2003-2007 The FreeBSD Simplified Chinese Project
Powered by phpBB © 2001, 2005 phpBB Group
The FreeBSD China Project 网站: 中文计划网站 社区网站
The FreeBSD China Project 版权所有 (C) 1999 - 2003 网页设计版权 著作权和商标