dimanche 25 octobre 2015

SQLite error with fastcgi, php and lighttpd on Manjaro

I just run an lighttpd server on Manjaro following: Lighttpd on archlinux.org

My phpinfo() output on jsfiddle.

Trying to test if my sqlite is working I run the following script:

    <?php
    // Create an SQLite DB in the file test.sqlite
      $db = new SQLiteDatabase("test.sqlite");
      $db-&gt;query("BEGIN;
              CREATE TABLE dbtest(id INTEGER PRIMARY KEY, article CHAR(50),price FLOAT(10));
              INSERT INTO dbtest (article,price) VALUES('Book1','12.99');
              INSERT INTO dbtest (article,price) VALUES('Book2','15.23');
              COMMIT;");
      $result = $db-&gt;query("SELECT * FROM dbtest");

      // Read and show the DB we created
      echo "&lt;PRE&gt;";
      printf("+------------+------------------------------------------+\n");
      printf("| Price       | Article                              |\n");
      printf("+------------+------------------------------------------+\n");
      while ($result-&gt;valid()) {
        $row = $result-&gt;current();
        printf("| %10s | %-40s |\n",$row['price'],$row['article']);
        $result-&gt;next();
      }
      printf("+------------+------------------------------------------+\n");
      echo "&lt;/PRE&gt;";
      unset($db);
     phpinfo();
    ?>

as newdb.php file.

The answer I get is 500 error code from browser when accessing localhost/newdb.php .

Logs from var/log/lighttpd/: (times might be wrong due to that I have changed my time zone today).

2015-10-25 19:14:29: (log.c.194) server started 
2015-10-25 19:41:51: (server.c.1451) [note] graceful shutdown started 
2015-10-25 19:41:51: (log.c.194) server started 
2015-10-25 19:41:51: (server.c.1567) server stopped by UID = 0 PID = 1257 
2015-10-25 19:52:58: (server.c.1451) [note] graceful shutdown started 
2015-10-25 19:52:58: (log.c.194) server started 
2015-10-25 19:52:58: (server.c.1567) server stopped by UID = 0 PID = 1257 
2015-10-25 20:35:20: (server.c.1451) [note] graceful shutdown started 
2015-10-25 20:35:20: (server.c.1567) server stopped by UID = 0 PID = 1 
2015-10-25 20:35:51: (log.c.194) server started 
2015-10-25 20:49:34: (server.c.1451) [note] graceful shutdown started 
2015-10-25 20:49:34: (server.c.1567) server stopped by UID = 0 PID = 400 
2015-10-25 20:50:45: (log.c.194) server started 

My lighttpd configs:

# This is a minimal example config
# See /usr/share/doc/lighttpd
# and http://ift.tt/1MN8nEl

server.port     = 80
server.username     = "http"
server.groupname    = "http"
server.document-root    = "/srv/http"
server.errorlog     = "/var/log/lighttpd/error.log"
dir-listing.activate    = "enable"
index-file.names    = ( "index.html" )
mimetype.assign     = (
                ".html" => "text/html",
                ".txt" => "text/plain",
                ".css" => "text/css",
                ".js" => "application/x-javascript",
                ".jpg" => "image/jpeg",
                ".jpeg" => "image/jpeg",
                ".gif" => "image/gif",
                ".png" => "image/png",
                "" => "application/octet-stream"
            )
include "conf.d/cgi.conf"
include "conf.d/fastcgi.conf"

cgi.conf:

server.modules += ( "mod_cgi" )

cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
                               ".cgi" => "/usr/bin/perl",
                               ".rb"  => "/usr/bin/ruby",
                               ".erb" => "/usr/bin/eruby",
                               ".py"  => "/usr/bin/python",
                               ".php" => "/usr/bin/php-cgi" )

index-file.names           += ( "index.pl",   "default.pl",
                               "index.rb",   "default.rb",
                               "index.erb",  "default.erb",
                               "index.py",   "default.py",
                               "index.php",  "default.php" )

fastcgi.conf

#######################################################################
##
##  FastCGI Module 
## --------------- 
##
## http://ift.tt/206kC8G
##
server.modules += ( "mod_fastcgi" )

# Make sure to install php and php-cgi. See:                                                             
# http://ift.tt/1MN8oIo

# FCGI server
# ===========
#
# Configure a FastCGI server which handles PHP requests.
#
index-file.names += ("index.php")
fastcgi.server = ( 
    # Load-balance requests for this path...
    ".php" => (
        # ... among the following FastCGI servers. The string naming each
        # server is just a label used in the logs to identify the server.
        "localhost" => ( 
            "bin-path" => "/usr/bin/php-cgi",
            "socket" => "/tmp/php-fastcgi.sock",
            # breaks SCRIPT_FILENAME in a way that PHP can extract PATH_INFO
            # from it 
            "broken-scriptfilename" => "enable",
            # Launch (max-procs + (max-procs * PHP_FCGI_CHILDREN)) procs, where
            # max-procs are "watchers" and the rest are "workers". See:
            # http://ift.tt/206kA0F 
            "max-procs" => 4, # default value
            "bin-environment" => (
                "PHP_FCGI_CHILDREN" => "1" # default value
            )
        )
    )   
)
##
## PHP Example
## For PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini.
##
## The number of php processes you will get can be easily calculated:
##
## num-procs = max-procs * ( 1 + PHP_FCGI_CHILDREN )
##
## for the php-num-procs example it means you will get 17*5 = 85 php
## processes. you always should need this high number for your very
## busy sites. And if you have a lot of RAM. :)
##
#fastcgi.server = ( ".php" =>
#                   ( "php-local" =>
#                     (
#                       "socket" => socket_dir + "/php-fastcgi-1.socket",
#                       "bin-path" => server_root + "/cgi-bin/php5",
#                       "max-procs" => 1,
#                       "broken-scriptfilename" => "enable",
#                     )
#                   ),
#                   ( "php-tcp" =>
#                     (
#                       "host" => "127.0.0.1",
#                       "port" => 9999,
#                       "check-local" => "disable",
#                       "broken-scriptfilename" => "enable",
#                     )
#                   ),
#
#                   ( "php-num-procs" =>
#                     (
#                       "socket" => socket_dir + "/php-fastcgi-2.socket",
#                       "bin-path" => server_root + "/cgi-bin/php5",
#                       "bin-environment" => (
#                         "PHP_FCGI_CHILDREN" => "16",
#                         "PHP_FCGI_MAX_REQUESTS" => "10000",
#                       ),
#                       "max-procs" => 5,
#                       "broken-scriptfilename" => "enable",
#                     )
#                   ),
#                )

##
## Ruby on Rails Example
##
## Normally you only run one Rails application on one vhost.
##
#$HTTP["host"] == "rails1.example.com" {
#  server.document-root  = server_root + "/rails/someapp/public"
#  server.error-handler-404 = "/dispatch.fcgi"
#  fastcgi.server = ( ".fcgi" =>
#    ("someapp" =>
#      ( "socket" => socket_dir + "/someapp-fcgi.socket",
#        "bin-path" => server_root + "/rails/someapp/public/dispatch.fcgi",
#        "bin-environment" => (
#              "RAILS_ENV" => "production",
#              "TMP" => home_dir + "/rails/someapp",
#        ),
#      )
#    )
#  )
#}

##
## Another example with multiple rails applications on one vhost.
##
## http://ift.tt/1MN8nEn
##
#$HTTP["host"] == "rails2.example.com" {
#  $HTTP["url"] =~ "^/someapp1" {
#    server.document-root  = server_root + "/rails/someapp1/public"
#    server.error-handler-404 = "/dispatch.fcgi"
#    fastcgi.server = ( ".fcgi" =>
#      ("someapp1" =>
#        ( "socket" => socket_dir + "/someapp1-fcgi.socket",
#          "bin-path" => server_root + "/rails/someapp1/public/dispatch.fcgi",
#          "bin-environment" => (
#                "RAILS_ENV" => "production",
#                "TMP" => home_dir + "/rails/someapp1",
#          ),
#          "strip-request-uri" => "/someapp1/"
#        )
#      )
#    )
#  }
#
#  $HTTP["url"] =~ "^/someapp2" {
#    server.document-root  = server_root + "/rails/someapp2/public"
#    server.error-handler-404 = "/dispatch.fcgi"
#    fastcgi.server = ( ".fcgi" =>
#      ("someapp2" =>
#        ( "socket" => socket_dir + "/someapp2-fcgi.socket",
#          "bin-path" => server_root + "/rails/someapp2/public/dispatch.fcgi",
#          "bin-environment" => (
#                "RAILS_ENV" => "production",
#                "TMP" => home_dir + "/rails/someapp2",
#          ),
#          "strip-request-uri" => "/someapp2/"
#        )
#      )
#    )
#  }
#}

## chrooted webserver + external PHP
##
## $ spawn-fcgi -f /usr/bin/php-cgi -p 2000 -a 127.0.0.1 -C 8
##
## webserver chrooted to /srv/www/
## php running outside the chroot
#
#fastcgi.server = ( 
#  ".php" => (( 
#    "host" => "127.0.0.1",
#    "port" => "2000",
#    "docroot" => "/srv/www/servers/http://ift.tt/1eRAJDX"
#  )))
#
#server.chroot = "/srv/www"
#server.document-root = "/servers/http://ift.tt/206kC8I"
#

##
#######################################################################

Aucun commentaire:

Enregistrer un commentaire