2016/Nuremberg: April 16, 2016!

PHP


PHP is a programming language and web server runtime environment used for many IndieWeb projects.

Contents

Projects

Libraries

Articles

Articles about the use of PHP, especially for software that you are expected to download and install on your own domain:

Troubleshooting

UTF8

While there are a number of symptoms (weird looking characters, one character split into two), the problems with UTF8 handling in PHP happen for a handful of different reasons. Here are some suggested fixes for some cases.

  • check the HTTP header returned, it should have:
    Content-Type: text/html; charset=UTF-8
    if it does not then you may need a line like this in your PHP code before it outputs any HTML:
  • header('Content-type: text/html; charset=UTF-8');

session start failed

If you get an error like:

Warning: session_start() [function.session-start]: open(/home/.../tmp/sess_..., O_RDWR) failed: No such file or directory
  • Look like the server can't write to /home/.../tmp/
    • so either it used to be able to, or it used to write to some other path
    • ssh in, and see what the permissions for /home/tantek/tmp
  • Or it's possible the session.save_path configuration changed. http://us2.php.net/manual/en/function.session-save-path.php

Possible resolutions:

  • If your webhosting is a shared server
    • start a ticket with your hosting provider, OR
    • add this code to your PHP application somewhere before session access:
      if (!is_dir(ini_get('session.save_path'))) {
      mkdir(ini_get('session.save_path'), 0700, true);
      }
      • This code auto-creates the PHP session storage directory if it doesn't already exist (inspired by the mkdir suggestion at [1], but tightened up with a conditional and tighter perms)
      • You may (should) consider providing additional error handling if the mkdir fails, and at some point provide the user an error message describing the error in enough detail that they can either file a support ticket with their webhosting provider, or ask a specific question in an appropriate community.
    • 2014-08-07 Tantek Çelik: These steps worked for me this past week using Falcon on shared webhosting. If Please only edit these instructions if you are documenting how you actually solved a problem firsthand, not how it might or should be possible.
    • OR write a completely different non-filesystem method of session handling.
  • If this is on your local dev setup (e.g. yourdomain.dev on your laptop)
    • check your local dev php.ini to make sure it is setting session.save_path, if not fix it.
      • don't know where is your local dev php.ini?
        • create a file like phpinfo.php on your local dev setup with:
          <!doctype html><meta charset=utf-8><title>php info</title><?php phpinfo();?>
        • go access that phpinfo.php e.g. if you put it in a test directory: yourdomain.dev/test/phpinfo.php
        • look for "Loaded Configuration File:" and it will tell you where is your local dev php.ini,
      • don't have a local dev php.ini? if you see: "Loaded Configuration File: (none)" then you need to make one
        • look for "Configuration File (php.ini) path" in that same output from above.
        • go to that directory and look for a php.ini.default file
        • copy it to php.ini e.g. with
          cp php.ini.default php.ini
        • if you get an error like
          cp: /etc/php.ini: Permission denied
          then you need to use sudo:
          sudo cp php.ini.default php.ini
      • restart your local dev setup Apache, e.g. in a terminal window on your local dev machine:
        sudo apachectl -k graceful</blockquot>
      • if you see an error/warning like:
        httpd: Could not reliably determine the server's fully qualified domain name
        ignore it. Your local dev setup should work now.
      • if you instead (or also) saw an error like:
        httpd not running, trying to start
        (13)Permission denied: make_sock: could not bind to address [::]:80
        (13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
        no listening sockets available, shutting down
        Unable to open logs
        then you forgot to use sudo. Try again with the exact sudo apachectl -k graceful command above.
    • 2014-08-07 Tantek Çelik: These steps worked for me this past week using a Macbook Air running OSX 10.7 and default Apache/PHP. Please only edit these instructions if you are documenting how you actually solved a problem firsthand, not how it might or should be possible.
  • Hopefully that fixes the "Warning: session_start()" error. If not, please ask in IRC and document further description/details below this item.

See Also