Please note, this is a STATIC archive of website www.htmlgoodies.com from 16 Nov 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Wednesday, November 16, 2022

How Laravel Speeds Up App Development

Laravel is an open-source PHP framework by Taylor Otwell for creating full-featured web applications. It features a modular packaging system with a dedicated dependency manager, different ways for accessing relational databases, and utilities that aid in application deployment and maintenance, that is oriented toward syntactic sugar. For those of you who are proficient in PHP, Laravel will make your job a lot easier by saving you time compared to developing a website from scratch. As an added bonus, websites built in Laravel are more secure and are resistant to several types of web attacks.

In this tutorial, we will learn two ways to work with Laravel: first, on its own, then within the Laravel Homestead Virtual Machine environment.

Getting Started

Laravel uses Composer for managing dependencies so you’ll have to install it before you install Laravel. During the installation process, Composer will ask you to point it to your PHP executable.

Once Composer is installed, you can check the installation by typing composer at the command prompt. That should bring up the logo, version details, and a list of commands:

composer_check (94K)

Now we’re ready to create our Laravel project. Create a new directory anywhere in your system for your new Laravel project. Then, cd into the parent of the new directory and type the following command there to install Laravel:

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

For example:

C:\Users\blackjacques>mkdir laravel

C:\Users\blackjacques>composer create-project laravel/laravel -- prefer-dist

Composer will download a whole wack of modules and create the following directory structure:

laravel_dir_structure (66K)

And that’s it! Now we can start the Laravel service by executing the following command:

php artisan serve

Point your browser to https://localhost:8000/ to see the default Laravel page:

laravel_page (16K)

Installing Laravel Homestead Components

Laravel has a generally stricter set of server requirements than your typical PHP frameworks and projects. This allows Laravel to do more and make use of cool modern features. That’s why Laravel offers Homestead. It’s a pre-packaged Vagrant box that has all the necessary PHP configurations to use Laravel as well as some additional features. It’s also setup to so you can manage multiple sites and projects from a single virtual machine. Vagrant is a portable virtual software development environment. It’s written in the Ruby language and simplifies software configuration management of virtualizations in order to increase development productivity.

The process for installing Vagrant depends on your particular OS. I will cover Windows 10 here, but you can find instructions for other OSes on the Laravel Homestead site.

  1. First, you need to download and install virtualbox, vagrant, and git bash, in that order. You may need to restart your PC after the installations are complete.
  2. Open git bash in administrator mode and run the following command:
    vagrant box add laravel/homestead
  3. Vagrant will then ask you which virtual box provider you want to use:

    C:\Users\robg>vagrant box add laravel/homestead
    ==> box: Loading metadata for box 'laravel/homestead'
        box: URL: https://vagrantcloud.com/laravel/homestead
    This box can work with multiple providers! The providers that it
    can work with are listed below. Please review the list and choose
    the provider you will be working with.
    
    1) parallels
    2) virtualbox
    3) vmware_desktop
    
    Enter your choice: 2
    

    Now, the laravel/homestead box will be downloaded and added to your Vagrant installation. It will take a few minutes to download the box, depending on your Internet connection speed. Git will keep you updated on its progress:

    ==> box: Adding box 'laravel/homestead' (v6.1.0) for provider: virtualbox
        box: Downloading: https://vagrantcloud.com/laravel/boxes/homestead/versions/6.1.0/providers/virtualbox.box
        box: Progress: 40% (Rate: 552k/s, Estimated time remaining: 0:28:27)
    

    Eventually, like maybe thirty to forty minutes later, the installation will complete:

    ==> box: Adding box 'laravel/homestead' (v6.1.0) for provider: virtualbox
        box: Downloading: https://vagrantcloud.com/laravel/boxes/homestead/versions/6.1.0/providers/virtualbox.box
        box: Progress: 100% (Rate: 479k/s, Estimated time remaining: -- : -- : -- )
    ==> box: Successfully added box 'laravel/homestead' (v6.1.0) for 'virtualbox'!
    
  4. The next step is to clone the Official Laravel Repository onto your computer. You’re going to want to clone it to a location other than where all your projects reside. As you will find out, with Homestead you’re actually mapping all your projects to their folders on your computer. Homestead actually acts as a manager for your all your projects.

    Create a new directory named “homestead” and then navigate to it within the console.

  5. Now we’ll clone the Homestead repository into the current (homestead) folder:

    C:\Users\blackjacques\homestead>git clone https://github.com/laravel/homestead.git .
    Cloning into '.'...
    remote: Counting objects: 2972, done.
    remote: Compressing objects: 100% (12/12), done.
    remote: Total 2972 (delta 9), reused 22 (delta 9), pack-reused 2948
    Receiving objects: 100% (2972/2972), 610.46 KiB | 387.00 KiB/s, done.
    Resolving deltas: 100% (1762/1762), done.
    
  6. Next, we have to create the Homestead.yaml (Ain’t Markup Language) configuration file. This requires the use of a Bash shell. As a Windows user, I would recommend win-bash. It’s a stand-alone bash for Windows that is a port of the famous GNU bash.

    C:\Users\blackjacques>cd homestead
    
    C:\Users\blackjacques\homestead>bash init.sh
    init.sh: [[: command not found
    Homestead initialized!
    

    Although the init.sh shell script produced a “command not found” error, it still gave the “Homestead initialized!” success message. To be on the safe side, you can verify that the Homestead.yaml file was created in the C:\Users\USER_NAME\Homestead folder:

    Homestead.yaml_file (88K)

Conclusion

In this tutorial we learned two ways of working with Laravel: on its own and within the Laravel Homestead Virtual Machine environment. Next time, we’ll configure our laravel/homestead environment and create a new project within it.

Rob Gravelle
Rob Gravelle
Rob Gravelle resides in Ottawa, Canada, and has been an IT guru for over 20 years. In that time, Rob has built systems for intelligence-related organizations such as Canada Border Services and various commercial businesses. In his spare time, Rob has become an accomplished music artist with several CDs and digital releases to his credit.

Popular Articles

Featured