Last active
April 28, 2023 08:37
-
-
Save mattiasghodsian/c39199464726aee86217969c2f48cb5d to your computer and use it in GitHub Desktop.
Auto make site for nginx (localhost only)
This file contains hidden or 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 | |
| ### | |
| # Title: add site (experimental) | |
| # Author: Mattias Ghodsian | |
| # Description: Auto make site for nginx (run with sudo) | |
| # Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian | |
| # Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5 | |
| ### | |
| # args | |
| if [ -n "$1" ]; then | |
| domain=$1 | |
| else | |
| echo "Argument 1 missing!!" | |
| exit 1; | |
| fi | |
| # make folder | |
| if [ ! -d "/srv/www/$domain" ]; then | |
| mkdir /srv/www/$domain | |
| echo -e "Folder created: /srv/www/$domain" | |
| echo "<?php phpinfo(); ?>" > /srv/www/$domain/index.php | |
| echo -e "index.php created: /srv/www/$domain/index.php" | |
| chmod -R 777 /srv/www/$domain/ | |
| fi | |
| # Nginx VH server configuration | |
| cat <<EOT >> /etc/nginx/sites-available/$domain | |
| server { | |
| listen 80; | |
| listen [::]:80; | |
| server_name $domain www.$domain; | |
| root /srv/www/$domain; | |
| index index.php index.html index.htm; | |
| location ~ \.php$ { | |
| include snippets/fastcgi-php.conf; | |
| fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; | |
| } | |
| } | |
| EOT | |
| # Creating symbolic link to the sites-enabled | |
| ln -s /etc/nginx/sites-available/$domain /etc/nginx/sites-enabled/$domain | |
| echo -e "Creating symbolic link for $domain" | |
| # Make sure that there are no syntax errors | |
| nginx -t | |
| # Restart nginx | |
| systemctl restart nginx | |
| # add domain localy | |
| echo "127.0.0.1 $domain www.$domain" >> /etc/hosts | |
| echo -e "$domain added to hosts file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment