免费注册 查看新帖 |

Chinaunix

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

[FreeBSD] FNMP(FreeBSD+Nginx+Mysql+PHP)安装记 [复制链接]

论坛徽章:
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
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-02-15 22:46 |只看该作者 |倒序浏览
折腾了一个晚上,基本上都是用packages安装,php用ports安装,由于PHP只用了FastCGI模式,所以phpmyadmin提示缺少模块而无法安装,最后下载的源码安装。整个过程中,竟然发现最耗费时间的PHP的那些模块!
其实安装完成后再回过头来看,步骤熟练后,加上编译时间,半个小时足够!  

先做个规划,操作步骤分三块,分别用三个帖子来写,分别是:软件的安装,软件的设置,启动调试及遇到错误说明。

主要思路:用php-fpm来管理FastCGI。在网上的大多数资料都是用lighttp来安装管理,但是据说php-fpm比那个要强,所以就赶了一回时髦,用了一下php-fpm。

http://php-fpm.org/downloads/

先列一下安装的东西,其实由安装的软件列表,就可以看出用做的过程,今天晚了,明天写步骤:

autoconf-2.62       Automatically configure source code on many Un*x platforms
autoconf-wrapper-20071109 Wrapper script for GNU autoconf
e2fsprogs-libuuid-1.41.3_1 UUID library from e2fsprogs package
freetype2-2.3.7     A free and portable TrueType font rendering engine
gettext-0.17_1      GNU gettext package
gmake-3.81_3        GNU version of 'make' utility
jpeg-6b_7           IJG's jpeg compression utilities
kbproto-1.0.3       KB extension headers
libICE-1.0.4_1,1    Inter Client Exchange library for X11
libSM-1.1.0,1       Session Management library for X11
libX11-1.1.99.2,1   X11 library
libXau-1.0.4        Authentication Protocol library for X11
libXaw-1.0.5_1,1    X Athena Widgets library
libXdmcp-1.0.2_1    X Display Manager Control Protocol library
libXext-1.0.4,1     X11 Extension library
libXmu-1.0.4,1      X Miscellaneous Utilities libraries
libXp-1.0.0,1       X print library
libXpm-3.5.7        X Pixmap library
libXt-1.0.5_1       X Toolkit library
libiconv-1.11_1     A character set conversion library
libltdl-1.5.26      System independent dlopen wrapper
libmcrypt-2.5.8     Multi-cipher cryptographic library (used in PHP)
libpthread-stubs-0.1 This library provides weak aliases for pthread functions
libxcb-1.1.93       The X protocol C-language Binding (XCB) library
libxml2-2.7.2_1     XML parser library for GNOME
m4-1.4.11,1         GNU m4
mysql-client-5.0.75 Multithreaded SQL database (client)
mysql-server-5.0.75 Multithreaded SQL database (server)
nginx-0.6.35        Robust and small WWW server

pcre-7.8            Perl Compatible Regular Expressions library
perl-5.8.9          Practical Extraction and Report Language
php5-5.2.8          PHP Scripting Language
php5-bz2-5.2.8      The bz2 shared extension for php
php5-ctype-5.2.8    The ctype shared extension for php
php5-dom-5.2.8      The dom shared extension for php
php5-exif-5.2.8     The exif shared extension for php
php5-fpm-5.2.8      PHP Scripting Language with FastCGI Process Manager
php5-gd-5.2.8       The gd shared extension for php
php5-mbstring-5.2.8 The mbstring shared extension for php
php5-mcrypt-5.2.8   The mcrypt shared extension for php
php5-mysql-5.2.8    The mysql shared extension for php
php5-openssl-5.2.8  The openssl shared extension for php
php5-session-5.2.8  The session shared extension for php
php5-simplexml-5.2.8 The simplexml shared extension for php
php5-spl-5.2.8      The spl shared extension for php
php5-xml-5.2.8      The xml shared extension for php
php5-xmlreader-5.2.8 The xmlreader shared extension for php
php5-zlib-5.2.8     The zlib shared extension for php
phpMyAdmin-3.1.2    A set of PHP-scripts to manage MySQL over the web
pkg-config-0.23_1   A utility to retrieve information about installed libraries
png-1.2.34          Library for manipulating PNG images
printproto-1.0.4    Print extension headers
python25-2.5.2_3    An interpreted object-oriented programming language
t1lib-5.1.2_1,1     A Type 1 Rasterizer Library for UNIX/X11
xcb-proto-1.3       The X protocol C-language Binding (XCB) protocol
xextproto-7.0.4     XExt extension headers
xproto-7.0.14       X11 protocol headers


后来找到phpMyAdmin的安装,老提示少一个pdflib,后来加上-f参数强行跳过去了。

[ 本帖最后由 lsstarboy 于 2009-11-1 19:29 编辑 ]

评分

参与人数 1可用积分 +1 收起 理由
shang2010 + 1

查看全部评分

论坛徽章:
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
2 [报告]
发表于 2009-02-15 22:47 |只看该作者
第一部分:软件的安装

0、预备式:FB系统安装。这个就不再多说了,要做服务器,最小化安装就行了,其它的都不用。

---------------------------------------------------------------------------------------------------------------------------

1、信赖软件安装:
 可以用packages来安装,节省时间和硬盘空间,注意红字部分,要加上版本号(Mysql安装也需要加上版本号,下面为了用packages安装php5-mysql,要用mysql50-server来安装mysql5.0.26):

setenv PACKAGESROOT ftp://ftp.freebsdchina.org
pkg_add -r libxml2 gmake autoconf262
  千万别怀疑,目前为止,这三个就够了。

---------------------------------------------------------------------------------------------------------------------------

2、nginx安装

  pkg_add -r nginx  


     没错!安装就这么简单。

---------------------------------------------------------------------------------------------------------------------------


3、php的模块安装。

  没记错,就是这样安装。因为这些模块会信赖php5,所以默认会把php5给安装上。然后再装php5-fpm时就把php5给覆盖。如果先安装php-fpm再安装这些模块的话,信赖的php5就会把php-fpm的一些文件覆盖,导致“参数为零”的错误。

  这个主要看用哪些模块,一般php5-gd,php5-mysql是必须的:
pkg_add -r php5-bz2 php5-dom php5-exif php5-gd php5-session php5-simplexml php5-spl php5-xml php5-xmlreader php5-zlib


---------------------------------------------------------------------------------------------------------------------------


4、核心部分:php-fpm安装,这是操作的最重要的一个环节,在网上的资料也不多,网上关于php-fpm的资料大多是基于Linux的,基于BSD环境的很少。

  
  • (1)到php-fpm的官方网站下载ports。http://php-fpm.org/downloads/


    如果想手动下载,然后上传到服务器中,那么在网址:http://php-fpm.anight.org/

          ------2009年7月27日注:php-fpm已经出了5.10版的ports,http://php-fpm.org/downloads/fre ... 3.tar.gz-----------

      
  • (1.5)说明     注意到网站上去找的路径,千万别走错地方,如果直接点下载的话,编译会老出错,会卡在一个“不是libtool的模块”的错误上:download->archive->freebsd-port->php-5.2.8-fpm-0.5.10.tar.gz 。也可以直接点这儿
         CU本地链接下载: php-5.2.8-fpm-0.5.10.tar.gz (9.43 KB, 下载次数: 75)

      
  • (2)下载最新ports,只要base和devel就可以。
    ee /usr/share/examples/cvsup/ports-supfile

    修改约49行:
    *default host=cvsup5.cn.FreeBSD.org

    注释掉65行,
    #ports-all

    去掉74行和88行前面的“#”号。
    ports-base
    ports-devel

    执行升级:
    csup /usr/share/examples/cvsup/ports-supfile


      
  • (2.5)说明:需要升级devel子目录,是因为后面的PHP编译需要里面autoconf262的ports,如果找不到这个ports,即使安装好packages包,也会提示
    cannot install: unknown AUTOCONF version: 262


      如果不想下载那么多的ports,那么可以只升级ports-base,将下面的文件解压到/usr/ports/devel/autoconf262就行。当然如果你的硬盘足够大,可以把整个ports树都升级。 autoconf262.tar (2.9 KB, 下载次数: 71)
    然后执行就行了:
    tar -xzvPf autoconf262.tar -C /usr/ports/devel/



      
  • (3)对下载下来的文件解压,这个不用说了。这时候php-5.2.8-fpm-0.5.10.tar.gz会变成php-5.2.8-fpm-0.5.10.tar.diff。
    gupzip php-5.2.8-fpm-0.5.10.tar.gz


      
  • (4)再解压。有人会说有毛病啊!已经是diff文件了还用解压,但的确是这样,这不是一个普通的diff文件,而是一个ports的tar文档。
    tar -xvf php-5.2.8-fpm-0.5.10.tar.diff
    ,这时候会出现一个文件夹,里面就是php的ports:
    php5-fpm


      
  • (5)把/usr/ports/lang/php5里面清空(如果有的话,没有就建一个),再把这个文件夹的内容复制到/usr/ports/lang/php5里面去:
    rm -rf /usr/ports/lang/php5
    cp -r php5-fpm /usr/ports/lang/php5


      
  • (5.5)说明:对于纯命令行操作,上面的三步可以并作一步走,但是操作要求高点:
    cd ~ && mkdir -p /usr/ports/lang && tar -xvf php-5.2.8-fpm-0.5.10.tar.gz -C /usr/ports/lang/



      
  • (6)进入php5,进行编译。编译时如果不用ipv6,则去掉ipv6选项。
    cd /usr/ports/lang/php5-fpm&&make install clean


      注:其实这个包的编译和安装还需要/usr/ports/textproc/libxml2的ports,但是没有的话也只是报一个错误,不影响使用。

    ---------------------------------------------------------------------------------------------------------------------------

    5、mysql安装
      这个简单,但是注意要加上版本号,否则会和下面的php5-mysql冲突。

      
    pkg_add -r mysql50-server


    ---------------------------------------------------------------------------------------------------------------------------


    6、phpmyadmin的安装:

      没啥说的,提示一下注意大小写:
    pkg_add -r phpMyAdmin

    [ 本帖最后由 lsstarboy 于 2009-11-1 19:30 编辑 ]
  • 论坛徽章:
    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
    3 [报告]
    发表于 2009-02-15 22:47 |只看该作者
    第二部分:软件的配置

    一、mysql

      Mysql部分主要有三个步骤:配置mysql、建立数据库、设立root密码。

    cp /usr/local/share/mysql/my-medium.cnf /var/db/mysql/my.cnf&&ee /var/db/mysql/my.cnf
    主要是把里面的skip-networking前的#号去掉,这样就不再监听3306端口。(如果mysql和php不是在一个主机上,那么不能做这一步。)
      说明:有很多资料说是把配置文件复制为:/etc/my.cnf,但是根据/usr/local/etc/mysql-server里的脚本,应该把配置文件放在/var/db/mysql里。5.0.67会出现max_join_size的错误,这个应该是mysql的一个bug,在mysql网站上也有人提交了这个bug,据说在5.0.68里解决。http://bugs.mysql.com/bug.php?id=33785

    建立数据库,并设置数据库的权限,ports安装完后,自动建了一个mysql:mysql用户:
    /usr/local/bin/mysql_install_db
    chown -R mysql:mysql /var/db/mysql
    然后就可以启动数据库试试,如果没有其它的提示,就成功了:
    /usr/local/etc/rc.d/mysql-server forcestart



    修改root密码,这是因为默认的root用户没有密码,很容易造成安全问题。
    /usr/local/bin/mysqladmin -u root password "abcd"
    其中“abcd”为想设置的密码,建议设置的复杂一些。

    二、php-fpm的配置:修改
    /usr/local/etc/php-fpm.conf
    修改里面的user和group,这个应该和nginx里的相对应。因为ports创建了www:www用户,所以还是改为www:www:
                            Unix user of processes
                    <value name="user">www</value>

                            Unix group of processes
                    <value name="group">www</value>


    三、php配置:如果不想改,或者没有其它特殊的选项,直接复制就可以了,默认的配置就比较不错。
    cp /usr/local/etc/php.ini-recommended /usr/local/etc/php.ini


    四、nginx配置:
    ee /usr/local/etc/nginx/nginx.conf
    修改内容主要为:
      (1)第1行:user www
      (2)37行: server_name 换成IP地址。
      (3)45行: index  index.php index.html index.htm;加上index.php
      (4)把64行到72行的注释去掉,并且修改一下fastcgi_param  SCRIPT_FILENAME,这个比较容易出问题,还是列一下例子:

    [/quote]        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;                 
            }                                     [/quote]注意上面提到的那个参数,因为ports默认把网站根目录放到/usr/local/www/nginx里,所以要设置为/usr/local/www/nginx,后面的那个变量可以不用管。如果你想把网站根目录放到另外一个地方,那么就修改到你所指定的位置,提醒一下,别忘了修改/root。

    五、FreeBSD的自动启动:
    在/etc/rc.conf里加上下面三句:
    mysql_enable="yes"
    php_fpm_enable="yes"
    nginx_enable="yes"
    注意第二句,php和fpm之间是下划线,不是短横,我因为这个错误重启了好几次。


      至些为止,可以启动一下试试了。

    [ 本帖最后由 lsstarboy 于 2009-2-19 19:26 编辑 ]

    论坛徽章:
    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 [报告]
    发表于 2009-02-15 22:47 |只看该作者
    第三部分:说明与问题

    论坛徽章:
    0
    5 [报告]
    发表于 2009-02-15 22:59 |只看该作者
    强帖出现,占位

    论坛徽章:
    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
    6 [报告]
    发表于 2009-02-15 23:19 |只看该作者
    呵呵!顺手再占个位,发个nginx的locate说明,这东西挺费脑筋!

    有时间再翻译一下,这玩意高手不用翻译,新手又看不懂!在配置中又占很高的地位,所以......还是好好学英文!!!

    http://wiki.codemongers.com/NginxChsHttpCoreModule#location

    location

    syntax: location [=|~|~*|^~] /uri/ { ... }

    default: no

    context: server

    This directive allows different configurations depending on the URI. It can be configured using both conventional strings and regular expressions. To use regular expressions, you must use the prefix ~* for case insensitive match and ~ for case sensitive match.

    To determine which location directive matches a particular query, the conventional strings are checked first. Conventional strings match the beginning portion of the query and are case-sensitive - the most specific match will be used (see below on how nginx determines this). Afterwards, regular expressions are checked in the order defined in the configuration file. The first regular expression to match the query will stop the search. If no regular expression matches are found, the result from the convention string search is used.

    There are two ways to modify this behavior. The first is to use the prefix "=", which matches an exact query only. If the query matches, then searching stops and the request is handled immediately. For example, if the request "/" occurs frequently, then using "location = /" will expedite the processing of this request.

    The second is to use the prefix ^~. This prefix is used with a conventional string and tells nginx to not check regular expressions if the path provided is a match. For instance, "location ^~ /images/" would halt searching if the query begins with /images/ - all regular expression directives would not be checked.

    Furthermore it is important to know that NGINX does the comparison not URL encoded, so if you have a URL like "/images/%20/test" then use "/images/ /test" to determine the location.

    To summarize, the order in which directives are checked is as follows:

       1. Directives with the = prefix that match the query exactly. If found, searching stops.
       2. All remaining directives with conventional strings, longest match first. If this match used the ^~ prefix, searching stops.
       3. Regular expressions, in order of definition in the configuration file.
       4. If #3 yielded a match, that result is used. Else the match from #2 is used.

    Example:

    location  = / {
        # matches the query / only.
        [ configuration A ]
    }
    location  / {
        # matches any query, since all queries begin with /, but regular
        # expressions and any longer conventional blocks will be
        # matched first.
        [ configuration B ]
    }
    location ^~ /images/ {
        # matches any query beginning with /images/ and halts searching,
        # so regular expressions will not be checked.
        [ configuration C ]
    }
    location ~* \.(gif|jpg|jpeg)$ {
        # matches any request ending in gif, jpg, or jpeg. However, all
        # requests to the /images/ directory will be handled by
        # Configuration C.   
        [ configuration D ]
    }

    Example requests:

        *

          / -> configuration A
        *

          /documents/document.html -> configuration B
        *

          /images/1.gif -> configuration C
        *

          /documents/1.jpg -> configuration D

    Note that you could define these 4 configurations in any order and the results would remain the same.

    How nginx Determines Which Path Matches

    Most users will not need to know how nginx internally determines which path to use - know that it will choose the "most specific" match for your URL in a speedy and efficient manner. For those that are curious, however, read on.

    All path strings are sorted alphabetically. nginx then proceeds to search down the list looking for matches until the request URI has a "higher" value then the current string in the sorted list. This is determined using the family of strcmp() functions - once strcmp() returns 1, then searching stops. Once searching stops, the last string which matched is used.

    For example, lets say we have the following paths:

    /
    /a
    /apple
    /banana

    Now, lets say the server gets the path "/az". nginx would begin search down this list. First, "/" would match, but "/ is less than "/az" so searching continues. "/a" also matches, but "/a" is still less than "/az" so we continue again. "/apple" does not match. The next string, "/banana", is greater than "/az" so searching stops and the last match, "/a", would be used.

    论坛徽章:
    0
    7 [报告]
    发表于 2009-02-16 12:12 |只看该作者
    强帖出现,占位学习!!!嘿嘿!

    论坛徽章:
    0
    8 [报告]
    发表于 2009-02-16 22:58 |只看该作者
    强帖站位  保持关注

    请问下  nginx  怎么做虚拟主机呢  
    就是  多域名绑定 指定不同目录  一直没搞明白!

    [ 本帖最后由 ppabc 于 2009-2-20 09:06 编辑 ]

    论坛徽章:
    0
    9 [报告]
    发表于 2009-02-18 12:58 |只看该作者
    好东西
    学习

    论坛徽章:
    2
    狮子座
日期:2013-08-26 15:25:32金牛座
日期:2013-09-05 15:45:36
    10 [报告]
    发表于 2009-02-18 21:39 |只看该作者
    恩,php解析那个没用过

    可以第一页站位吗
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

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

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP