Logo
  • PHP
    • HipHop / HHVM
    • Modern PHP
    • PHPStorm
    • LAMP
    • Laravel
    • Composer
    • PDO
  • JavaScript
    • node.js
    • AngularJS
  • CSS
    • SASS
    • “CSS4” (CSS level 4)
  • HTML
  • Git
  • LAMP
  • Vagrant
  • UI / UX
  • Architecture of …
  • Off-Topic
With ♥ from Berlin
August 23, 2013
Chris
Linux, Login, PHP, php-login project
Comments Off on How to install php-login-one-file on Ubuntu 12.04 LTS

How to install php-login-one-file on Ubuntu 12.04 LTS

PreviousNext
the-php-login-project

This tutorial will show you how to install the one-file version of php-login.net‘s login script (see the full GitHub repository here) on a standard Ubuntu server – in a very short and a very detailed way.

THE VERY SHORT TUTORIAL:

If you prefer a short tutorial, do it like this: Copy the content of the php-login-one-file folder to your server’s web root (or whereever you want to have it) and run _install.php (in the _installation folder), which will create a database file in the project’s root folder. Make sure you have PHP 5.3.7+ with SQLite extension and PDO installed (see long tutorial).

 

THE VERY DETAILED TUTORIAL:

THE BASIC REQUIREMENTS:

  1. A server, in this tutorial we’ll use Ubuntu 12.04 LTS as the operation system.
  2. Apache installed on the server.
  3. PHP 5.3.7 or higher installed on the server (this includes PHP 5.4+ and PHP 5.5+). PHP introduced some hashing algorithms (that are used in this script) in version 5.3.7, so you definitely need this. This tutorial will show you how to check your PHP version and how to upgrade PHP.
  4. You should be able to access your server via SSH.
  5. You should know the basics of how a server works, how to login via SSH, how to use the linux command line and how to copy files to your server.

 

THE FURTHER REQUIREMENTS:
Find out which version of PHP your server runs

This script does not use MySQL, but a simple SQLite database file (which is in this case just a file), so we need to make sure that the installed version of PHP is able to handle SQLite:

Create a file called phpinfo.php on your local computer and put the following stuff in there:

<?php
phpinfo();

The function phpinfo(); shows the entire configuration and settings of PHP, so it’s perfect for inspecting and finding out what your installed version of PHP can do and what not. I think it’s a good idea to create such an phpinfo.php on every new server you set up.

Copy the file to your server’s web root folder, usually /var/www/ ! For easily accessing a server via SSH in Windows 7/8 I can recommend WinSCP and Putty. WinSCP let’s you log in via your SSH credentials (username and password OR via SSH key file) and look at your server like in a FTP tool while Putty is a simple, but effective command-line tool. WinSCP will automatically open Putty (already connected to your server) when you log in.

When you have moved the phpinfo.php file to your web root, open your browser and go to

http://www.yourdomain.com/phpinfo.php

You’ll see something like this:

check for correct php version, must be PHP 5.3.7 or higher

Is your PHP version 5.3.7 or higher ? Fine, then let’s go on ! If not, then you are using a very old version of PHP that should be updated instantly.

By the way, you can also find out your installed PHP version by doing this on the linux command line (but we did it the above way to check if your server displays php files correctly ;)

php -v

 

THE FURTHER REQUIREMENTS:
Update the PHP version (if older than 5.3.7)

Updating PHP is a big topic, so let’s do it the quick way. To update PHP, log into your server and do this on the command line (or “shell” or “bash”, whatever you call it):

sudo apt-get update

to let your system (beside some other stuff) check for updateable software, then do this to upgrade PHP:

sudo apt-get --only-upgrade install php5

After this is done, restart the Apache server with:

sudo service apache2 restart

Now check the installed version of PHP with a simple:

php -v

Is it 5.3.7 or higher now ? Perfect ! If not, then you should contact your server provider, hoster etc. and ask for an update or simply get a modern server somewhere else. It’s 2013, ladies, and the 5.3 branch of PHP has officially reached the End of Life, which means no more updates for this branch. Seriously, there is really no good reason to use a 4 year old version of PHP.

 

THE FURTHER REQUIREMENTS:
Install SQLite extension (if not installed)

This version of the login script does not use a MySQL database, it simply creates a little file in a subfolder of your web project. One file for each database table by the way. This kind of database is called SQLite, and PHP needs a special SQLite extension to work with this stuff. To check if the SQLite extension is installed, search for this box on your phpinfo.php output screen:

check for installed PDO SQLite extension in PHP

Does it say sqlite in the right column ? If not, install the PHP SQLite extension with

sudo apt-get install php5-sqlite

(if you have problems, check How to enable SQLite3 for PHP on StackOverflow)

and restart the Apache server (to load the new extension) like this

sudo service apache2 restart

To prove everything is installed correctly, reload your phpinfo.php screen and have a look. It should look like this:

PHP PDO SQLite extension successfully installed

 

THE INSTALLATION PROCESS:
Copy the script to your server

This step is easy: Delete the phpinfo.php from your server (as it is not necessary anymore and will give potential attackers informations about your server) and copy the contents of the php-login-one-file folder to your web root, usually /var/www/.

 

THE INSTALLATION PROCESS:
Making the “database” folder writeable

By default the www folder on your web root path /var/www/ might not be writeable by PHP. Folder/file rights on linux are a huge and complex topic, so we only do it the quick way here, so let’s go to /var/ on the command line by doing

cd /var

and changing the right of the “database” folder with

sudo chown -R www-data:www-data www

By the way, if this does not work, try setting full acess to the folder. Note that 777 is insecure as it gives too much rights on the folder, but for development purposes it’s okay.

sudo chmod 777 www

 

THE INSTALLATION PROCESS:
First run, creating the database

Open your browser and start the installation function inside the script by calling

http://www.yourdomain.com/_installation/_install.php

which will create the user database file within the root folder. The script is now ready to go under your web address:

http://www.yourdomain.com/

Make sure to delete the _install.php file now ! To always have a look into your one-file database simply call _debug.php. Also make sure to delete this file when you are running a real app!

 

IMPORTANT SECURITY NOTICE:

In the default setup the database – which is only a simple users.db file – can be downloaded directly. To prevent this, change the path of your database file! A path that is not accessable by public is perfect. The .htaccess in the project does not work in every setup.

 

SOME FINAL THOUGHTS

Your app is now running. To be honest, this tutorial was a little bit overcomplicated. When you are reading this post you probably want to create a very simple tool, based on a one-file login system, so you probably have rent a simple and pre-configured server that already has a modern version of PHP and the PDO / SQLite extension installed. Usually copying the script files to the server and calling the install script is everything you have to do.

 

SOME WORDS ABOUT LOCAL & REMOTE DEVELOPMENT

It’s always a good decision to develop LOCALLY, which means directly on your own computer, or even better, within a virtual machine hosted on your system. Usually, developing on a live server on the web might be critial, because your tools might have no or weak passwords, your app is in development and therefore attackable, or simply because you just mistyped a bash command and your server now tries to download the entire web. This can kill you if you pay for every gigabyte of traffic. Believe me ;)

When developing locally, you could install PHP, MySQL etc by hand or use a pre-combined and pre-configured easy-to-handle development bundle, like Ampps [Win, Mac], EasyPHP [Win], WampServer [Win], SecureWAMP [Win] or even Xampp [Win, Mac, Linux]. A lot of people seems to use Xampp, but I wouldn’t recommend this, as it’s by far the worst of all those.

 

linuxloginPHPtutorialUbuntu
Share this
harper reed about big data

Harper Reed – The magic and mystery of Big Data (30min video from Webstock’15)

Harper Reed is speaking, so nothing can go wrong. :) The former CTO of Threadless.com and Obama for America definitly

microsoft-windows-azure-cloud-hosting

Microsoft’s Azure platform gives away high money prizes for “testing out” their cloud services

Disclaimer: DEV METAL does not get any money etc. for saying this, there is no affiliate link, no deal with

offf-2014

Europeans: Get ready for OFFF conference / festival in Barcelona, May 2014

Designers and frontend guys, this is for you: If you live or simply are in western Europe in May 2014,

mod-rewrite-ubuntu-14-04-lts

How to enable mod_rewrite in Ubuntu 14.04 LTS

A little note first: This is the most basic way to enable mod_rewrite. However, it’s not the best way. The

sass

New features in SASS 3.3 (a talk by SASS-creator Chris Eppstein)

A very interesting conference talk by Chris Eppstein, creator of SASS itself, showing some of the new features in SASS

phpstorm 7.0 php

How to install GitHub’s, NetBeans’s and Sublime2’s syntax highlighting code colours theme in PHPStorm 6/7

PHPStorm’s default code colouring might not be what you want, especially when you just switched from NetBeans. But there are

Serious hard-to-fix bug in OAuth and OpenID discovered, lots of major sites affected

Just a short notice rather than a real article, full story later (I need to check the facts): Several sources

O’Reilly’s Programming JavaScript Applications by Eric Elliott for free (Early Access release)

O’Reilly currently offers the entire book Programming JavaScript Applications by Eric Elliott for free (as an online-readable version) while its

mod-rewrite-ubuntu-14-04-lts

How to enable mod_rewrite in Ubuntu 12.04 LTS

A little note first: This is the most seen way to enable mod_rewrite in tutorials. However, it’s not the best

hack-php

Facebook releases HipHop (HHVM) 3.0, adds mysqli and support for Hack language

Lots of movement in the PHP world these days! After releasing Hack (a dramatically improved fork of the entire PHP

1/4

Categories

Search

Ghost
[FREE SERVER PROMO] Install GHOST for free on a free SSD server with this coupon
Install MINI in 30 seconds inside Ubuntu 14.04 LTS
angular js
Learn AngularJS in 20 (or 90) minutes with Dan Wahlin
hiphop php
HipHop VM reaches 100% green Unit Tests in Laravel, Drupal, Slim, CodeIgniter etc.
bash-command-line-tutorial
Best introduction to unix command line / bash ever (by André Augusto Costa Santos)
php
A super-simple introduction into PHP namespaces (7min video)
php
PHP 5.6 announced, statically typed (!) “new” PHP announced by Facebook devs
php
How to use the PHP 5.5 password hashing functions
laracon-2014-eu-amsterdam
Laracon 2013 – Kapil Verma: Engineering Complex Applications with Laravel 4 (40min video)
ubuntu-14-04-lts lamp
How to install/setup a basic LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu 12.04 or Debian 7.0/7.1
How to setup a config-free WordPress, PHP and MySQL (for local development) in Windows 7 / 8 in under 3 minutes
symfony-framework-logo
SensioLabs, creator of Symfony and Silex PHP frameworks, gets $7 million capital
Quick fix for 404 error in WordPress category / tag page
github-logo-octocat
GitHub rolls out .PSD diff and viewing
battlefield-3-free
Electronic Arts / Origin offers Battlefield 3 for free (limited promo action) !

Tags

apache bash centos composer conference coupon CSS debian fonts framework git GitHub hack HHVM HipHop HTML HTML5 IDE JavaScript JS LAMP laravel linux mod_rewrite MVC MySQL Nginx optimization PHP PHP 5.5 PHP 5.6 phpmyadmin PHPStorm security server SSD Ubuntu UI UX vagrant video virtual machine voucher VPS wordpress
Side-Project: Wordle-Solver:
www.wordle-helper.info

Pages

  • Privacy Policy