ramar.work

Getting Started With Laravel

Just started playing with Laravel after a long time of not really touching PHP. To get it running wasn’t as straight-forward as I hoped, so I’ve written a little set of instructions to help me remember how to get it going in the future. This little guide is only for Cygwin right now, as I have yet to do this on a real Unix box.

If you have not already done so, download apt-cyg. It’s an indispensable tool for your Cygwin toolkit and makes life much easier. The script is located on Github, and you probably won’t find a package for it when running setup.exe. However, it is a quick and easy install via the command-line. You can copy and paste the following into your terminal:

lynx -source rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg
install apt-cyg /bin

You’ll also want to upgrade Cygwin so you have the newest versions of all software. You will need to run setup.exe for this, unfortunately, but newer versions of Cygwin highlight all that you need to get current.

Laravel needs a fair bit to get running on a vanilla system. As stated on the website, a basic installation of Laravel depends on Composer, OpenSSL, PDO, MBString, Tokenizer and XML . Composer is used to manage the project’s dependencies, but if you have not done this in a while, you’ll find that there are more packages than you bargainzed for.

To PHP set up the way we need it, try the following:

apt-cyg install php php-mbstring, php-pdo_*, php_iconv, php-tokenizer, php-xmlreader, php-xmlwriter, php-zlib, php-zip

That should handle all of the dependencies needed to make Laravel not complain.

The next step is Composer. I must say, this could probably be much cleaner and I’m not sure why a simple shell script is not shipped with this tool. Anyway, the commands to get it running are something like:

#!/bin/sh
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")

if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
    >&2 echo 'ERROR: Invalid installer signature'
    rm composer-setup.php
    exit 1
fi

php composer-setup.php --quiet
RESULT=$?
rm composer-setup.php
exit $RESULT

Per Composer’s site, these commands will always give you the newest version. If you do run into any errors, however, visit Composer’s website for the most up-to-date instructions.

Now, Cygwin still has another step to get rolling. The Composer setup script does not install a copy of Composer globally. So you will have to roll your own link.

[ -f composer.phar ] && { mv composer.phar /usr/local/bin/composer; }
composer global require "laravel/installer"
ln -s $HOME/.composer/vendor/bin/laravel /usr/local/bin/
laravel 2>|grep 'laravel' #Should show output...

So, provided that you were able to get here with no issues, you should have a nice Laravel installation ready to roll. And you too, can roll out some fancy new PHP websites.

Hope this helps!