In order to run this locally you will need the following tools/programs:
- Composer - https://getcomposer.org/download/ (Requires PHP to be installed I recommend using Wamp Server and using PHP7 http://www.wampserver.com/en/ )
- Node / NPM - https://nodejs.org/en/download/
- Cmder - http://cmder.net/ (optional but I highly recommend has git built in, allows for aliases, etc...)
- Git - https://git-scm.com/download/win (not needed if you use cmder as it comes installed)
For php/composer install the following packages globally so they can be used anywhere:
composer global require "phpunit/phpunit"
composer global require "laravel/installer"
composer global require "squizlabs/php_codesniffer=*"
If you are using cmder I highly recommend setting up some aliases that will make your life a lot easier.
{CmderDirectory}\config\user-aliases.cmd
add the following lines:
gs=git status
aa=git add --all
push=git push
pull=git pull --rebase
test=phpunit
testreport=php -c .\php-xdebug.ini C:\Users\{USERNAME}\AppData\Roaming\Composer\vendor\phpunit\phpunit\phpunit --coverage-html ./storage/logs/phpunit
testu=phpunit --testsuite unit
testf=phpunit --testsuite functional
testa=phpunit --testsuite functional
cleandb=php artisan migrate:refresh && php artisan db:seed
cleancode=phpcbf ./
From the project directory you will need to make sure you have all frontend dependencies (npm) as well as backend dependencies (composer). The following commands will need to ran:
composer install
npm install
First you will need to create your local version of your .env
file. This goes in the root directory of the
project code. This allows you to set environment variables without having to worry about what web server you
are using. You can copy the contents of /.env.example
to your /.env
file.
Your the first thing you need to do is set your APP_KEY
. This can be done automatically after you create your
.env
file by running the following command:
php artisan key:generate
Make sure you update your database credentials in your .env
file to connect to your local database server. Set your database as an
empty database then use migrations to create all tables.
To run database migrations simple run the artisan command migrate
from the root directory of the project.
If you want to use seed data run the artisan command db:seed
command from the root directory of the project.
php artisan migrate
php artisan db:seed
You have two options for running a web server locally. You can either run the server from the command line or you can use something like WAMP Server (http://www.wampserver.com/en/). I personally use Wamp Server 64bit with PHP 7.0.
From the project directory you will simply need to run php artisan serve
. By default it will be running on
localhost:8000
, so you should be able to go to http://localhost:8000 in your browser.
First I normally setup a host record for a dev domain name, something like mroc.local
. Open up your
windows host file which can be found at C:/Windows/System32/drivers/etc/hosts
. Add a line that looks
like this:
127.0.0.1 mroc.local
In your wamp directory look for a directory called /alias
, I normally create a vhost in here by creating
a sites.conf
file. Mine looks like this:
<VirtualHost *:80>
ServerName mroc.local
DocumentRoot c:/wamp64/www/mroc/public
</VirtualHost>
Modify your DocumentRoot
if your code is in a different location. After you have added this make sure you
restart apache for it to pick up the new .conf file. After this you should be able to visit http://mroc.local
in your browser.
Our goal is to follow the PSR guides for php code. PSR-1 and PSR-2 are the main PSR rules you should worry about for most code. You can view the guides here http://www.php-fig.org/psr/
Other developers have created tools that can automatically format code to the PSR standards. If you go to
https://github.com/squizlabs/PHP_CodeSniffer you can find instructions on installing phpcs
(PHP CodeSniffer)
and phpcbf
(PHP Code Beautifier and Fixer). phpcs
runs and just lets you know what is wrong with your code,
phpcbf
will actually automatically fix your code so I normally run this. You can find the instructions for
installation on the link above but normally you can just run:
composer global require "squizlabs/php_codesniffer=*"
Once the two scripts are installed you can simply run the following command from the main project directory:
phpcbf ./
There is a phpcs.xml
file in the project directory that allows us to exclude certain directories and also
specify the rules we are following. The file currently has the PSR-1 and PSR-2 rules included.
To keep code clean and well formated please try to remember to run phpcbf
before pushing code up.
I seem to always mix up the cbf
part of the command so I simply add an alias like we do above like so:
cleancode=phpcbf ./