LEMP Site Setup Script, including SFTP

Setting up a LEMP server on Debian 6 was the first post I ever wrote. The impetus for that post (and this blog) was to chronicle all the steps I took, so that I could go back later and find my answers here, instead of googling them up all over again. After I got that server up and running, I decided to automate the process of setting up a new site. I googled around until I found a shell script that was close to what I needed, then with some more googling I managed to modify it for my needs. This script is very specific to my setup, so I doubt anyone would be able to simply download it and use it, but it should provide the groundwork for someone to craft a similar script, suited to their own server.

Here is what the script does:

  1. Asks for a domain, user and password.
  2. Creates the needed directories.
  3. Builds a simple index page (or downloads WordPress, but more on that later)
  4. Copies my nginx vhost template to the sites-available directory.
  5. Creates the symlink to sites-enabled.
  6. Does a find and replace on the vhost config to insert the correct domain name.
  7. Copies my php pool config template to PHP’s pool.d directory.
  8. Does a find and replace on the pool config to insert the correct domain name and user.
  9. Creates the user. This user will have no home directory and no shell access besides SFTP.
  10. Changes the owner of the public_html directory to the new user.
  11. Restarts Nginx and PHP
  12. Copies my SFTP template to a temp directory, does a find and replace to insert the correct file path and user, then appends the contents of that file to the sshd_config.
  13. Restarts ssh

There are two optional arguments you can pass the script when you execute it. The first is “wp”, which stands for WordPress, and if you pass that argument there are two changes in the execution of the script:

  1. Instead of creating a simple index file, WordPress is downloaded and unpacked.
  2. A WordPress specific vhost config template is used.

The second argument is “i”, which stands for “import”. If I’m importing an existing WordPress site, then I don’t want it to download and unpack a new WordPress installation, but I do still want it to use the WordPress specific vhost template, and that’s what this argument will accomplish.

[note color=”#DDD”]newsite.sh
[/note]
Category(s): Googling for Answers, Linux, Nginx
Tags: , , , , ,

Leave a Reply

Your email address will not be published.

* Copy this password:

* Type or paste password here: