Getting Started

By | 31/10/2019

I need to get out of the ‘it’s easier to do this in rails’ mentality as even setting up the environment I’m thinking ‘I don’t remember it being this fiddly in rails!’ and that’s only installing PHP, Composer, Laravel & Valet!

Actually it wasn’t that bad – install homebrew if you haven’t already… (Oh I’m on a mac by the way) and we’ll then install php, postgresql, mysql (just in case you don’t like postgres and laravel uses it as the default data base also).

$ brew install php
$ brew install postgreql
$ brew install mysql

That should be it to start, then head over to terminal and test they’re all installed and working.

Installing Laravel

Next we need to install laravel, but first we need to install composer. Composer is like npm or I suppose a Gem manager in ruby – it’s effectively a package manager.
Head to the composer site and paste the code directly into your terminal and you’ll be ready to go

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; 
unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"

Now ensure you install it globally by running

$ sudo mv composer.phar /usr/local/bin/composer

Now head to the Laravel Website and use composer to install the laravel framework

$ composer global require laravel/installer

It’s installed globally however you need to add $HOME/.config/composer/vendor/bin to your paths directory. If you’re using bash run

$nano ~/.bash_profile

and paste
export PATH="~/.composer/vendor/bin:$PATH"
at the bottom of the file – ctrl + x and hit y to save.

If you’re using zsh (as I was) this won’t work so you need to nano into your ~/.zshrc file and add
export PATH="$HOME/.composer/vendor/bin:$PATH"
ctrl + x again and restart terminal.
No matter where you are now – you should be able to run

$ laravel new website

and it’ll go off and do it’s magic – and your php Laravel site will be generated!
To see your new site in action cd into the folder and run

$ php artisan serve

This’ll run a local web server and you’ll see your work in its finest glory!

Oh, I have a folder called Workspace with a PHPProjects sub-folder all my php projects will sit in.
I also have RailsProjects, NodeProjects, PythonProjects, RubyProjects & DataScienceProjects – it’s not just PHP that get’s its own folder!

Let’s install valet to save us having to run artisan serve every time!
Head to the terminal and run

$ composer global require laravel/valet --dev 
$ valet install

Then cd into the folder your keeping all your PHP Laravel projects in and run

$ valet park

This registers the director and any sub directories to valet and in the browser you’ll be able to visit website.test and it’ll serve your project… how easy is that. Actually that’s cooler than rails:)