doucai7294 2010-02-09 23:42
浏览 56
已采纳

Sqlite3,apache用户,易于安装

I'm writing a small app that needs to have a super easy install process. Version one used a csv file instead of a database, so priority #1 for v2 is getting sqlite going instead. I've used sqlite a lot with Ruby, and love it, but this is my first time using it with PHP.

Basically, in order to get SQlite3 to be able to insert into the db, I needed to make both the database.sqlite3 file and the folder containing it owned by the apache user. From reading the docs, this seems normal.

However, apache isn't always going to be running as the same user. Here, it's 'http', but I know on Ubuntu it's 'www-data', right?

So, is there a good way to detect the username Apache is running as, and changing it, or am I going about this wrong? It needs to be something I can just put in the install script, as the people who use this app don't know or care anything about tiny details like this.

Thanks.

  • 写回答

1条回答 默认 最新

  • dongshi1424 2010-02-10 20:38
    关注

    I believe you're going at it from the wrong side: you need the SQLite db to be writable by the PHP script, as I understand the matter, and this might not be the same as the Apache user. If PHP is installed as an Apache module it will inherit the Apache user, but a much more common case on shared servers is to have PHP set up as CGI under suphp or phpsuexec, so the scripts run with the permissions of the user himself.

    I'd suggest you write an install.php script to create the folder and the database, so both will inherit the script's permissions, no matter which user it is. Look into the manual for mkdir() and sqlite_open(). If nothing else works there's always chmod().

    As you specifically cite SQLite v. 3 you may want to check the server version with phpversion(); in PHP 5.3 sqlite_* functions do work with version 3, PHP 5.2 and below understand version 2 instead. To use version 3 in PHP 5.2 you must use pdo_sqlite.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 找人不需要人工智能回答的gamit解算后做形变分析
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错