Last active
April 27, 2018 00:15
-
-
Save BerkhanBerkdemir/65f35c0d8e88703a22bb0992a9727c8e to your computer and use it in GitHub Desktop.
Ubuntu, Nginx and PHP-FPM auto script
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 | |
read -p "Domain: " domain | |
read -p "DB name: " db_name | |
read -p "DB pass: " db_password | |
apt update | |
echo "===================" | |
echo "Nginx installing" | |
echo "===================" | |
apt install -yqq nginx > /dev/null | |
systemctl stop nginx.service | |
systemctl enable nginx.service > /dev/null | |
echo -e """### Created with script at $(date) | |
upstream php { | |
server unix:/run/php/php7.0-fpm.sock; | |
server 127.0.0.1:9000; | |
}""" > /etc/nginx/conf.d/upstream.conf | |
echo -e """### Created with script at $(date) | |
server { | |
## Your website name goes here. | |
#server_name $(echo $domain); | |
## Your only path reference. | |
root /home/$(echo $domain)/public_html; | |
## This should be in your http block and if it is, it's not needed here. | |
index index.php; | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
location / { | |
# This is cool because no php is touched for static content. | |
# include the \"?\$args\" part so non-default permalinks doesn't break when using query string | |
try_files \$uri \$uri/ /index.php?\$args; | |
} | |
location ~ \.php$ { | |
include fastcgi.conf; | |
fastcgi_intercept_errors on; | |
fastcgi_pass php; | |
} | |
location ~* \\.(js|css|png|jpg|jpeg|gif|ico)$ { | |
expires max; | |
log_not_found off; | |
} | |
}""" > /etc/nginx/sites-available/$domain | |
mkdir -p /home/$domain/public_html | |
rm -rf /etc/nginx/sites-enabled/default | |
ln -s /etc/nginx/sites-available/$domain /etc/nginx/sites-enabled/$domain | |
echo "PHP installing" | |
echo "===================" | |
apt install -yqq php-fpm php-mysql php-curl > /dev/null | |
systemctl enable php7.0-fpm.service > /dev/null | |
systemctl start nginx.service | |
echo "MySQL installing" | |
echo "===================" | |
debconf-set-selections <<< "mysql-server mysql-server/root_password password $(echo $db_password)" | |
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $(echo $db_password)" | |
apt-get -y install mysql-server > /dev/null | |
systemctl enable mysql.service > /dev/null | |
echo "DB Initiliaze" | |
echo "===================" | |
echo "CREATE DATABASE $(echo $db_name);" | mysql -u root -p$(echo $db_password) | |
cd /home/$domain | |
wget -q "https://wordpress.org/latest.tar.gz" | |
tar -xf latest.tar.gz | |
rm -rf public_html | |
mv wordpress public_html | |
chown www-data:www-data -R /home | |
chmod 755 -R /home |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment