Last active
December 4, 2020 21:18
-
-
Save Wowfunhappy/be28b3a05a564ec59bbc814816b14c1f to your computer and use it in GitHub Desktop.
Enable Apache
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 | |
if (( $(echo "${OSTYPE:6} > 13" | bc -l) )) | |
then | |
mkdir ~/Sites ; sudo bash -c "printf '<Directory \"/Users/`whoami`/Sites/\">\n\tAddLanguage en .en\n\tAllowOverride All\n\tOptions Indexes MultiViews FollowSymLinks\n\tRequire all granted\n</Directory>' > /etc/apache2/users/`whoami`.conf ; echo 'AddDefaultCharset utf-8' >> /etc/apache2/httpd.conf ; sed -i '' '/LoadModule userdir_module libexec\/apache2\/mod_userdir.so/s/^#*//g' /etc/apache2/httpd.conf ; sed -i '' '/LoadModule php[0-9]*_module libexec\/apache2\/libphp[0-9]*.so/s/^#*//g' /etc/apache2/httpd.conf ; sed -i '' '/Include \/private\/etc\/apache2\/extra\/httpd-userdir.conf/s/^#*//g' /etc/apache2/httpd.conf ; sed -i '' '/Include \/private\/etc\/apache2\/users\/\*.conf/s/^#*//g' /etc/apache2/extra/httpd-userdir.conf ; apachectl start" | |
elif (( $(echo "${OSTYPE:6} > 10" | bc -l) )) | |
then | |
mkdir ~/Sites ; sudo bash -c "printf '<Directory \"/Users/`whoami`/Sites/\">\n\tAddLanguage en .en\n\tAllowOverride All\n\tOptions Indexes MultiViews FollowSymLinks\n\tOrder allow,deny\n\tAllow from all\n</Directory>' > /etc/apache2/users/`whoami`.conf ; echo 'AddDefaultCharset utf-8' >> /etc/apache2/httpd.conf ; sed -i '' '/LoadModule userdir_module libexec\/apache2\/mod_userdir.so/s/^#*//g' /etc/apache2/httpd.conf ; sed -i '' '/LoadModule php[0-9]*_module libexec\/apache2\/libphp[0-9]*.so/s/^#*//g' /etc/apache2/httpd.conf ; sed -i '' '/Include \/private\/etc\/apache2\/extra\/httpd-userdir.conf/s/^#*//g' /etc/apache2/httpd.conf ; sed -i '' '/Include \/private\/etc\/apache2\/users\/\*.conf/s/^#*//g' /etc/apache2/extra/httpd-userdir.conf ; apachectl start" | |
fi | |
if (( $(echo "${OSTYPE:6} > 10" | bc -l) )) | |
then | |
clear | |
echo '"http://[IP Address]/~Username" will display contents of ~/Sites directory.' | |
echo '"http://[IP Address]" by itself will display contents of /Library/WebServer/Documents.' | |
echo '' | |
echo 'You may wish to symlink /Library/Webserver/Documents to another directory with "sudo ln -s [target directory] /Library/WebServer/Documents/"' | |
echo '' | |
echo 'To disable directory listing, edit /etc/apache2/users/[username].conf, find the "Options" line, and remove the word "Indexes".' Then, reboot your computer. | |
else | |
echo 'This script is unnecessary on your system, and no changes have been made. Enable web sharing in System Preferences.' | |
fi | |
sleep 30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment