Skip to content

TianMeds/Laradock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 

Repository files navigation

Laradock

How to install Laradock to your project

So, right now we’re going to talk about how to install a Laradock or a dockerized Laravel application, but first, what is Laradock?

Laradock

  • Laradock simplifies the process of dockerizing Laravel applications, offering a convenient and efficient solution for developers. Dockerizing your Laravel project with Laradock allows you to encapsulate the entire development environment, making it portable and reproducible across different systems. This guide will walk you through the straightforward process of installing Laradock for your Laravel project. You can Visit Laradock Documentation here

Tools We need

  • Docker
  • Visual Studio Code or any IDE you want
  • Browser
  • Composer Installed
  • PHP Installed

Steps for Installing Laradock

  • Step 1: Create a folder of you want to create your file, so in my case i create a folder structure like this

  •  Folder Structure
  • Step 2: So you should cd to your Backend Folder, so if you are in the Desktop this is how you will do it.

  • cd Main Folder
    cd Backend Folder
    
  • Step 3: Clone Laradock to folder of choice

  • git clone https://github.com/Laradock/laradock.git
    
  • Step 4: Enter the Laradock folder created inside the Backend Folder, so it means that you will cd again after that rename .env.example to .env

  • cp .env.example .env
    
  • Step 5: Change PHP version in .env to 8.2

  • PHP Version ENV
  • Step 6: Run your Docker containers

  • docker-compose up -d nginx mysql phpmyadmin workspace
    
  • Step 7: Enter Workspace container, to run commands like artisan, phpunit

  • docker-compose exec workspace bash
    
  • Step 8: Create the project or the Laravel Application

  • composer create-project laravel/laravel `your-project-name`
    
  • Step 9: Create DB for the project

    • Open phpMyAdmin, localhost:8081
    • server: mysql
    • username: root
    • pass: root
  • Step 10: Create NGINX Configuration for the project

  • Note you can name it all the way you i just make it consistent so not too hard to remember

    1. Open /nginx/sites/
    2. Duplicate laravel.conf.example
    3. Rename the duplicate to `your-project-name`.conf
    4. Change these Lines 18-19
        server_name `your-project-name`; // add that to your machines /etc/hosts
        root /var/www/`your-project-name`/public;
    
  • Step 11: Now after that make sure to go to your /etc/hosts in your Unit for window users you can thru it by

  • C Drive -> Windows -> System32 -> Drivers -> etc -> hosts
    

    Note: Make sure to run the hosts as Administrator

    After that edit the hosts file to like this and then saved it.

    --- hosts file ---
    
    #End of section
    127.0.0.1  `Name it on what you named in the step 10`
    
  • Step 12: Now Laravel Interface should be searchable and seen when you search it, It will be like this when you search it.

  • http://name-you-put-in-hosts-and-step10
    

    This is the output should look or make sure its accessible in short

    Laravel Interface

Issues might encounter

  • First Issue: 404 not found:: Can’t access the static Laravel front-end

  • Ensure that Nginx has the necessary permissions to access the files in your Laravel project. The Nginx process needs to have read permissions for the files and execute permissions for the directories.

    docker-compose exec workspace chmod -R 755 /var/www/your-project-name
    
  • Second Issue: laravel — The stream or file “/storage/logs/laravel.log” could not be opened in append mode: failed to open stream: Permission denied

  • /var/www/`project-name`#  sudo chmod -R ugo+rw storage
    

Notes

  • Rebuilding a container
docker-compose build `container` 
docker-compose build workspace
  • Recreating a container
docker-compose up -d `container`
docker-compose up -d workspace

References

Special Contribution

Special thanks also for John Christian Berbon for this guide