Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Ubuntu - Create a Laravel Project

Steps

Create folder for your project and navigate into it.

PROJECT_NAME="my-project"
mkdir $PROJECT_NAME
cd $PROJECT_NAME

Install composer if you haven't already.

Install Laravel Through Composer

Initialize the project through composer.

composer create-project laravel/laravel . --prefer-dist

That will install the latest version of laravel (which is 5.2.8 at the time of writing this). If you wish to install a specific version of laravel, use:

composer create-project laravel/laravel . 4.2 --prefer-dist

Composer.json File

You should now have the Laravel framework in place. I would recommend taking a look at the composer.json file (below) and adding your own packages under require at this point.

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "fideloper/proxy": "~3.3",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "~6.0",
        "symfony/thanks": "^1.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

Test it Out!

If you have php installed locally, you can try it out immediately by navigating to the public folder and then running the php local webserver like so:

php -S localhost:8080 index.php

Then navigate to localhost:8080 in your browser and you should see this:

The reason for using port 8080 is that it doesn't require admin privileges. If you want, you can use prefix the command above with sudo and use port 80 instead.

Docker

I have created a publicly available dockerized version of Laravel that you can use to quickly get started and deployed if you like.

To run my dockerized version of Laravel, use the following commands:

git clone https://github.com/programster/dockerized-laravel.git
cd dockerized-laravel
composer update
cd docker
bash build.sh

Wait for it to finish building before running the container.

bash run-container.sh

References