Created
January 6, 2024 22:01
-
-
Save dmpop/109c552aaea789fd649b01c539a5d7e5 to your computer and use it in GitHub Desktop.
Automate VPS initial setup
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
#!/usr/bin/env bash | |
if [ "$(whoami)" != "root" ]; then | |
echo "You must run this script as root" | |
exit 1 | |
fi | |
apt update | |
apt upgrade | |
apt install apache2 php libapache2-mod-php php-gd \ | |
certbot python3-certbot-apache \ | |
git fail2ban | |
echo "----------------------------------------" | |
echo " Specify new user name (example: monkey)" | |
echo " Press ENTER" | |
echo "----------------------------------------" | |
echo | |
read newuser | |
useradd -m $newuser | |
passwd $newuser | |
apt install sudo | |
usermod -aG sudo $newuser | |
echo "-----------------------------------------" | |
echo " Enter a domain name (example: hello.xyz)" | |
echo " Press ENTER" | |
echo "-----------------------------------------" | |
echo | |
read domain_name | |
touch /etc/apache2/sites-available/$domain_name.conf | |
echo "<VirtualHost *:80>" > /etc/apache2/sites-available/$domain_name.conf | |
echo "" >> /etc/apache2/sites-available/$domain_name.conf | |
echo "DocumentRoot /var/www/html/$domain_name" >> /etc/apache2/sites-available/$domain_name.conf | |
echo "ServerName $domain_name" >> /etc/apache2/sites-available/$domain_name.conf | |
echo "ServerAlias $domain_name" >> /etc/apache2/sites-available/$domain_name.conf | |
echo "" >> /etc/apache2/sites-available/$domain_name.conf | |
echo "<Directory /var/www/html/$domain_name/>" >> /etc/apache2/sites-available/$domain_name.conf | |
echo "Options FollowSymlinks" >> /etc/apache2/sites-available/$domain_name.conf | |
echo "AllowOverride All" >> /etc/apache2/sites-available/$domain_name.conf | |
echo "Require all granted" >> /etc/apache2/sites-available/$domain_name.conf | |
echo "</Directory>" >> /etc/apache2/sites-available/$domain_name.conf | |
echo "" >> /etc/apache2/sites-available/$domain_name.conf | |
echo 'ErrorLog ${APACHE_LOG_DIR}/error.log' >> /etc/apache2/sites-available/$domain_name.conf | |
echo 'CustomLog ${APACHE_LOG_DIR}/access.log combined' >> /etc/apache2/sites-available/$domain_name.conf | |
echo "" >> /etc/apache2/sites-available/$domain_name.conf | |
echo "</VirtualHost>" >> /etc/apache2/sites-available/$domain_name.conf | |
sudo a2dissite 000-default | |
sudo a2ensite $domain_name.conf | |
sudo a2enmod rewrite | |
sudo systemctl restart apache2 | |
sudo certbot --apache | |
sudo mkdir /var/www/html/$domain_name | |
sudo chown www-data:www-data -R /var/www/html/$domain_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment