You could earn up to $300 by adding new articles!

Get Started Now

Setup a Laravel 5 Application on Ubuntu 14

Published on: Wed, Apr 15, 2015 at 2:21 am EST

Introduction

Laravel is a mature PHP framework that you can use to flush out ideas very quickly. It has great documentation and is one of the most popular PHP frameworks. In addition to that, Laravel has a strong community backing.

Installation

  1. Create a Vultr startup script named "Laravel-5.0".

    • On the "My Servers" tab, click on "Statup Scripts".
    • Click on the "Add Startup Script" button.
    • Name the startup script "Laravel-5.0".
    • Copy and paste the contents from this GitHub repository into the script section. This script is a slightly modified version of the provisioning used to build Homestead. Homestead is a virtual machine used to develop Laravel apps locally. It is a popular suite that comes with a lot of goodies, including PHP 5.6, Nginx, HHVM, MySQL, PostgreSQL, Redis, Memcache, Beanstalked, and Node.
  2. Deploy an instance of Ubuntu 14.10 x64 with the "Laravel-5.0" script created above. It is preferable to have at least 1GB (1024 MB) of memory.

  3. SSH into the server ssh root@[vultr-instance-ip]. [vultr-instance-ip] is the IP address of the server. You will need to use the password from the Vultr control panel, unless you are using SSH keys.

  4. Install Laravel 5 and setup a test Laravel application.

    PATH="$HOME/.composer/vendor/bin:$PATH"
    composer global require "laravel/installer=~1.1"
    mkdir /apps
    cd /apps
    laravel new testLaravelApp
    cd testLaravelApp
    php -S [vultr-instance-ip]:8000 -t public
    

    Note that we chose to setup the app under an /apps directory, however this can be anywhere of your choosing.

    Navigate to http://[vultr-instance-ip]:8000 and you'll be greeted with a "Laravel 5 welcome screen".

    When you're finished development, hit Ctrl+C in your terminal to stop the PHP server.

  5. Serve your Laravel application with Nginx.

    Open the Nginx default site configuration.

    sudo nano /etc/nginx/sites-available/default
    

    Paste the following content into this file, then save.

    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
    
        root /apps/testLaravelApp/public;
        index index.html index.htm index.php;
    
        # Make site accessible from http://localhost/
        server_name localhost;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        # Pass all .php files onto a php-fpm/php-fcgi server.
        location ~ [^/]\.php(/|$) {
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            if (!-f $document_root$fastcgi_script_name) {
                return 404;
            }
            include fastcgi.conf;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
    }
    

    Update permissions and restart Nginx.

    chown -R www-data:www-data /apps/laravelTestApp
    chmod -R 775 /apps/laravelTestApp
    sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
    sudo service nginx restart
    

    Browse to http://[vultr-instance-ip]. You will be greeted with a "Laravel 5 welcome screen".

Conclusion

Now that you have Laravel setup, consider exploring its framework, or try out its little brother, Lumen. Laravel is mature, expressive, and satisfying to work with.

Want to contribute ?

You could earn up to $300 by adding new articles!

Get started in the SSD Cloud!