Skip to content

Instantly share code, notes, and snippets.

@pixelpylon
Created August 22, 2020 17:55
Show Gist options
  • Save pixelpylon/e8ba33594902fc4a6075ea3967988a6a to your computer and use it in GitHub Desktop.
Save pixelpylon/e8ba33594902fc4a6075ea3967988a6a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
APACHE_USER=wwwhost
VHOSTS_DOMAINS=(example.com second.example.com)
sudo ufw allow in "OpenSSH"
# Install Apache
sudo apt-get update
sudo apt-get install apache2
sudo nano /etc/apache2/apache2.conf # Add ServerName ... directive at bottom
sudo apache2ctl configtest
sudo systemctl restart apache2
sudo ufw allow in "Apache Full"
# Install MySQL
sudo apt-get install mysql-server
sudo mysql_secure_installation
# Install PHP
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
sudo nano /etc/apache2/mods-enabled/dir.conf # Move index.php to start
sudo systemctl restart apache2
# Install Composer
sudo apt-get install curl php-cli git
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
# Secure Apache
sudo adduser $APACHE_USER
sudo nano /etc/apache2/envvars # Update APACHE_RUN_USER & APACHE_RUN_GROUP to '$APACHE_USER'
# Create VirtualHosts
for $DOMAIN in "${VHOSTS_DOMAINS[@]}"
do
sudo mkdir -p /var/www/$DOMAIN/public_html
sudo chown -R $APACHE_USER:$APACHE_USER /var/www/$DOMAIN
then
sudo chmod -R 755 /var/www
for $DOMAIN in "${VHOSTS_DOMAINS[@]}"
do
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/$DOMAIN.conf
# Edit & enable vhost after copying
# sudo nano /etc/apache2/sites-available/$DOMAIN.conf
# sudo a2ensite $DOMAIN.conf
then
sudo a2enmod rewrite
sudo systemctl restart apache2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment