免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 19593 | 回复: 27
打印 上一主题 下一主题

[FreeBSD] FreeBSD7.0编译安装nginx+php+mysql. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-08 12:41 |只看该作者 |倒序浏览
环境
系统:FreeBSD7.0
软件:mysql-5.0.51a,nginx-0.6.30,lighttpd-1.4.19,php-5.2.6
所有软件都安装到/usr/local/vhost,如果需要请自行修改

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


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

  3. cd /usr/ports/www/nginx-devel/
  4. make fetch

  5. cd /usr/ports/lang/php5
  6. make fetch

  7. cd /usr/ports/www/lighttpd
  8. make fetch
复制代码
二、编译安装
MySQL
  1. cd /usr/ports/distfiles/
  2. tar -jxf mysql-5.0.51a.tar.gz
  3. cd mysql-5.0.51a
  4. ./configure --prefix=/usr/local/vhost/mysql --with-charset=utf8 --with-extra-charsets=all --with-big-tables --with-pthread
  5. make &&make install
复制代码
Nginx
  1. cd /usr/ports/devel/pcre
  2. make install clean

  3. cd /usr/ports/distfiles/
  4. tar -jxf nginx-0.6.30.tar.gz
  5. cd nginx-0.6.30
  6. ./configure --prefix=/usr/local/vhost/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_sub_module
  7. make &&make install
复制代码
Lighttpd
(安装lighttpd是为了得到启动fastcgi进程)
  1. cd /usr/ports/distfiles/
  2. tar -jxf lighttpd-1.4.19.tar.bz2
  3. cd lighttpd-1.4.19
  4. ./configure --prefix=/usr/local/vhost/lighttpd
复制代码
Php
  1. cd /usr/ports/textproc/libxml2
  2. make install clean

  3. cd /usr/ports/ftp/curl
  4. make install clean

  5. cd /usr/ports/graphics/jpeg
  6. make install clean

  7. cd /usr/ports/graphics/png
  8. make install clean

  9. cd /usr/ports/devel/gettext
  10. make install clean

  11. cd /usr/ports/distfiles/
  12. tar -jxf php-5.2.6.tar.bz2
  13. cd php-5.2.6
  14. ./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
  15. make && make install
  16. cp php.ini-dist /usr/local/vhost/php/lib/php.ini
复制代码
三、配置

MySQL
  1. cd /usr/local/vhost/mysql
  2. pw adduser mysql -d /dev/null -s /sbin/nologin
  3. bin/mysql_install_db
  4. cp share/mysql/mysql.server ./
  5. chmod +x mysql.server
  6. chown -R mysql ./
复制代码
启动
/usr/local/vhost/mysql/mysql.server start


配置nginx
  1. cd /usr/local/vhost/nginx/
  2. pw adduser webuser -d /dev/null -s /sbin/nologin
  3. cp /usr/local/vhost/lighttpd/bin/spawn-fcgi ./sbin/
  4. rm -rf /usr/local/vhost/lighttpd
复制代码
vi sbin/php.sh
  1. #!/bin/sh
  2. /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
  1. location ~ \.php$ {
  2.         root           html;
  3.         fastcgi_pass   127.0.0.1:9000;
  4.         fastcgi_index  index.php;
  5.         fastcgi_param  SCRIPT_FILENAME  /usr/local/vhost/nginx/html$fastcgi_script_name;
  6.         fastcgi_param  QUERY_STRING       $query_string;
  7.         fastcgi_param  REQUEST_METHOD     $request_method;
  8.         fastcgi_param  CONTENT_TYPE       $content_type;
  9.         fastcgi_param  CONTENT_LENGTH     $content_length;

  10.         fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
  11.         fastcgi_param  REQUEST_URI        $request_uri;
  12.         fastcgi_param  DOCUMENT_URI       $document_uri;
  13.         fastcgi_param  DOCUMENT_ROOT      $document_root;
  14.         fastcgi_param  SERVER_PROTOCOL    $server_protocol;

  15.         fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
  16.         fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

  17.         fastcgi_param  REMOTE_ADDR        $remote_addr;
  18.         fastcgi_param  REMOTE_PORT        $remote_port;
  19.         fastcgi_param  SERVER_ADDR        $server_addr;
  20.         fastcgi_param  SERVER_PORT        $server_port;
  21.         fastcgi_param  SERVER_NAME        $server_name;

  22.         # PHP only, required if PHP was built with --enable-force-cgi-redirect
  23.         fastcgi_param  REDIRECT_STATUS    200;
  24. }
复制代码
vi conf/nginx.conf
  1. user  webuser webuser;
  2. worker_processes  1;

  3. events {
  4.     worker_connections  4096;
  5.     use kqueue;
  6. }


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

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

  13.     #access_log  logs/access.log  main;

  14.     client_header_timeout  3m;
  15.     client_body_timeout    3m;
  16.     send_timeout           3m;
  17.     client_max_body_size  5m;

  18.     client_header_buffer_size    1k;
  19.     large_client_header_buffers  4 4k;

  20.     gzip on;
  21.     gzip_min_length  1100;
  22.     gzip_buffers     4 8k;
  23.     gzip_types       text/plain;

  24.     output_buffers   1 32k;
  25.     postpone_output  1460;

  26.     sendfile         on;
  27.     tcp_nopush       on;
  28.     tcp_nodelay      on;
  29.     send_lowat       12000;

  30.     keepalive_timeout  75 20;


  31.     server {
  32.         listen       80;
  33.         server_name  localhost;

  34.         location / {
  35.             root   html;
  36.             index  index.php index.html index.htm;
  37.         }

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

  45.         include enable_php;
  46.         error_page   500 502 503 504  /50x.html;
  47.         location = /50x.html {
  48.             root   html;
  49.         }

  50.     }
  51. }
复制代码
测试配置文件
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
  1. <?php
  2. phpinfo();
  3. ?>
复制代码
启动测试
/usr/local/vhost/nginx/sbin/nginx


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


安装配置phpMyadmin
  1. cd /usr/ports/databases/phpmyadmin/
  2. make fetch

  3. cd /usr/ports/distfiles
  4. tar -jxf phpMyAdmin-2.11.6-all-languages.tar.bz2
  5. mv phpMyAdmin-2.11.6-all-languages /usr/local/vhost/nginx/html/dbadmin
复制代码
此时MySQL的root没有密码,如果一切正常可以用
http://192.168.29.128/dbadmin/index.php来管理MySQL了

论坛徽章:
2
2015年辞旧岁徽章
日期:2015-03-03 16:54:1515-16赛季CBA联赛之上海
日期:2016-05-05 09:45:14
2 [报告]
发表于 2008-05-08 13:33 |只看该作者
顶老哥一把,和和,

论坛徽章:
0
3 [报告]
发表于 2008-05-08 14:34 |只看该作者
好像直接用ports安装比这个省了许多吧,脚本什么的都自动创建了。

php.ini最好用php.ini-recommended。

论坛徽章:
54
2017金鸡报晓
日期:2017-02-08 10:39:42操作系统版块每日发帖之星
日期:2016-03-08 06:20:00操作系统版块每日发帖之星
日期:2016-03-07 06:20:00操作系统版块每日发帖之星
日期:2016-02-22 06:20:00操作系统版块每日发帖之星
日期:2016-01-29 06:20:00操作系统版块每日发帖之星
日期:2016-01-27 06:20:00操作系统版块每日发帖之星
日期:2016-01-20 06:20:00操作系统版块每日发帖之星
日期:2016-01-06 06:20:0015-16赛季CBA联赛之江苏
日期:2015-12-21 20:00:24操作系统版块每日发帖之星
日期:2015-12-21 06:20:00IT运维版块每日发帖之星
日期:2015-11-17 06:20:002015亚冠之广州恒大
日期:2015-11-12 10:58:02
4 [报告]
发表于 2008-05-08 22:12 |只看该作者
挺好!

论坛徽章:
2
2015年迎新春徽章
日期:2015-03-12 10:39:39IT运维版块每日发帖之星
日期:2015-10-10 06:20:00
5 [报告]
发表于 2008-05-09 09:42 |只看该作者
nginx现在很火啊


不知道又没有水分

论坛徽章:
0
6 [报告]
发表于 2008-05-09 09:52 |只看该作者
原帖由 蓝色虫 于 2008-5-9 09:42 发表
nginx现在很火啊


不知道又没有水分


nginx的负载能力真的没话说。

论坛徽章:
0
7 [报告]
发表于 2008-05-24 22:05 |只看该作者
配置起来其实很简单的。完成可以用ports来安装的。我来帮楼主总结一下吧,如何用ports来搞定这一切。
nginx是通过调用fastcgi来解析PHP的,所以就可以这样说了。安装NGINX是一部分,然后安装PHP也是一部分,然后将nginx跟fastcgi连起来就行了。
先进入 /usr/ports/www/nginx    make install clean。OK nginx安装好了。
然后进入/usr/ports/www/lighttpd  运行make,不要运行make insall,因为nginx需要lighttpd带的spawn-fcgi来调用php-cgi,你make一下,他就自动生成了spawn-fcgi,在这里/usr/ports/www/lighttpd/work/lighttpd-1.4.19/src,运行
cp /usr/ports/www/lighttpd/work/lighttpd-1.4.19/src/spawn-fcgi /usr/local/bin

然后再进入/usr/ports/lang/php5  运行make install clean,注意要选CGI,跟FASTCGI,不能只选FASTCGI而不选CGI,这样就不会生成php-cgi程序。
如果还要安装其他PHP的扩展库,可以进入/usr/ports/lang/php5-extensions
运行make install clean 按需安装,安装完成之后,也就是PHP已经安装好了。

这个时候运行 /usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www -f /usr/local/bin/php-cgi
也就是初始化php的fastcgi进程,是127.0.0.1:9000端口,然后-C 10是指加载10个进程,-u www是以WWW用户来运行

然后接下来就是改nginx.conf了,按照楼主的来改就行了,改好之后就OK了。然后你要保证
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www -f /usr/local/bin/php-cgi  这条命令在开机就能运行,把他加到crontab里面就行了,让他开机自启动这条命令就行了。

论坛徽章:
0
8 [报告]
发表于 2008-05-24 23:31 |只看该作者
好文.留下来慢慢看

论坛徽章:
0
9 [报告]
发表于 2008-05-25 09:05 |只看该作者
好文,支持下!

论坛徽章:
0
10 [报告]
发表于 2008-05-25 15:02 |只看该作者
强烈支持。。。严重支持。。。。。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP