Last active
August 11, 2020 21:08
-
-
Save fischgeek/d11ffe6a235bf148df2a5ba8fe470498 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WSL Configuration | |
## Update Ubuntu components: | |
Update and upgrade system | |
sudo apt-get update && sudo apt-get upgrade | |
Install LAMP stack (note the caret) | |
sudo apt-get lamp-server^ | |
Start apache. Windows will complain about opening network access. | |
You can just cancel to restrict it to the local machine, since we will restrict it in the vhost anyway | |
sudo apache2ctl start | |
Visit http://127.0.0.1 in a browser. | |
You should get the Apache2 Ubuntu Default Page. | |
We may need to fix the bad WSL default permission scheme. | |
Files get mounted/created read-write and executable for everyone. No good, especially for git. See https://www.turek.dev/post/fix-wsl-file-permissions/ for more info. | |
Make changes using the Nano editor (if the file doesn't exist, create it) | |
sudo nano /etc/wsl.conf | |
Add the following | |
[automount] | |
enabled = true options = "metadata,umask=22,fmask=11" | |
Save & exit | |
nano ~/.profile | |
Add after #umask 022 | |
if [[ "$(umask)" = "0000" ]]; then umask 0022 fi | |
We also want to run drush without needing its path from the project root directory. | |
Add this line to the end of the file | |
alias drush="./vendor/bin/drush" | |
Save & exit | |
Personally I hate the color prompt, and I like to see a full current path in the prompt. You may disagree, but if you want to change it | |
nano ~/.bashrc | |
Comment out the 3 lines after `# set a fancy prompt` To kill the color. Then in each of the the 3 lines further on that begin with `PS1=`, replace `\w` with `\$PWD` to display a full path in the prompt. | |
Save & exit | |
Close and reopen Ubuntu console to have these take effect. | |
Install some tools | |
sudo apt update && sudo apt install wget php-cli php-zip curl | |
Download and install composer | |
curl -sS https://getcomposer.org/installer -o composer-setup.php | |
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer | |
rm composer-setup.php | |
Check things are installed | |
php -v | |
composer --version | |
rsync --version | |
git --version | |
Create a new ssh key without passphrase | |
ssh-keygen | |
cat ~/.ssh/id_rsa.pub | |
Copy the key as displayed on screen and add it to your github account. Name it "Desktop WSL" or such to identify it. | |
Add an apache virtual host file. Note this is a system file so needs admin privileges to edit (sudo). | |
sudo nano /etc/apache2/sites-available/yoursitename.test.conf | |
``` | |
<VirtualHost \*:80> | |
DocumentRoot "/home/yourusername/sites/yoursitename/web" | |
ServerName painedpolitics.test | |
ServerAlias painedpolitics.test | |
<Directory "/home/yourusername/sites/yoursitename/web"> | |
AllowOverride All | |
Require local | |
</Directory> | |
</VirtualHost> | |
``` | |
Save & exit | |
Create the sites directory we specified in the virtual host and go there | |
mkdir /home/yourusername/sites | |
cd /home/yourusername/sites | |
Build the project directory and add drush | |
composer create-project drupal/recommended-project yoursitename | |
cd yoursitename | |
composer require drush/drush | |
If that fails, we need some extra php extensions installed | |
sudo apt-get install unzip php-gd php-mbstring php-dom php-curl php-simplexml | |
composer install | |
Enable the apache vhost we added, and disable the default host. | |
sudo a2ensite yoursitename.test.conf | |
sudo a2dissite 000-default.conf | |
By default, apache doesn't allow access outside of /var/www. | |
But we have put our Drupal projects under /home/yourusername/sites. | |
Add a directory entry in apache conf to allow this, below the existing one for `/var/www` | |
sudo nano /etc/apache2/apache2.conf | |
``` | |
<Directory /home/yourusername/sites/> | |
Options Indexes FollowSymLinks | |
AllowOverride None | |
Require local | |
</Directory> | |
``` | |
Save & exit | |
We will also need apache rewrite module for Drupal clean urls | |
sudo a2enmod rewrite | |
We want apache to run as your local user, not www-data, so drush syncing files doesn't run into permission issues because the command line user is not the same as the apache/php (drupal) user that wrote the files. | |
This is safe enough on dev. Staging and prod will use more robust mechanisms. | |
sudo nano /etc/apache2/envvars | |
Change to the following | |
export APACHE_RUN_USER=yourusername | |
export APACHE_RUN_GROUP=yourusername | |
Save & exit | |
Check the windows hosts file has an explicit entry for localhost and our site. | |
Run notepad as admin, edit C:/Windows/System32/drivers/etc/hosts | |
127.0.0.1 localhost | |
127.0.0.1 test | |
127.0.0.1 yoursitename.test | |
Restart Windows. | |
We need this to ensure the Ubuntu system gets a full clean boot for the apache user change to work. Reopen the Ubuntu terminal and start Apache and MySQL | |
sudo apache2ctl start | |
sudo service mysql start | |
Create our mysql DB/user via sudo/root | |
"Enter [username]'s password" if asked is your user password for sudo | |
"Enter password" is mysql root user, just hit enter | |
sudo mysql -u root -p | |
mysql> create database dev_d8_yoursitename1; | |
mysql> grant all privileges on dev_d8_yoursitename1.\* to yoursitename@localhost identified by '678533f927tdq098703hgf'; | |
> mysql exit; | |
We should be ready to install Drupal. I prefer to use drush from the project root | |
drush site:install | |
Or you can just visit http://yoursitename.test in a browser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment