Dev Notes

Software Development Resources by David Egan.

Install Laravel on Ubuntu 16.04 Desktop


Laravel, Sysadmin, Ubuntu
David Egan

This article describes how to get Laravel up and running in a Ubuntu Xenial Xerus development environment.

Minimum requirements for Laravel:

  • PHP >= 5.6.4
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension

These notes describe installing Laravel on PHP 7 with MariaDB and Apache.

Laravel Installer

Use Composer to download the Laravel installer. It will then be available globally:

composer global require "laravel/installer"

This will place the installer in ~/.composer/vendor/laravel/installer/, symlinked in ~/.composer/vendor/bin.

This latter directory shoudl be in your $PATH so that the laravel installer can be located by the system. You may need to add the follwoing to your ~/.bashrc file:

# Add to ~/.bashrc for global access to Laravel installer
export PATH=$HOME/.composer/vendor/bin:$PATH

The Laravel installer calls the Symfony\Component\Console\Application class to work it’s magic.

Installing Laravel

The development site will be located in the Apache docroot - and the installer will install Laravel in the current directory:

cd /var/www/html
laravel new project-name

Accessing http://localhost/project-name/ in a browser will display the app directory structure.

Post-Installation Permissions

Assuming the Apache user is www-data, the following ownership settings need to be applied:

# Move into the new project root
cd /var/www/html/project-name

# Apply ownership
sudo chown -R www-data storage
sudo chown -R www-data bootstrap/cache

The Public Directory

The front controller for Laravel is public/index.php file - this is the file that all requests hit. The public directory will be the document root for the project.

If you’ve set permissions correctly, you should be able to access the new app: http://localhost/project-name/public/

It’s abit cumbersome to use this URL in the development environment. You should instead configure a virtual host directive for a suitable URL, and adjust your /etc/hosts file so that your chosen domain directs to 127.0.0.1 (localhost).

Localhost and the Trailing Slash

There is a “gotcha” if you decide to devlop locally under Apache localhost - adding a trailing slash to the URL http://localhost/your-app/page/ triggers Laravel to redirect to a non-trailing slashed home URL, which will be http://localhost/page rather than http://localhost/your-app/page.

This can be worked around (maybe by means of .htaccess rules) - but it’s probably easier all round to just set up a local Apache virtual host config and amend etc/hosts to point to your localhost for a specified domain.

Post Install Checks

Check the 32 character application key in .env has been set to a random string.


comments powered by Disqus