Supercharge Your Development: Setting Up Laravel in Devilbox — A Match Made in Heaven!

Why Laravel and Devilbox are a Perfect Pair

Shishir Kumar
6 min readMay 13, 2024

Laravel is an excellent choice for beginners who want to dive into PHP development and create something exciting right from the start. Its user-friendly approach and inspiration from Ruby on Rails make it a developer favorite. Laravel follows the “convention over configuration” philosophy, which means beginners can focus on building unique features without getting overwhelmed by complex setups. The framework adheres to the MVC architecture pattern, providing a structured and organized way to develop applications.

Laravel comes with Artisan, a command-line interface similar to Ruby on Rails’ Rake or Rail CLI. It simplifies common development tasks and boosts productivity. The framework also includes familiar concepts like migrations, eloquent ORM, routes, controllers, and models, making it easy to transition from Ruby on Rails. With its beginner-friendly nature and powerful features, Laravel is a top choice for both novice and expert developers.

Devilbox, a versatile PHP Docker stack, enhances the Laravel experience. It supports a wide range of technologies, including LEMP, MEAN, Websockets, Node, Python, and Golang. With an automated reverse proxy setup, Devilbox eliminates the need for complex configurations. Once Docker is installed, simply pull the Devilbox repository from GitHub and start your development server with a single command. Devilbox streamlines the setup process, allowing you to focus on building incredible Laravel applications without the hassle of manual configurations.

Prerequisites: Getting Ready for the Setup

To get started with Devilbox, you’ll need to have Docker installed on your operating system. If you haven’t set up Docker yet, don’t worry! Simply follow the link provided to download and install both Docker and Docker Compose. The installation process is straightforward, and it won’t take long. Once you’ve completed the installation, you can verify that everything is working correctly by running a simple command in your terminal. This command will confirm that Docker is up and running, and you’re ready to begin your journey with Devilbox.

docker — vesion command

First, you’ll need to clone the Devilbox repository, which you can find on GitHub. Once you’ve cloned the repository, navigate to the newly created devilbox directory. The next step is to copy the example-env file and rename it to .env. Detailed instructions for these steps can be found on the Devilbox GitHub repository page. By following these simple instructions, you’ll be well on your way to setting up Devilbox and taking advantage of its powerful features.

Step-by-Step Guide to Installing Laravel in Devilbox

Once you’ve successfully installed Devilbox, it’s time to start the containers and get your development environment up and running. Navigate to the devilbox directory and execute the command provided. Keep in mind that the initial run might take a bit longer as it pulls all the necessary images. So, grab a cup of coffee and let the command execute fully. Once it’s done, you’ll have a fully functional Devilbox environment ready for your Laravel projects!

docker compose up -d
docker compose up -d

To install Laravel within your Devilbox environment, ensure that you’re currently in the devilbox directory. From there, you can run the provided command to enter the container.

./shell.sh

However, if you’re using Windows, the command will be slightly different. Don’t worry; we’ve got you covered! Simply use the alternative command provided specifically for Windows users.

shell.bat

Now, let’s create a new directory for your Laravel project. While inside the Devilbox container, you can use the mkdir command followed by the desired directory name. Feel free to choose a name that reflects your project.

mkdir devillaravel
cd devillaravel
laravel new devjobs

Once you’ve created the directory, navigate into it and run the Laravel installer command. This will set the foundation for your new Laravel project, and you’ll be well on your way to building something amazing!

Create a new Laravel application

Congratulations are in order! You’ve successfully installed the Laravel application within the Devilbox environment.

Configuring Laravel for Optimal Performance in Devilbox

To ensure your Laravel application functions seamlessly within the Devilbox environment, there’s one crucial step to remember: symlinking the webroot to the htdocs directory. Here’s how you can do it: First, make sure you’re inside the directory you created earlier for your Laravel project. Once you’re in the right location, simply run the provided command. This command will create a symbolic link between your project’s webroot and the htdocs directory, allowing Devilbox to serve your Laravel application without any issues.

ln -s devjobs/public/ htdocs

Tips and Tricks for Seamless Laravel Development in Devilbox

The next step is to add a DNS record to your hosts file, which can be done by following these instructions. First, copy the line provided from http://localhost/vhosts.php, as this will be added to your hosts file. The process of accessing the hosts file depends on your operating system. If you’re using Linux or Mac, open the terminal and follow the instructions below. You’ll be prompted for your password, so have it ready.

sudo vi /etc/hosts

Once you’re in the hosts file, use the keyboard shortcut Ctrl + V to paste the copied line at the end of the file. Finally, save and exit the file by pressing :wq and then Enter.

Hosts file

Great job! You’ve completed the necessary steps, and now it’s time to see your Laravel application in action. Visit the link (http://devillaravel.dvl.to/), and you’ll be greeted by your newly created Laravel application.

Laravel Application

Troubleshooting Common Issues

Accessing your database through tools like phpMyAdmin is made easy with Devilbox. To get started, visit http://localhost/index.php, where you’ll find links to various tools provided by Devilbox. Click on “Tools” and then select “phpMyAdmin” to launch the database management interface. Here, you can create a new database, with the default user being “root” and no password required. Don’t forget to update your Laravel project’s .env file with these database credentials. Your Laravel project is located inside the “devilbox” directory at “data/www/devillaravel/devjobs/”.

Access phpMyAdmin

To run Laravel’s Artisan commands, it’s important to ensure that you’re inside the Devilbox container. If you encounter any issues running php artisan commands, it’s likely because you’re not within the container. Simply enter the container by following the provided instructions, and you’ll be able to execute Artisan commands successfully.

./shell.sh 
cd devillaravel/
cd devjobs/
php artisan
PHP artisan tool

Supercharging Your Workflow: The Benefits Unveiled

Devilbox provides all the essential tools and utilities you need, neatly organized and readily available, just like a well-stocked toolbox. With Devilbox, you can effortlessly set up your Laravel projects, manage dependencies, and ensure smooth development. Together, Devilbox and Laravel make a dynamic duo, streamlining your development process and empowering you to create exceptional web applications with ease.

Conclusion: Unleash Your Laravel Projects with Devilbox

In today’s fast-paced development landscape, mastering Docker, Devilbox, and Laravel is crucial for any developer aiming for success. Laravel stands out for its adoption of cutting-edge technologies and frequent updates, ensuring developers stay ahead of the curve. Devilbox complements this by providing a configuration-free environment, allowing developers to focus on learning and utilizing modern tools without the hassle of tedious setups. Embrace these skills, and you’ll be well-equipped to tackle the challenges of modern web development.

--

--