1. PHP API Lab v2
  2. Lab Setup

Lab Setup

Project Location

You can put the project files anywhere you like. If you are running this lab in a Nutanix Frame environment, the c:developer folder has already been created for you to use.

For those following this lab outside of Nutanix frame, the following commands can be used to setup the project structure.

../../_images/linux_logo_32x32.png
../../_images/osx_logo_32x32.png
mkdir -p ~/developer
cd ~/developer
../../_images/windows_logo_32x32.png
cd %HOMEPATH%
mkdir developer
cd developer

Preprepared Scripts

Many scripts and files throughout this lab have been prepared and stored in our Nutanix Developer Github repository.

Throughout this lab, raw source files will be shown as per the example below:

Note

Raw source file for this section, if required: https://fakeurl.com/FakeFile404.php

In order for this lab to be successful, you will first need to install a base Laravel 6 application.

To complete this step, ensure you have PHP Composer installed and that is functioning correctly. A quick test is to run the following command.

composer --version
../../_images/create_structure_check_composer.png

Now we can install the base application. All dependencies are taken care of during this process.

Note

Make sure your terminal’s current directory is the “developer” directory (see steps above).

  1. From a command prompt, run the following command. Make sure you replace <your_initials> with your actual initials. For example:

    composer create-project --prefer-dist laravel/laravel api-app-lab-v2-<your_initials>
    
    ../../_images/create_app.png
  2. Change to the new application’s folder:

    ../../_images/linux_logo_32x32.png
    ../../_images/osx_logo_32x32.png
    cd ~/developer/api-app-lab-v2-<your initials>
    
    ../../_images/windows_logo_32x32.png

Note

Experienced Laravel developers will recognise that some of the commands below were automatically run during the project creation process. We are running them again purely to make 100% sure all packages are up to date and that our app is ready for use.

  1. Run the following command. This will make sure all required Laravel packages are installed.

    composer update
    
    ../../_images/composer_update.png
  2. Run the following command. This will generate an application key, something that is required for Laravel session management.

    php artisan key:generate
    
  3. Run the following command. The ‘artisan’ commands are provided with Laravel and simplify the creation of models/classes, views (etc) along with many application management features. This command will start a local web server and make your new Laravel application available.

    php artisan serve
    
  4. Test the application by browsing to http://127.0.0.1:8000. If your system already has a service or application listening on port 8000, you can change the port PHP listens on by modifying the command as follows:

    php artisan serve --port=<port>
    

    If you see the Laravel default page, your base application has been installed successfully. The default page, at the time of writing this lab, looks as follows:

    ../../_images/new_app_running.png

You can now continue to the next part of this lab - the app itself.

Back to Top