Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # ---------------- USER CONFIGURATION -------------------------------
- # -------------------------------------------------------------------
- # You can set some parameters here.
- # Make sure that these parameters fit your needs.
- # dirbase is where all the virtual hosts will be created.
- # Default value is "/var/www" which is Apache's default document root.
- # Whatever you change it to, do NOT add a slash to the end of this variable!!!
- # If you change it to something else, e.g. "/home", then you must take extra steps
- # to make suexec work with a non-default document root.
- # One simple way to do this is to bind /home to /var/www.
- dirbase="/var/www"
- # dirprefix is a word that will be attached to the front of all directory names.
- # By default, this is left blank. It can be changed to something like "vhost_".
- dirprefix=""
- # dirpattern can be either "username" or "domain".
- # If set to "username", directory names will follow user names, e.g. "example".
- # If set to "domain", directory names will follow domain names, e.g. "example.com".
- dirpattern="username"
- # apacheuser is "www-data" by default.
- # Most Debian-based distros will follow this pattern, but change it if necessary.
- apacheuser="www-data"
- # ---------------- COLLECT INFORMATION ------------------------------------
- # -------------------------------------------------------------------------
- echo "+------------------------------------------------------------------+"
- echo "| Easy Website Creation Tool with NGINX AND PHP-FPM ver. 0.1.1 |"
- echo "+------------------------------------------------------------------+"
- echo -n "Enter domain name (without www): "
- read domn
- echo -n "Enter new user name: "
- read usrn
- # ---------------- CREATE USER & GROUP ------------------------------------
- # -------------------------------------------------------------------------
- # Add user/group and ask for password.
- # If username already exists, exit with error.
- # Group is automatically created in Ubuntu, but let's check just in case.
- useradd $usrn || exit 1
- passwd $usrn
- groupadd -f $usrn
- # Add Apache user to the same group.
- # This allows Apache to read files with 640 permissions.
- usermod -G $usrn -a $apacheuser
- # ---------------- CREATE USER DIRECTORY STRUCTURE ------------------------
- # -------------------------------------------------------------------------
- if [ "$dirpattern" == "username" ]; then
- dirname="$usrn"
- else
- dirname="$domn"
- fi
- dirn="$dirbase/$dirprefix$dirname"
- echo "Creating directory structure at $dirn"
- mkdir $dirn
- #mkdir $dirn/cgi-bin
- #mkdir $dirn/.cgi-bin/php5-fcgi-wrapper
- #mkdir $dirn/conf
- #mkdir $dirn/lib
- mkdir $dirn/logs
- mkdir $dirn/public_html
- #mkdir $dirn/public_html/stats
- #mkdir $dirn/tmp
- # Set user's home directory.
- usermod -d $dirn $usrn
- # ---------------- CREATE CONFIG FILES ------------------------------------
- # -------------------------------------------------------------------------
- echo "Creating FastCGI configuration files"
- # Apache vhost config file
- # I have enabled per vhost server-side includes and indexfiles.
- # Per vhost logging is also enabled. (Also see Webalizer stats below)
- # Change this if you want to use different options.
- cat > /etc/nginx/conf.d/$domn.conf <<- _EOF3_
- server {
- listen 127.0.0.1;
- server_name $domn www.$domn;
- autoindex on;
- access_log /var/www/$domn/logs/access.log;
- error_log /var/www/$domn/logs/error.log;
- location / {
- root /var/www/$domn/public_html;
- index index.php index.html;
- # if (-f $request_filename ) {
- # expires max;
- # break;
- # }
- # if ($request_filename !~ "\.(js|htc|ico|gif|jpg|png|css)$") {
- # rewrite ^(.*) /app.php last;
- # }
- try_files $uri /index.php;
- }
- location ~ \.php$ {
- root /var/www/$domn/public_html;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include /etc/nginx/fastcgi_params;
- }
- }
- _EOF3_
- # Default html placeholder page
- cat > $dirn/public_html/index.php <<- _EOF4_
- <?php phpinfo(); ?>
- _EOF4_
- # ---------------- SET OWNERSHIP AND PERMISSION ---------------------------
- # -------------------------------------------------------------------------
- # Home directory must be owned by user, of course!
- echo "Setting Permissions"
- chown -R $usrn:$usrn $dirn
- # Log directory must be owned by www-data.
- # Otherwise Apache can't write logs to it.
- chown www-data:$usrn $dirn/logs
- touch $dirn/logs/access.log
- touch $dirn/logs/error.log
- # Never use permissions greater than 750 for directories
- # or greater than 640 for files. This also applies to .php files.
- # The only file that needs to be 750 is the FastCGI wrapper.
- # The wrapper & php-cgi executes .php files for you, so
- # .php files don't need to be executable themselves.
- chmod -R 750 $dirn
- chmod 640 $dirn/public_html/index.php
- #chmod 640 $dirn/conf/php.ini
- chmod 640 $dirn/logs/*
- chmod -R 750 $dirn
- # ---------------- RELOAD NGINX AND PHP-FPM WEBSERVER --------------------------------
- # -------------------------------------------------------------------------
- /etc/init.d/nginx restart
- /etc/init.d/php-fpm restart
- echo "Done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement