Install DDEV on WSL
January 24, 2025 · AI Conversations
—
### **Step 1: Ensure WSL and Docker are Installed**
1. Install **WSL 2**:
– Open PowerShell (as Administrator) and run:
wsl --install
– Restart your system if prompted.
– Verify WSL installation:
wsl --list --verbose
– Ensure WSL 2 is the default version.
2. Install a Linux distribution:
– From the Microsoft Store, install a distribution like **Ubuntu**.
– Launch the distribution and complete the setup.
3. Install Docker Desktop:
– [Download Docker Desktop for Windows](https://www.docker.com/products/docker-desktop/).
– During installation, ensure **"Enable WSL 2 features"** is checked.
– After installation, go to Docker Desktop > Settings > **Resources > WSL Integration** and enable Docker for your WSL distribution.
—
### **Step 2: Install DDEV**
1. Open your WSL terminal (e.g., Ubuntu) and run the following commands:
2. **Install Homebrew (Optional, but recommended)**:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
After installation, add Homebrew to your path:
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
3. **Install DDEV**:
Using Homebrew:
brew install ddev/ddev/ddev
Or directly using the installation script:
curl -fsSL https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh | bash
4. **Verify the installation**:
ddev --version
—
### **Step 3: Test DDEV with Docker**
1. Make sure Docker Desktop is running.
2. In your WSL terminal, create a test DDEV project:
mkdir my-ddev-project
cd my-ddev-project
ddev config --project-type=php --docroot=public --create-docroot
ddev start
3. Access the project in your browser by navigating to the provided URL (usually `http://my-ddev-project.ddev.site`).
—
### **Step 4: Optional Configuration**
– **Enable WSL Integration in Docker**:
Ensure that Docker Desktop > Settings > **Resources > WSL Integration** includes your WSL distribution.
– **Use a global `.ddev` folder** (optional):
mkdir ~/.ddev
cp -r .ddev ~/.ddev
That's it! 🎉 DDEV is now installed and running in WSL. Let me know if you run into any issues!
—
### **Step 1: Ensure Prerequisites**
1. **WSL and Docker**:
– Ensure WSL 2 is installed and set up on your system.
– Install Docker Desktop and enable **WSL 2 integration** for your WSL distribution (e.g., Ubuntu).
Verify Docker is working in WSL:
docker --version
—
### **Step 2: Install DDEV**
#### **Option 1: Use the Official Installation Script**
1. Run the installation script in your WSL terminal:
curl -fsSL https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh | bash
2. Verify the installation:
ddev --version
#### **Option 2: Manually Install the DDEV Binary**
1. **Download the DDEV binary**:
– Find the latest release on the [DDEV GitHub releases page](https://github.com/drud/ddev/releases).
– Use `wget` to download the binary for Linux. Replace `vX.Y.Z` with the latest version (e.g., `v1.23.3`):
wget https://github.com/drud/ddev/releases/download/vX.Y.Z/ddev_linux.vX.Y.Z.tar.gz
2. **Extract the binary**:
tar -xvzf ddev_linux.vX.Y.Z.tar.gz
3. **Move the binary to a directory in your PATH**:
sudo mv ddev /usr/local/bin/
4. Verify the installation:
ddev --version
—
### **Step 3: Test the Installation**
1. Create a new DDEV project:
mkdir my-ddev-project
cd my-ddev-project
ddev config --project-type=php --docroot=public --create-docroot
ddev start
2. Access the project in your browser:
– DDEV will provide the URL (e.g., `http://my-ddev-project.ddev.site`).
—
### **Step 4: Optional Configuration**
– **Enable WSL Docker Integration**:
Ensure Docker Desktop > Settings > **Resources > WSL Integration** includes your WSL distribution.
—
This method avoids using Homebrew entirely. Let me know if you need further clarification! 😊
—
### **Step 1: Ensure mkcert Certificates Are Trusted in WSL**
1. Inside WSL, verify that `mkcert` is installed:
mkcert --version
2. If you haven't created a local CA (Certificate Authority) yet, do so:
mkcert -install
This installs the `mkcert` root CA in WSL's trusted certificate store.
—
### **Step 2: Export the Root Certificate to Windows**
1. Locate the root certificate created by `mkcert` in WSL. By default, it’s stored at:
~/.local/share/mkcert
2. Copy the root CA file to a location accessible by Windows. For example:
cp ~/.local/share/mkcert/rootCA.pem /mnt/c/Users/<Your-Windows-Username>/Downloads/
—
### **Step 3: Trust the Certificate in Windows**
1. Open the **Certificate Manager** in Windows:
– Press `Win + R`, type `certmgr.msc`, and hit Enter.
2. Import the root CA certificate:
– In the Certificate Manager, navigate to **Trusted Root Certification Authorities** > **Certificates**.
– Right-click, select **All Tasks > Import**, and follow the prompts:
– Browse to the `rootCA.pem` file you copied to Windows.
– Make sure it’s imported into the **Trusted Root Certification Authorities** store.
—
### **Step 4: Verify in Chrome**
1. Restart Chrome and try accessing a site served via `mkcert` (e.g., `https://your-local-domain`).
2. If Chrome still doesn’t trust the certificate:
– Open Chrome and navigate to `chrome://settings/security`.
– Ensure **Use secure DNS** is disabled (it can override local certificates).
—
### **Step 5: Additional Debugging**
– If you are using Docker in WSL and running your site through it:
– Make sure the `.crt` and `.key` files generated by `mkcert` are correctly configured in your web server (e.g., Nginx or Apache).
– Ensure your browser is connecting to the correct local domain.
—
### **Tips**
– To simplify certificate management across environments, you can install `mkcert` in both WSL and Windows, and share the same root CA file between them.
– If you often develop in WSL, consider creating a script to sync certificates between WSL and Windows.
Let me know if you encounter any issues! 😊
—
### **Step 1: Verify the Certificate Installation**
1. **Ensure `mkcert` root CA is properly installed on Windows:**
– Open the **Certificate Manager** on Windows (`certmgr.msc`).
– Navigate to **Trusted Root Certification Authorities** > **Certificates**.
– Look for a certificate named something like `mkcert development CA` or similar.
2. **Reinstall the root certificate in Windows:**
– If the certificate is missing or seems incorrect, re-export it from WSL and re-import it into Windows.
– Use the commands:
cp ~/.local/share/mkcert/rootCA.pem /mnt/c/Users/<Your-Windows-Username>/Downloads/
Then, re-import it in the Certificate Manager.
—
### **Step 2: Confirm Certificate Usage**
1. **Generate a certificate for your local domain:**
Inside WSL, generate a certificate for your local development domain (e.g., `example.test`):
mkcert example.test
This will create `example.test.pem` (certificate) and `example.test-key.pem` (private key).
2. **Configure the web server to use these certificates:**
– For **Nginx**:
server {
listen 443 ssl;
server_name example.test;
ssl_certificate /path/to/example.test.pem;
ssl_certificate_key /path/to/example.test-key.pem;
root /path/to/your/project;
index index.html;
}
– For **Apache**:
<VirtualHost *:443>
ServerName example.test
SSLEngine on
SSLCertificateFile "/path/to/example.test.pem"
SSLCertificateKeyFile "/path/to/example.test-key.pem"
DocumentRoot "/path/to/your/project"
</VirtualHost>
3. Restart your web server after configuring it.
—
### **Step 3: Clear and Trust in Chrome**
1. **Clear Chrome’s cache:**
– Navigate to `chrome://settings/clearBrowserData`.
– Clear cached images and files.
2. **Disable Chrome’s Secure DNS:**
– Navigate to `chrome://settings/security`.
– Disable **Use Secure DNS**.
3. **Manually trust the certificate in Chrome:**
– Open Chrome and navigate to the HTTPS version of your site (e.g., `https://example.test`).
– If you see an "invalid certificate" error, click **Not Secure** > **Certificate** > **Details** > **Export**.
– Save the certificate as a `.crt` file.
– Import the certificate in the Windows **Certificate Manager** under **Trusted Root Certification Authorities**.
—
### **Step 4: Verify the Domain Name**
Ensure the domain name matches exactly:
– If you generated the certificate for `example.test`, make sure your browser is accessing `https://example.test`.
– If you're using a custom domain, ensure your `hosts` file in Windows and WSL points the domain to `127.0.0.1`:
– In Windows:
127.0.0.1 example.test
Edit the file at `C:WindowsSystem32driversetchosts`.
—
### **Step 5: Additional Debugging**
1. **Check Chrome Flags:**
– Go to `chrome://flags` and ensure `Allow invalid certificates for resources loaded from localhost` is **Enabled**.
2. **Force Chrome to Trust Certificates:**
– Close Chrome completely.
– Reopen it using the following command:
"C:Program FilesGoogleChromeApplicationchrome.exe" --ignore-certificate-errors --unsafely-treat-insecure-origin-as-secure=https://example.test
3. **Verify the Full Certificate Chain:**
– Run the following command in WSL to confirm that the root CA and certificate chain are correct:
openssl s_client -connect example.test:443 -servername example.test
– Look for the `Verify return code: 0 (ok)` line in the output.
—
### **If It Still Doesn’t Work**
If after following these steps the certificate is still invalid:
– Double-check that the root CA and the generated certificate are the same (sometimes multiple installations can conflict).
– Verify that the correct certificate is being served by your web server (not a default or invalid one).
– Test the site in another browser (Firefox, Edge) to isolate the issue to Chrome.
Let me know how it goes or if you need further assistance! 😊
Here’s how you can fix it:
—
### **Step 1: Generate a New Application Key**
Run the following command in your project directory:
php artisan key:generate
This will:
– Generate a new application key.
– Automatically update the `APP_KEY` field in the `.env` file.
You should see output like:
Application key set successfully.
—
### **Step 2: Verify the `.env` File**
Ensure that your `.env` file contains a valid `APP_KEY`. After running the above command, the `.env` file should look something like this:
APP_KEY=base64:your_generated_key_here
If the `APP_KEY` is missing or remains unchanged, it could be due to file permission issues. In that case:
1. Manually copy the key shown in the terminal output.
2. Add or replace the `APP_KEY` line in the `.env` file.
—
### **Step 3: Clear and Cache the Configuration**
After setting the application key, clear and re-cache your configuration:
php artisan config:clear
php artisan config:cache
—
### **Step 4: Ensure `.env` is Loaded**
If the `.env` file is not being loaded properly:
1. Check that the `.env` file exists in the root directory of your project.
2. Verify that the `.env` file is readable by the server.
If you’re in a production environment, double-check that the server user has the correct permissions to access the `.env` file.
—
### **Step 5: Additional Troubleshooting**
1. **Missing `.env` File:**
If the `.env` file is missing, create one by copying the example file:
cp .env.example .env
Then run `php artisan key:generate`.
2. **Docker-Specific Issues:**
If you're running the Laravel application in a Docker container:
– Ensure the `.env` file is included in the build context and accessible inside the container.
– Rebuild the container if necessary:
docker-compose down
docker-compose up --build
3. **Environment Mismatch:**
Check the `APP_ENV` variable in your `.env` file and ensure it’s set to the correct environment (e.g., `local`, `production`).
—
### **Why is APP_KEY Important?**
The `APP_KEY` is critical for the following:
– Encryption and decryption of cookies.
– Secure generation of hashed values.
– Proper functioning of encrypted data in your application.
Without a valid `APP_KEY`, Laravel cannot perform these functions securely.
—
If the problem persists, let me know the specific setup (e.g., Docker, hosting environment) for tailored troubleshooting! 😊