LinuxWizardry
  • Home
  • Tutorials
  • News
  • Ubuntu
  • Centos
  • Tools
No Result
View All Result
LinuxWizardry
  • Home
  • Tutorials
  • News
  • Ubuntu
  • Centos
  • Tools
No Result
View All Result
LinuxWizardry
No Result
View All Result

Setting up Laravel 10 on DDEV on Ubuntu: a Comprehensive Step-by-Step Guide

by Robert Keller
August 6, 2023
in Tutorials
ShareTweetShareShare

DDEV is a fantastic open-source tool that simplifies setting up PHP development environments using Docker. If you’re looking to set up Laravel, one of the most popular PHP frameworks, using DDEV, you've come to the right place. This article will guide you through the process step-by-step, ensuring you have a smooth Laravel development experience.

Prerequisites:

  1. Docker installed and running on your machine.
  2. DDEV command-line tool installed.
  3. Basic knowledge of Laravel and PHP.

1. Creating a New Laravel Project

Before we integrate with DDEV, let's set up a new Laravel project. Open your terminal or command line and run:

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

This command creates a new Laravel project named laravel-ddev.

2. Setting up DDEV for Laravel

Navigate to your project directory:

cd laravel-ddev

Now, configure a new DDEV project:

ddev config

This will prompt you with a series of questions. For most of them, the default values will suffice. When asked for the project type, choose php.

Once that's done, you'll want to adjust the webserver_type and php_version to values that Laravel supports. Update .ddev/config.yaml:

webserver_type: nginx-fpm
php_version: "8.0"

Note: Always cross-check the PHP version with Laravel's documentation to ensure compatibility.

3. Database Configuration

Laravel uses .env for environment-specific configurations. DDEV provides dynamic database credentials, which we can inject into Laravel's configuration. In your .env file, update the database credentials to:

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=db
DB_USERNAME=db
DB_PASSWORD=db

4. Configuring the Web Server for Laravel

Laravel has specific rewrite rules, especially for its public directory. Update the .ddev/nginx-site.conf to properly serve Laravel:

Replace the existing server block with:

server {
    listen 80; 
    server_name _; 
    root /var/www/html/public;

    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

5. Starting DDEV

Start your DDEV environment:

ddev start

Once it's up, you can access your Laravel application via the provided URL, usually something like http://laravel-ddev.ddev.site.

6. Finalizing the Laravel Installation

After starting DDEV, run the following commands to complete your Laravel setup:

  1. Migration (Setting up Laravel's default tables):
ddev exec php artisan migrate
  1. Key Generation (Setting application key):
ddev exec php artisan key:generate

Wrapping Up

You now have a Laravel 9/10 environment running smoothly on DDEV. The setup leverages Docker, which ensures that the application will run consistently across different setups, making it easier for team collaborations.

Remember to periodically check both Laravel's and DDEV's official documentation for updates and best practices. This guide should serve as a solid starting point, but the tech landscape is always shifting. Happy coding!

ShareTweetShareShare
Previous Post

How to Monitor Apache Web Server Load and Statistics in Realtime

Next Post

How to Get Started With HuggingFace and AI on Ubuntu

Next Post
How to Get Started With HuggingFace and AI on Ubuntu

How to Get Started With HuggingFace and AI on Ubuntu

Discussion about this post

Copyright © 2022 LinuxWizardry.com

No Result
View All Result
  • #682 (no title)

Copyright © 2022 LinuxWizardry.com

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In