Last active
January 29, 2019 00:39
-
-
Save jgmuchiri/a3e0c6bb5340dad57dc31e3a6bea3f9d to your computer and use it in GitHub Desktop.
A quick way to create a Dev env with WSL as the server for Apache and MySQL
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
#!/bin/bash | |
sudo apt-get update | |
sudo apt-get install apache2 mysql-server php72-cli git | |
sudo service apache2 start | |
sudo service mysql start | |
sudo service php7.2-fpm start | |
#Mailhog -optional | |
git clone https://github.com/mailhog/MailHog.git mailhog | |
git clone https://github.com/mailhog/mhsendmail.git | |
sudo cp mailhog /usr/local/bin/mailhog | |
sudo cp mhsendmail /usr/local/bin/mhsendmail | |
# Create a script that will be run from Windows task scheduler | |
mkdir -p ~/.local/bin/ | |
echo "service apache2 start" >> ~/.local/bin/mydev-env.sh | |
echo "service mysql start" >> ~/.local/bin/mydev-env.sh | |
# add more stuff here to run on startup | |
chmod +x ~/.local/bin/mydev-env.sh | |
ln -s /mnt/c/MyDevDir /var/www/ |
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
## add the following to your .bash_aliases and source it | |
function new-site(){ | |
# Get variables | |
echo Enter Server Name EX. myproject.test | |
read SERVER_NAME | |
echo Enter Document Root /var/www/*myproject* | |
read DOC_ROOT | |
# Paths | |
A2_SITES_AVAILABLE=/etc/apache2/sites-available/ | |
A2_SITES_ENABLED=/etc/apache2/sites-enabled/ | |
WIN_HOSTS=/mnt/c/Windows/System32/Drivers/etc/hosts | |
THE_FILE=$SERVER_NAME.conf | |
# Create the file | |
touch $THE_FILE | |
# add site configuration | |
echo Writing configuration to $THE_FILE... | |
printf "\n<VirtualHost *:80>" >> $THE_FILE | |
printf "\n\tServerName $SERVER_NAME" >> $THE_FILE | |
printf "\n\tServerAlias www.$SERVER_NAME" >> $THE_FILE | |
printf "\n\tDocumentRoot /var/www/$DOC_ROOT" >> $THE_FILE | |
printf "\n\n\tServerAdmin webmaster@localhost" >> $THE_FILE | |
printf "\n\tLogLevel debug" >> $THE_FILE | |
printf "\n\n\tErrorLog ${APACHE_LOG_DIR}/error.log" >> $THE_FILE | |
printf "\n\tCustomLog ${APACHE_LOG_DIR}/access.log combined" >> $THE_FILE | |
printf "\n</VirtualHost>\n" >> $THE_FILE | |
# copy the file to available sites | |
echo Copying config file to available sites... | |
sudo cp $THE_FILE $A2_SITES_AVAILABLE && | |
# move the file to enabled sites | |
echo Moving config file to enabled sites... | |
sudo mv $THE_FILE $A2_SITES_ENABLED | |
# restart Apache server | |
echo Restarting server | |
sudo service apache2 reload | |
# add the site to Windows hosts file | |
echo Adding site to Windows hosts... | |
printf "\n127.0.0.1\t$SERVER_NAME" >> $WIN_HOSTS | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment