sudo chmod 777 new-wp-site.sh
./new-wp-site.sh
Last active
March 28, 2020 09:52
-
-
Save trungpv1601/d8117c4f6f3aac271925c1a5445b7338 to your computer and use it in GitHub Desktop.
Bash Script Setup a new Wordpress Site
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 | |
#encoding=utf8 | |
MYSQL_PASSWORD=`date +%s|sha256sum|base64|head -c 32` | |
# Main | |
function main() { | |
echo "-------------------------" | |
echo "Setup a new Wordpress site ;)" | |
echo "-------------------------" | |
echo "Please enter few infomation for a new site: " | |
read -p "Domain: " domain | |
read -p "Email: " email | |
read -p "MYSQL ROOT PASSWORD: " root_password | |
sudo mkdir "/var/www/$domain" | |
sudo chown -R www-data:www-data "/var/www/$domain" | |
sudo chmod -R 755 "/var/www/$domain" | |
cat > "/var/www/$domain/_i.php" <<EOF | |
<?php | |
phpinfo(); | |
EOF | |
cat > "/etc/apache2/sites-available/$domain.conf" <<EOF | |
<VirtualHost *:80> | |
ServerAdmin $email | |
ServerName $domain | |
ServerAlias www.$domain | |
DocumentRoot /var/www/$domain | |
ErrorLog ${APACHE_LOG_DIR}/error.log | |
CustomLog ${APACHE_LOG_DIR}/access.log combined | |
<Directory /var/www/$domain> | |
Options Indexes FollowSymLinks MultiViews | |
AllowOverride All | |
Require all granted | |
</Directory> | |
</VirtualHost> | |
EOF | |
sudo a2ensite "$domain.conf" | |
sudo a2enmod rewrite | |
sudo systemctl restart apache2 | |
sudo apt-get install unzip wget -y | |
cd "/var/www/$domain" | |
wget https://wordpress.org/latest.zip | |
unzip latest.zip | |
cd wordpress/ | |
sudo mv * ../ | |
cd .. | |
sudo rm -R wordpress/ latest.zip | |
sudo chown -R www-data:www-data "/var/www/$domain" | |
sudo chmod -R 755 "/var/www/$domain" | |
database="${domain//./}" | |
mysql -u root -p"$root_password" <<EOF | |
CREATE DATABASE $database; | |
CREATE USER '$database'@'%' IDENTIFIED BY '$MYSQL_PASSWORD'; | |
GRANT ALL PRIVILEGES ON $database.* TO '$database'@'%'; | |
FLUSH PRIVILEGES; | |
EOF | |
echo "-------------------------" | |
echo "DONE ;)" | |
echo "Your Website: http://$domain" | |
echo | |
echo "MYSQL INFO" | |
echo "Database: $database" | |
echo "Username: $database" | |
echo "Password: $MYSQL_PASSWORD" | |
echo "-------------------------" | |
} | |
main | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment