Windows Subsystem for Linux
The Windows Subsystem for Linux (WSL) lets you run a real Linux distribution on Windows, with its own package manager, shell and services, without managing a separate virtual machine. For Grav development that means you get the same Apache and PHP setup most Linux hosts run, while still using your Windows editor and browser.
For more information visit the Windows Subsystem for Linux documentation.
Installing WSL and Ubuntu
Open PowerShell or Windows Terminal as Administrator and install WSL with Ubuntu 24.04 LTS, which ships PHP 8.3, the minimum Grav 2 needs:
wsl --install -d Ubuntu-24.04
Restart Windows if asked, then open Ubuntu 24.04 from the Start menu and create your Linux username and password. Microsoft's Install WSL guide covers older Windows builds and troubleshooting.
Bring the new distribution up to date:
sudo apt update && sudo apt upgrade -y
Important
Keep your sites inside the Linux filesystem (for example ~/sites), not on the Windows drive under /mnt/c. Files on /mnt/c are reached through a network bridge, which makes every page load noticeably slower and breaks Linux file permissions. Windows tools can still reach your Linux files: type \\wsl$\Ubuntu-24.04\home\<username>\sites in File Explorer, or open the folder in Visual Studio Code with the WSL extension by running code . from the Ubuntu shell.
Installing Apache and PHP
Install Apache, PHP 8.3 and the extensions Grav uses:
sudo apt install -y apache2 libapache2-mod-php8.3 unzip \
php8.3-cli php8.3-curl php8.3-gd php8.3-mbstring php8.3-xml \
php8.3-zip php8.3-intl php8.3-apcu php8.3-sqlite3
Check the PHP version:
php -v
You should get a response similar to this:
PHP 8.3.6 (cli) (built: ...) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies
Enable the Apache modules Grav's .htaccess relies on:
sudo a2enmod rewrite headers
Run Apache as your own user
Apache normally runs as www-data, which cannot write to files in your home folder, so Grav could not write its cache or save content. On a development machine the simplest fix is to run Apache as your own user. Open Apache's environment file:
sudo nano /etc/apache2/envvars
and change these two lines to your Linux username:
export APACHE_RUN_USER=<username>
export APACHE_RUN_GROUP=<username>
Note
Save the file by pressing Ctrl+O, and hit Enter to confirm. Exit with Ctrl+X.
Warning
Only do this on your own development machine. On a public server, keep the web server and your login user separate.
Configure the virtual host
Create a folder for your sites:
mkdir -p ~/sites
Open the Apache default virtual host configuration file:
sudo nano /etc/apache2/sites-available/000-default.conf
Replace its contents with the following, changing <username> to your Linux username:
1<VirtualHost *:80>
2 ServerName localhost
3 DocumentRoot /home/<username>/sites
4
5 <Directory /home/<username>/sites>
6 Options FollowSymLinks
7 AllowOverride All
8 Require all granted
9 </Directory>
10
11 ErrorLog ${APACHE_LOG_DIR}/error.log
12 CustomLog ${APACHE_LOG_DIR}/access.log combined
13</VirtualHost>
AllowOverride All is what lets Grav's bundled .htaccess apply its rewrite and security rules. See the Apache page for more.
New WSL installs run systemd, so Apache can be enabled to start with the distribution, and restarted to pick up the changes:
sudo systemctl enable apache2
sudo systemctl restart apache2
Tip
If systemctl reports that the system has not been booted with systemd, your WSL install is older. Add [boot] and systemd=true to /etc/wsl.conf, run wsl --shutdown from PowerShell, and open Ubuntu again.
Installing Grav
From the Ubuntu shell, download the Grav + Admin package, which bundles Admin Next, and unzip it into your sites folder:
cd ~/sites
wget -O grav-admin.zip https://getgrav.org/download/core/grav-admin/latest
unzip grav-admin.zip
mv grav-admin my-site
rm grav-admin.zip
Open http://localhost/my-site in your Windows browser. WSL forwards localhost to Linux, so you will land on the admin's setup page, where you create your administrator account.
For other installation options, visit Grav's Installation documentation.
Installing Xdebug (optional)
If you develop your own plugins and themes, you will want a debugger sooner or later. Install Xdebug:
sudo apt install -y php8.3-xdebug
Open its configuration file:
sudo nano /etc/php/8.3/mods-available/xdebug.ini
And add the following lines below the existing zend_extension line:
xdebug.mode = debug
xdebug.start_with_request = trigger
xdebug.client_port = 9003
Restart Apache:
sudo systemctl restart apache2
Activating the debugger
With start_with_request = trigger, Xdebug only starts a session when the request carries the XDEBUG_TRIGGER (or XDEBUG_SESSION) cookie, query parameter or header, so normal browsing stays fast. A browser extension sets the cookie with one click; Xdebug keeps a list of helper extensions for each browser.
Toggle Debug in the extension to switch debugging on or off for a site.
Debugging in Visual Studio Code (optional)
Open your site folder with the WSL extension (code ~/sites/my-site from the Ubuntu shell), install the PHP Debug extension when VS Code offers it inside WSL, and add this launch configuration to .vscode/launch.json:
1{
2 "name": "Listen for Xdebug",
3 "type": "php",
4 "request": "launch",
5 "port": 9003
6}
Because VS Code and PHP both run inside WSL, the file paths match and no path mappings are needed.
Adding extra virtual hosts (optional)
During the different stages in the lifecycle of your site (development, testing, production) you may want different Grav configurations, for example caching or asset pipelines switched off during development and on when testing performance. Grav picks the configuration from the host name; see Environment Configuration for how it works.
-
Start an editor as Administrator and open the file
C:\Windows\System32\drivers\etc\hosts. You could, for example, add the following hosts:TXT127.0.0.1 my-site-dev 127.0.0.1 my-site-prod -
Create a virtual host config file for each in
/etc/apache2/sites-available:BASHsudo nano /etc/apache2/sites-available/my-site-dev.confPaste the following into the editor, changing
<username>to your Linux username:APACHE1<VirtualHost *:80> 2 ServerName my-site-dev 3 DocumentRoot /home/<username>/sites/my-site 4 5 <Directory /home/<username>/sites/my-site> 6 Options FollowSymLinks 7 AllowOverride All 8 Require all granted 9 </Directory> 10 11 ErrorLog ${APACHE_LOG_DIR}/error.log 12 CustomLog ${APACHE_LOG_DIR}/access.log combined 13</VirtualHost> 14
Repeat this for my-site-prod.conf with ServerName my-site-prod, then enable the new virtual hosts:
sudo a2ensite my-site-dev my-site-prod
sudo systemctl reload apache2
Now http://my-site-dev opens the Grav site in ~/sites/my-site using the configuration in user/env/my-site-dev/config/.
Tips and Tricks
Windows Terminal
Windows Terminal gives you tabs, proper copy and paste, and a profile for each WSL distribution. It is the default terminal on Windows 11.
Multiple websites, one Grav codebase
If you have multiple Grav sites for separate projects, read the documentation on Symbolic Links and on Copying a Project to create a symlinked copy of a single Grav core.