查看: 3397|回复: 8

RioTboard 【上手试玩】成功安装NGINX + PHP

[复制链接]
  • TA的每日心情
    开心
    2013-10-31 08:31
  • 签到天数: 16 天

    连续签到: 1 天

    [LV.4]偶尔看看III

    发表于 2014-4-26 16:03:01 | 显示全部楼层 |阅读模式
    分享到:
    本帖最后由 gdmgb520 于 2014-4-27 16:37 编辑

    想要安装ouwCloud,前提是要搭建一个php环境。找来找去还是打算安装 NGINX + PHP + SQLite
    在爱板网的树莓板块找了网友的教程: 将树莓派变成一个Web服务器  来自网友 @GY@艳 ,表示感谢

    另外这里还有一篇很好的教程 Setting up nginx with php and SQLite on Ubuntu Server  :http://www.codebound.net/setting-up-nginx-with-php-and-sqlite-on-ubuntu-server.html

    按照这个帖子既可以搭建好,很简单,我就我重复码字了,这里补充我遇到的两个问题。我使用的串口登录的。

    1.直接使用  sudo apt-get install nginx 安装不成功,提示我使用 apt-get autoremove ,我就照做了,过程中貌似卸载了一些东西,然后重新执行 sudo apt-get install nginx 就成功。

    2.关于配置文件的问题
    与这篇教程里的不一样,需要改成这样
    1. location ~ \.php$ {
    2.                 fastcgi_pass 127.0.0.1:9000;
    3.                 fastcgi_index index.php;
    4.                 include fastcgi_params;
    5. }
    复制代码
    其他部分与教程里一致。

    搭建web服务器有什么用?搞个Wordpress?No No No! 智能家居或者书籍采集才是目的!

    大家赶紧试试吧。



    补充:
    遇到文件写权限问题:
    Warning: fopen(heiyeluren.txt) [function.fopen]: failed to open stream: Perm
    解决:
    修改NGINX下www目录的读写权限
    chmod 777 ./www

    安装sqlite3应该使用如下命令:
    sudo apt-get install php5-sqlite
    sudo apt-get install sqlite3
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2013-10-31 08:31
  • 签到天数: 16 天

    连续签到: 1 天

    [LV.4]偶尔看看III

     楼主| 发表于 2014-4-26 16:45:54 | 显示全部楼层
    补张图片,呵呵
    php.png
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2013-10-31 08:31
  • 签到天数: 16 天

    连续签到: 1 天

    [LV.4]偶尔看看III

     楼主| 发表于 2014-4-26 17:48:36 | 显示全部楼层
    想使用php操作sqlite3 数据库,还是没有成功。
    下面的代码提示缺少类,应该是要包含头文件,不知道是什么头文件!!
    1. <?php
    2. $db_path = 'sqlite3_db_php';
    3. //public SQLite3::__construct ( string $filename [, int $flags [, string $encryption_key ]] )
    4. //Returns an SQLite3 object on success.
    5. $db = new SQLite3($db_path);
    6. if (!!$db) {
    7.         //public bool SQLite3::exec ( string $query )
    8.         //$query : The SQL query to execute (typically an INSERT, UPDATE, or DELETE query).
    9.         //Returns TRUE if the query succeeded, FALSE on failure.
    10.         //下面创建一个表格
    11.         $db->exec('CREATE TABLE user (id integer primary key, name varchar(32), psw varchar(32))');
    12.         //插入记录
    13.         $name = rand(1001,9999);
    14.         $psw = md5($name);
    15.         $db->exec("INSERT INTO user VALUES (NULL, '{$name}', '{$psw}')");
    16.         //public int SQLite3::lastInsertRowID ( void )
    17.         echo "n成功插入记录:",$db->lastInsertRowID(),"n";
    18.         //public SQLite3Result SQLite3::query ( string $query )
    19.         //Returns an SQLite3Result object if the query returns results. Otherwise, returns TRUE if the query succeeded, FALSE on failure.
    20.         //查询记录
    21.         $result = $db->query('SELECT * FROM user ORDER BY id DESC LIMIT 0,10');
    22.         //public int SQLite3Result::numColumns ( void )
    23.         //public string SQLite3Result::columnName ( int $column_number )
    24.         $cols = $result->numColumns();
    25.         for($i=0; $i<$cols; $i++){
    26.                 echo $result->columnName($i),"t";
    27.         }
    28.         //public array SQLite3Result::fetchArray ([ int $mode = SQLITE3_BOTH ] )
    29.         //Fetches a result row as an associative or numerically indexed array or both. By default, fetches as both.
    30.         //$mode : SQLITE3_ASSOC, SQLITE3_NUM, or SQLITE3_BOTH.
    31.         //Returns a result row as an associatively or numerically indexed array or both.
    32.         while($row = $result->fetchArray(SQLITE3_ASSOC)){
    33.                 echo "n{$row['id']}t{$row['name']}t{$row['psw']}";
    34.         }
    35.         //重置结果集指针到第一条之前
    36.         //public bool SQLite3Result::reset ( void )
    37.         //Resets the result set back to the first row.
    38.         //Returns TRUE if the result set is successfully reset back to the first row, FALSE on failure.
    39.         $result->reset();
    40.         //public bool SQLite3Result::finalize ( void )
    41.         //释放结果集
    42.         $result->finalize();
    43.         //public bool SQLite3::close ( void )
    44.         //关闭数据库
    45.         $db->close();

    46.         //public SQLite3Stmt SQLite3::prepare ( string $query )
    47.         //Returns an SQLite3Stmt object on success 或者在失败时返回 FALSE.
    48.         //预处理查询
    49.         $stmt = $db->prepare('SELECT bar FROM foo WHERE id=:id');
    50.         //public bool SQLite3Stmt::bindValue ( string $sql_param , mixed $value [, int $type ] )
    51.         //Returns TRUE if the value is bound to the statement variable, FALSE on failure.
    52.         //$type:
    53.                 //SQLITE3_INTEGER: The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
    54.                 //SQLITE3_FLOAT: The value is a floating point value, stored as an 8-byte IEEE floating point number.
    55.                 //SQLITE3_TEXT: The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16-LE).
    56.                 //SQLITE3_BLOB: The value is a blob of data, stored exactly as it was input.
    57.                 //SQLITE3_NULL: The value is a NULL value
    58.         //绑定值
    59.         $stmt->bindValue(':id', 1, SQLITE3_INTEGER);
    60.         //public SQLite3Result SQLite3Stmt::execute ( void )
    61.         //Returns an SQLite3Result object on successful execution of the prepared statement, FALSE on failure.
    62.         //执行预处理
    63.         $result = $stmt->execute();
    64.         //public bool SQLite3Stmt::clear ( void )
    65.         //Returns TRUE on successful clearing of bound parameters, FALSE on failure.
    66.         //清除所有绑定参数
    67.         //public int SQLite3Stmt::paramCount ( void )
    68.         //Returns the number of parameters within the prepared statement.
    69.         //
    70.         //public bool SQLite3Stmt::bindParam ( string $sql_param , mixed &$param [, int $type ] )
    71.         //Returns TRUE if the parameter is bound to the statement variable, FALSE on failure.
    72.         //
    73. }
    74. ?>
    复制代码
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2013-10-31 08:31
  • 签到天数: 16 天

    连续签到: 1 天

    [LV.4]偶尔看看III

     楼主| 发表于 2014-4-26 17:55:39 | 显示全部楼层
    提示这样的错误:

    Fatal error: Class 'SQLite3' not found in /usr/share/nginx/www/testsqlite3.php on line 5
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2013-10-31 08:31
  • 签到天数: 16 天

    连续签到: 1 天

    [LV.4]偶尔看看III

     楼主| 发表于 2014-4-27 16:53:35 | 显示全部楼层
    本帖最后由 gdmgb520 于 2014-4-27 16:58 编辑

    从和这个网站找到怎么测试sqlit3是否安装成功。
    前提是要安装sqlite的命令行shell : apt-get install sqlite3
    具体方法:
    1. $ sqlite3 ex1
    2. SQLite version 3.8.4 2014-02-11 16:24:34
    3. Enter ".help" for usage hints.
    4. sqlite> create table tbl1(one varchar(10), two smallint);
    5. sqlite> insert into tbl1 values('hello!',10);
    6. sqlite> insert into tbl1 values('goodbye', 20);
    7. sqlite> select * from tbl1;
    8. hello!|10
    9. goodbye|20
    10. sqlite>
    复制代码
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    2015-11-4 19:13
  • 签到天数: 281 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2014-4-27 17:23:08 | 显示全部楼层
    这服务器能做什么,静态页面?
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2013-10-31 08:31
  • 签到天数: 16 天

    连续签到: 1 天

    [LV.4]偶尔看看III

     楼主| 发表于 2014-4-27 20:56:45 | 显示全部楼层
    小鸟愤怒 发表于 2014-4-27 17:23
    这服务器能做什么,静态页面?

    功能相当于 Apache + php + MySQL
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    2015-11-4 19:13
  • 签到天数: 281 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2014-4-27 21:13:25 | 显示全部楼层
    gdmgb520 发表于 2014-4-27 20:56
    功能相当于 Apache + php + MySQL

    那不是可以直接在上面建站了?
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2013-10-31 08:31
  • 签到天数: 16 天

    连续签到: 1 天

    [LV.4]偶尔看看III

     楼主| 发表于 2014-4-27 21:32:45 | 显示全部楼层
    小鸟愤怒 发表于 2014-4-27 21:13
    那不是可以直接在上面建站了?

    对的,但是更实际的意义应该是智能家居和分布式床拿起数据采集处理。
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-4-20 06:42 , Processed in 0.194170 second(s), 31 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.