It’s been quite a while since we’ve posted anything about Laravel. We’re strictly hobbyist developers here and in web development it’s almost impossible to keep up with the rate of change unless you’re a full time developer (and even then, it’s not easy). This pace of change of course means trouble not only for small-time developers like us, but also for enterprise users who favour stability over bleeding-edge features.
So the recent announcement is timely, that Laravel 5.1 is the first version to offer long term support (LTS). LTS in this case means two years of bug fixes and three years of security updates (as opposed to six months and one year respectively for other releases). And for us, this means that although our version 4 tutorials quickly became obsolete, our version 5 tutorials should have a chance of remaining relevant for the next three years. So we hope this new series will be useful for you, our readers.
Without further ado, let’s dive in.
Prerequisites
These days there’s a phenomenal number of ways to get up and running with a server – Vagrant, Puppet, Chef, Ansible and so on. For the purposes of this tutorial I’m going to assume the most basic requirements:
- Apache web server (other web servers will work, but we won’t explicitly deal with them)
- Shell access to the server (preferably SSH)
- Root access to install Composer globally (not essential)
- Git must be installed in your environment.
- PHP >= 5.5.9
- OpenSSL PHP Extension (probably compiled in to your PHP installation – check with
phpinfo();
)
- Mbstring PHP Extension
- Tokenizer PHP Extension
Install Composer
Composer is an integral part of Laravel these days. It’s used for managing dependencies – external libraries and the like, used by projects. It is also used to install Laravel. While logged in as root, to make Composer available globally, do:
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin
ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
The official Composer documentation suggests using mv composer.phar composer
, but if you use a symbolic link instead, upgrading Composer is as simple as running curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin
again.
Install Laravel
There are different ways of approaching this, but the approach I prefer (for its simplicity) is as follows. To install Laravel in the directory that will house your web project (e.g. if that’s under /var/www
), enter:
composer create-project laravel/laravel /var/www/new.website.name
There will be a lot of activity in the console as all Laravel’s various components are installed. The new website directory contains a folder “public” and it’s to this you need to direct your web server. So for example, with Apache, create a new configuration file /etc/apache2/sites-available/new.website.name.conf
:
<VirtualHost *:80>
ServerName new.website.name
DocumentRoot "/var/www/new.website.name/public"
<Directory "/var/www/new.website.name/public">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
Again, for Apache, enable the new website (e.g.):
a2ensite new.website.name
If you’re using a control panel (CPanel, Plesk, VirtualMin, etc.) your steps will vary. When you then browse to your new site, you should see something like this:
Configuration
There’s lots you can configure, but here are some basics.
- Make sure the storage and the bootstrap/cache directories are writeable by the web server. E.g.:
chown -R www-data:www-data /var/www/new.website.name/storage
chown -R www-data:www-data /var/www/new.website.name/bootstrap/cache
find /var/www/new.website.name/storage -type f -exec chmod ug+rw {} \;
find /var/www/new.website.name/storage -type d -exec chmod ug+rwx {} \;
find /var/www/new.website.name/bootstrap/cache -type f -exec chmod ug+rw {} \;
find /var/www/new.website.name/bootstrap/cache -type d -exec chmod ug+rwx {} \;
- In config/app.php set your time zone (e.g.):
'timezone' => 'Europe/London',
- And locale (e.g.):
'locale' => 'en_GB',
Pretty straightforward stuff really.