This post is meant as a helpful guide for setting up laravel 4 on a windows machine with WAMP server installed. The process is a little cumbersome so I wanted to jot down the steps. Hopefully these notes on setting up laravel on local windows dev environment help someone out there on the interwebs… and I’m sure I will refer back to these on occasion.
–edit–
for a list of helpful php artisan commands please refer to the bottom of this page
–end edit–
1.) Enable openSSL in wamp server (allows us to install composer which is step #2)
- From the wamp tray icon hit php > php extensions > php_openSSL (note we also need both php_curl & php_socket enabled for later steps)
- restart wamp server
- navigate to and open (C:\wamp\bin\php\php-5.4.3\php.ini). Search for openssl and remove the comment in front of the line (then save the file)
- now were ready to install composer
2.) Install Composer. On windows you can install composer by downloading this setup file (https://getcomposer.org/Composer-Setup.exe)
- if you did not enable openssl correctly you will get the following error (The openssl extension is missing, which will reduce the security and stability of Composer. If possible you should enable it or recompile php with –with-openssl). If you get this error go back and re-visit ((C:\wamp\bin\php\php-5.4.3\php.ini). openSSL needs to be enabled in this file for composer to install
- now open up the command prompt and navigate to the directory you will store laravel in and install composer. e.x. CD C:\wamp\www\laravel) then type “composer install”. The install will run and provide you feedback on if it was successful or not.
—-helpful note for newer version of wamp server—-
after installing a new version of wamp server you might have an issue using composer (you will have to re-install it and re-setup your environment varialbes to get it to work). Even after that though if your getting the following error when trying to run composer install then the steps below will help: /c/ProgramData/ComposerSetup/bin/composer: line 10: php: command not found
- : Open git bash
- go to your work directory like if you have wamp then c:/wamp/www.
- type “composer” if you can see the composer command list then its installed correctly
- type “composer self-update”.
Once the update runs you will be able to then navigate to your project directory and run “composer install”.
3.) Add PHP to windows environment variables
- start > environment variables for your account > Path > edit (now chose the path variable under “user variables”)
- add (C:\wamp\bin\php\php5.5.12) so full line will look like: (C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\wamp\bin\php\php5.5.12)
4.) Download Sqlite
- choose one of the windows DLL files on this page (http://www.sqlite.org/download.html), either 32bit or 64 bit.
- copy sql lite .dll into C:\wamp\bin\php\php5.5.12\ext
5.) Download gitbash (http://git-scm.com/downloads).
- this is not needed but it is a nicer user interface than the default windows command prompt
- you can navigate to a file, right click > git bash, then command prompt opens up in this directory… no need to cd into the directory manually
6.) Run first local migrations
- make a local database config file in (app\config\local\database.php)
- change the default to sqlite (line 29 ‘default’ => ‘sqlite’,)
- change the directory path to ../storage/database/ (line 51 ‘database’ => __DIR__.’/../../storage/database/production.sqlite’,)
- open git bash in your laravel directory
- run “php artisan migrate” (if having problems using local config run php artisan –env-local migrate)
7.) Run laravel on local environment
- navigate to your laravel directory (either through windows command prompt, or by going to the file right clicking and hitting git bash)
- type “php artisan serve”
- go to http://localhost:8000
Hopefully these notes help someone out there in the interwebs. Getting laravel up and running for the first time can feel like a somewhat daunting task, but the rewards of being able to work on a local environment are definitely worth it…. and a real plus to using sqlite is that you technically don’t even have to start wamp server now to test your local site. Once you have the local config files setup, you can open git bash, run php artisan serve and then artisan takes care of serving your actually website on localhost 8000…. which is pretty neat.
–random helpful notes & commands —
-runing migrations, open git bash in the laravel directory, and run: “php artisan migrate”
-to detect local and production environments edit bootstrap/start.php
$env = $app->detectEnvironment(array(
‘local’ => array(‘homestead’, ‘computer-name’),
‘production’ => array(‘server-name’),
));
//to detect what your server/computer name is locally put this in the top of the starts.php file and navigate to any page
echo gethostname();exit();
-to seed the db run “php artisan db:seed”
- to do seeds and migrations locally run “php artisan –env-local migrate” and or “php artisan –env-local db:seed”
- if getting an error of “cant replicate database seeder” run “composer dump-autoload”