WSL LAMP stack script

The following code is aimed to establish a WSL based LAMP environment.

This is instead XAMPP or WAMPP based LAMP environment which doesn't allow Bash.

The script includes a cat heredocument called "AWSM" (Apache Webapp Substrate Maker) that is used to make an Apache conf file for the app, as well as a mySQL user and DB with the same name (you can then run it with your domain as an argument (for example, the domain of the actual site your run in WSL as a test version):

/etc/apache2/sites-available/awsm example-1.com example-2.com example-3.com


I would like to have your opinion on the entire code as I might lack some security there (maybe I must delete OpenSSH, do some other stuff).

apt-get update -y && apt-get upgrade tree zip unzip lamp-server^ phpmyadmin -y
a2enmod mcrypt ; a2enmod mbstring ; a2enmod rewrite ; a2enmod deflate ; a2enmod headers; a2enmod expires

cat <<-AWSM > /etc/apache2/sites-available/awsm
#!/bin/sh
for domain; do
cat <<-EOF > /etc/apache2/sites-available/${domain}.conf <VirtualHost *:80> DocumentRoot "/var/www/html/${domain}"
ServerName "${domain}" <Directory "/var/www/html/${domain}">
Require all granted
</Directory>
ServerAlias www.${domain} </VirtualHost> EOF a2ensite "${domain}"
done
systemctl restart apache2.service
echo "Please enter password for user ${domain}: "; read -s waps mysql -u root -p <<-MYSQL create user "${domain}"@"localhost" identified by "${waps}"; create database${domain};
GRANT ALL PRIVILEGES ON ${domain}.* TO${domain}@localhost;
MYSQL
AWSM
chmod +x /etc/apache2/sites-available/awsm


Update

I should clarify that I don't have XAMPP/WAMP or even individual Apache or PHP on Windows outside of WSL; I aim to have only 1 LAMP stack in my Windows, inside WSL.

Besides having a fully functional WSL LAMP stack on Windows, the end state is to be able to access it from localhost in any Windows browser so I could easily test the sites and access PHPmyadmin locally.

Also, anyone is more than welcome to contribute directly in Github

• Security should probably be addressed on a more security-centric site. The security of what's installed in the windows subsystem for linux (WSL for short) is its own hellish discussion. And as I suggested to you in U&L's chat room, everything in WSL has to go through the Windows firewall and such. You ask about fail2ban - it won't help you since the firewall and blocking controls are at Windows, not Linux. Dec 28, 2017 at 19:26
• Have you tested this? I don't think it can work as you intended. It looks to me that the outermost here-document should be written as cat <<-"AWSM" to have the desired. The way it's currently written, I expect the outermost shell to replace all the \${domain} references embedded in the here-document, which would render the final /etc/apache2/sites-available/awsm script unusable. Have you checked that script is correctly generated? Because I don't see how that's possible. Jan 31, 2018 at 20:26