How to install php-login on Windows 7 / 8
In this tutorial we’ll work through the installation process of “php-login” (a user authentication system, and it’s my project btw) under Windows 7 (which is basically the same as in Windows 8 and 8.1). This tutorial has been created in addition to the official installation tutorial for Ubuntu 12.04 LTS as lots of people develop locally under Windows.
Some things first: PHP applications usually run on linux servers, so it’s very useful and very clean to develop on a linux server. There’s absolutly no need to develop on a real live server (security, costs, remote problems, etc.), instead virtual machines are the way to go: There’s an excellent software called Vagrant, letting you easily setup real linux servers on your local computer within seconds, servers that can exactly represent your production server. Do yourself a favour and start with Vagrant, as this will improve your PHP developer life dramatically! I’ve written some tutorials on that, here: How to setup a professional local server (in a virtual machine) with Vagrant in PHPStorm and How to setup a (or multiple) server/LAMP-stack inside a virtual machine for local development with Vagrant and PuPHPet.
If you still want to develop locally in Windows (which is totally okay, but be aware that a deployment on linux servers later might need additional work) I can recommend using one of the most advanced WAMP (Windows, Apache, MySQL, PHP) / MAMP (MAC OS X, Apache, MySQL, PHP) stacks available: EasyPHP, which will be used in this tutorial. This tool will install Apache, MySQL and PHP in a custom folder without messing up your system and provide a very clean and intuitive interface. There are others, but EasyPHP and AMPPS is my favourites. Make sure to download and install the VC9 version, the VC11 needs additional work to run properly. Also note that other WAMP stacks might have different configs, come with different extensions activated/deactivated or might have other problems.
The following tutorial has been made on a fresh Windows 7 installation to keep things as clean as possible.
1. Download, install and start a WAMP stack
We use EasyPHP in this tutorial. Be cool and don’t mess up your Windows 7 harddrive/partition, it’s useful to install your WAMP stack on a seperate partition. The current version comes with Apache 2.4, MySQL 5.6 and PHP 5.4 by default. Assuming that you have installed EasyPHP in D:\EasyPHP, then your web root folder is D:\EasyPHP\data\localweb ! Go there and delete the files that in in there as we don’t need them (it’s just demo stuff). Start EasyPHP. Note: There’s an EasyPHP icon in your taskbar (right, next to the clock etc, eventually the icon is hidden, then click the little white arrow to show it) that allows access to a lot of functions, configs etc. when right-clicked.
2. Download and extract php-login
Download the .zip from https://github.com/panique/php-login, extract it and move the content of the php-login-master folder into D:\EasyPHP\data\localweb, so that your index.php is directly in D:\EasyPHP\data\localweb.
3. Install Git
Git is needed for Composer, so we simply download and install git. The setup will run automatically. In the “Adjusting your PATH environment” screen, select the “Run git from the Windows Command Promt” option. Leave all other options like they are by default.
4. Install OpenSSL and Microsoft Visual C++ 2008 Redistributable Package (necessary to run Composer on Windows)
It’s annoying, but that’s how it is: To make Composer run under Windows, we need to install an OpenSSL tool. Reason is: Composer uses https to get its stuff, which needs OpenSSL on the machine. And it gets worse: In a naked Windows system OpenSSL will need an additional download of the Microsoft Visual C++ 2008 Redistributable Package (also linked on the OpenSSL page).
5. Edit EasyPHP’s PHP config to activate OpenSSL
Right-click on the EasyPHP taskbar icon, select Configuration -> PHP and uncomment this line.
Save the file. Restart the Apache with right-click on the EasyPHP taskbar and select “Restart”.
6. Install Composer
Download Composer from composer.org and install it. Leave the settings like they are. Composer will automatically detect the php.exe of EasyPHP while installation. If you get a message saying that the openSSL extension is missing, well, then you have made something wrong in step #4 or #5.
7. Run Composer on the project’s root
Open the windows command line (for example via StartMenu, then type “cmd”). Go to the project’s folder via typing the drive letter and then cd’ing to the folder, like
d: cd d:\EasyPHP\data\localweb
and then perform an composer-install that fetches all the necessary dependencies (from composer.json):
which should generate output like this [below] and load all scripts into a newly created vendor folder (like every time you work with Composer).
8. Install a simple mail sending (and receiving) tool
When you use PHP’s mail() function under Windows, nothing will happen. This topic is too complex for such a tutorial, but with smt4dev the mail() function will work perfectly. The tool will send AND receive these sent mails. Perfect for development.
9. Edit .htaccess
Edit .htaccess in the project’s root folder and remove (or comment out) this line
10. Edit the project’s configs
Go to 127.0.0.1/home and move your mouse over the icon next to the word MYSQL on the top. You’ll see a yellow popup showing the database login credentials. Usually it’s “root” as user and “” as the password (= no password). Edit application/config/config.php, change
to (don’t forget the trailing slash)
and change the DB block from
define('DB_HOST', '127.0.0.1'); define('DB_NAME', 'login'); define('DB_USER', 'root'); define('DB_PASS', 'mysql');
to the database credentials given above, in EasyPHP usually
define('DB_HOST', '127.0.0.1'); define('DB_NAME', 'login'); define('DB_USER', 'root'); define('DB_PASS', '');
For a first quick development-installation these settings are totally okay, but you would never use an empty password in real projects.
Note: For development no further config is required. But for a real project you should edit all the email configs, URLs, texts etc. to whatever you need.
11. Create and fill a demo database
Go to 127.0.0.1/home in the browser and open phpMyAdmin there. Click on “import” and import all three SQL statement files from the application/_installation/sql_statements folder.
12. First start
Go to 127.0.0.1 and have a look. It should look like this:
Okay, now create a new user account (on the register tab). You should instantly get a new mail delivered via smtp4dev, which looks like this:
Open the mail (you will need a mail client like Thunderbird, Outlook etc. to view the mail) and click the registration link. You’ll see the account verification screen. Go to the login screen. Log in with the chosen username and password. You’ll see the user’s dashboard page, and its username and avatar on the upper right corner of the viewport.