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
git-php-deployment

Extremely simple deployment with PHPloy

Let me ask you a question: How mad do you get when you have to remember which files you edited

Test GZIP compression of your server easily

If you are running servers (which you hopefully do), then Gzip compression should be a topic, as this simple thing

the-php-login-project

How to install php-login-minimal on Ubuntu 12.04 LTS

In this article I’ll show you how to install the minimal version of the php-login.net‘s login script (see the GitHub

phpstorm-8

Ignore .idea folder from git in PHPStorm

By default (?) PHPStorm will create a hidden folder named .idea directly within your project, containing user-specific stuff like chosen

Joshua Davis – my hero of Flash – in two excellent interviews (audio, video)

Joshua Davis is the reason why I’ve started to code. Seriously. Back in the late 90ies, the internet was a

php

Postmodern PHP: appserver.io, a multithreaded application server for PHP, written in PHP

There’s a lot of very interesting stuff going on in the PHP scene right now, I have the feeling this

vagrant

How to copy Vagrant boxes (or duplicate them)

Copy vagrant box & compress it Making a real 1:1 copy of a Vagrant box is really easy ! Simply

Increase your HTML / CSS coding speed with EMMET

Codeninja.com just published a very interesting article about the excellent free code-completion/code-generation tool EMMET, which allows you to create huge

Create a fast, perfect and bootable 1:1 Windows backup (full clone of HDD) for SSD migration

In this article I want to share a super-simple, extremely fast and totally free workflow with you that will create

phpstorm-8

PHPStorm 8 has just been released

The excellent PHP IDE PHPStorm just had a major release these days: Version 8 is out, coming with latest PHP

1/4

Categories

Search

Serious hard-to-fix bug in OAuth and OpenID discovered, lots of major sites affected
hiphop php
[Link] How to set up HipHop, Nginx and Laravel in Ubuntu 12.04 LTS (in a Vagrant box)
php-phalcon-logo
Which PHP-framework to learn in 2014 ? PHALCON, by far the fastest ever!
october cms
[Link] How To Install October CMS on a VPS running Ubuntu 14.04
composer
How to install Composer on Windows 7 / 8 or Ubuntu
phpstorm 7.0 php
How to install GitHub’s, NetBeans’s and Sublime2’s syntax highlighting code colours theme in PHPStorm 6/7
First look on Gitter, the chat for GitHub
battlefield-3-free
Electronic Arts / Origin offers Battlefield 3 for free (limited promo action) !
php
How to install sqlite driver for PHP in Ubuntu & Debian
phpstorm-8
Killer-feature in PHPStorm: Search everywhere
forbes 30 under 30
Need motivation ? Check out these 2 awesome “FORBES 30 under 30” lists (web, UI, games)
sass laravel
Extremely easy SASS in Laravel (with pure PHP)
Frontend Ops Conf 2014 – Sarah Goff-Dupont: Git, Continuous Integration and Making It Pretty (31min video)
O’Reilly’s Programming JavaScript Applications by Eric Elliott for free (Early Access release)
php
“Belt” adds very clever everyday functions to PHP, comes with JavaScript naming styles and eventually solves the needle/haystack problem

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