Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

How to Install Drupal with WSL on Windows 11 Step-by-Step Guide

How to Install Drupal with WSL on Windows 11 Step-by-Step Guide

Setting up Drupal on Windows 11 using Windows Subsystem for Linux (WSL) provides a seamless way to develop and test Drupal websites locally without needing a separate Linux machine. This method leverages WSL’s powerful Linux environment directly within Windows, making it easier to run PHP, MySQL, and Apache or Nginx needed for Drupal. Before starting, ensure your Windows 11 system is up to date, and you have administrative privileges to install required features. This guide walks you through installing WSL, setting up a Linux distribution, installing necessary packages, and configuring Drupal for local development.

What You’ll Need

  • Windows 11 PC with administrative privileges
  • Internet connection for downloading packages
  • Basic familiarity with command line interface
  • Optional: a code editor like Visual Studio Code

Step-by-Step

  1. Enable WSL and Virtual Machine Platform:
    • Open PowerShell as Administrator.
    • Run the command: wsl --install. This command enables WSL, installs the latest Ubuntu distribution, and sets WSL 2 as default.
    • If the command is not recognized, manually enable features:
      • Run: dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
      • Run: dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    • Restart your computer when prompted.
  2. Install WSL Linux Distribution:
    • After restart, open Microsoft Store.
    • Search for “Ubuntu” and select Ubuntu 22.04 LTS (or latest stable version).
    • Click “Install” and wait for the download to complete.
    • Launch Ubuntu from the Start menu. Complete initial setup by creating a username and password.
  3. Update and Upgrade Linux Packages:
    • In the Ubuntu terminal, run:
      sudo apt update && sudo apt upgrade -y
  4. Install Apache, PHP, and MySQL:
    • Run:
      sudo apt install apache2 php libapache2-mod-php php-mysql mysql-server -y
    • Start Apache and enable it to launch on boot:
      sudo service apache2 start
      sudo systemctl enable apache2
  5. Configure MySQL:
    • Secure your MySQL installation:
      sudo mysql_secure_installation
    • Create a database and user for Drupal:
      sudo mysql -u root -p
      CREATE DATABASE drupaldb;
      CREATE USER 'drupaluser'@'localhost' IDENTIFIED BY 'your_password';
      GRANT ALL PRIVILEGES ON drupaldb.* TO 'drupaluser'@'localhost';
      FLUSH PRIVILEGES;
      EXIT;
  6. Download and Install Composer:
    • Run:
      php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
      php composer-setup.php
      php -r "unlink('composer-setup.php');"
    • Move Composer to global path:
      sudo mv composer.phar /usr/local/bin/composer
  7. Download Drupal:
    • Navigate to your web root directory, typically /var/www/html:
      cd /var/www/html
    • Download Drupal via Composer:
      composer create-project drupal/recommended-project my_drupal_site
    • Set proper permissions:
      sudo chown -R www-data:www-data my_drupal_site
      sudo chmod -R 755 my_drupal_site
  8. Configure Apache for Drupal:
    • Create a new site configuration file:
      sudo nano /etc/apache2/sites-available/drupal.conf
    • Add the following configuration:
      <VirtualHost *:80>
          ServerName localhost
          DocumentRoot /var/www/html/my_drupal_site/web
          <Directory /var/www/html/my_drupal_site/web>
              AllowOverride All
              Require all granted
          </Directory>
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
      </VirtualHost>
    • Enable the site and rewrite module:
      sudo a2ensite drupal.conf
      sudo a2enmod rewrite
      sudo systemctl restart apache2
  9. Complete Drupal Installation:
    • Open a browser and navigate to http://localhost.
    • Follow the on-screen instructions to select language, verify requirements, and connect to your MySQL database (use the database name, user, and password you created).
    • Finish installing and set up your Drupal site.

Common Mistakes

  • Forgetting to enable required Apache modules like rewrite.
  • Using incorrect file permissions, which can prevent Drupal from running properly.
  • Not securing your MySQL installation, leaving default settings open to vulnerabilities.
  • Skipping the step of updating packages after installing Linux, leading to outdated software.
  • Failing to restart Apache after configuration changes, which prevents new settings from taking effect.

Tips

  • Use a dedicated folder within /var/www/html for your Drupal projects to keep things organized.
  • Install and use a code editor like Visual Studio Code with WSL extension for seamless editing.
  • Regularly update your Linux packages and Drupal core for security and features.
  • Configure a local hosts entry if you want to access your site via a custom domain rather than localhost.
  • Back up your database and files regularly during development.

Troubleshooting

  • Drupal cannot connect to database: Double-check your database credentials, ensure MySQL is running, and that the user has proper privileges.
  • Apache server not serving Drupal: Verify your site configuration file syntax, ensure the site is enabled, and restart Apache.
  • Permissions errors: Ensure web server user (usually www-data) owns the Drupal files and directories.
  • WSL not starting or commands failing: Restart WSL with wsl --shutdown and reopen the terminal.
  • Slow performance or network issues: Allocate more resources to WSL via Windows settings or optimize your network configuration.

Frequently Asked Questions

Can I run Drupal on Windows without WSL?

Yes, but it requires setting up a local web server environment like XAMPP or WAMP, which can be less flexible than WSL for development purposes.

Is WSL 2 necessary for Drupal development?

WSL 2 offers improved performance and full Linux kernel support, making it highly recommended for a smoother Drupal development experience.

How do I access my Drupal site outside of localhost?

Configure your Windows firewall, assign a static IP or use port forwarding, and update your hosts file or DNS settings accordingly.

Can I use PHPMyAdmin with this setup?

Yes, you can install PHPMyAdmin within your WSL environment or access MySQL via command line or other database tools.

How do I update Drupal once installed?

Use Composer within your Drupal project directory to update core and modules: composer update.

What if I encounter errors during installation?

Check the error messages, verify all dependencies are installed, and ensure your configurations are correct. Google specific errors for targeted solutions.

By following these detailed steps, you can set up a robust Drupal development environment on Windows 11 leveraging WSL, combining the flexibility of Linux with the convenience of Windows. Happy developing!

Related

How to Install Drupal with WSL on Windows 11 Step-by-Step Guide
Scroll to top