May 082013
 

Ever found yourself manually typing in information from one computer to the next, or saving to a text file on a thumb drive, unplugging it (not forgetting to swear at Microsoft Windows for not letting it go “safe removal problems” …), replugging it into the other computer, etc, etc …

Well there’s Apps like Evernote for situations like these. But you do not always want the full-blown extravaganza of note-taking Evernote provides. What about the good old quick & dirty approach?

There is a solution for that. A PHP based script, which can be run on your local Raspberry server.

Installing nginx

Apache is a very heavyweight / bloated webserver compared to nginx. For our purposes (some light PHP without any .htaccess / mod_rewrite magic) nginx will be quite OK.

Install and start nginx:

aptitude install nginx
service nginx start

Installing PHP and acceleration

We will install PHP-FPM, the Fast CGI PHP daemon. Fast CGI is a good choice (much faster than plain old CGI). Stil we will want some additional acceleration – PHP compiles each time a web page is opened, and pages rarely change. By caching the compilation output we can significantly increase the speed and responsiveness. VERY important on the Pi!

apt-get install php5-fpm
apt-get install php5-xcache
service php5-fpm restart

The default installation of PHP-FPM on the Pi will be configured to use Unix sockets, which again is a good thing as it eliminates TCP overhead.

Configuring nginx

You should now configure nginx and tell it to process .php files through the PHP-FPM daemon.

Edit your /etc/nginx/sites-available/default – it should look something like this after you’re finished:

server {
        listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /webroot;
        #/usr/share/nginx/www;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8080;
        #}

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/www;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

Notable entries in this file are:

  • I have changed the web server root to /webroot
    • obviously you need to create this directory and also change the owner to www-data:www-data
  •  index index.php index.html index.htm; –> use index.php first, if it exists
  •  try_files $uri =404; –> attempt to prevent “zero day exploits”
  • fastcgi_pass unix:/var/run/php5-fpm.sock; –> this tells nginx to use a Unix socket. The path is the default one for php5-fpm on Raspbian

Installing the webnotepad

This could be any other PHP application which does not depend upon a database backend. I’m going to make this real quick and rough:

image

This is a preview of the web notepad you are about to install.

Konstruktors html5-notepad

Get it from the above link ( we are using version 0.2) – the demo on that page seems to be down.

Unzip it, mv the folder which is extracted to a meaningful name (we chose “notes”). Inside it, create a folder with some random name (there is no entries folder in the ZIP download, just create a new folder).

Edit sync.php and change the DATA_DIR to the random name you entered, and edit user and password name (if you run out of ideas, try pi / raspberry).

Just use it to jot down notes, and transfer text (i.e. Dropbox links ?) between computers.

Most important: the Raspberry Pi is getting more useful by the day!

  • admin

    Please note that this web / cloud notepad is not compatible with the Opera browser.

Optimization WordPress Plugins & Solutions by W3 EDGE