Steps to add a WordPress Site to an existing VPS

I use to have a hard time configuring a new site under a common VPS. So I decided to document the steps for easy reference in future.
Following are the steps to add a new site “site-name.com” under a new user account “username” on your Linux VPS. This is to note that this works if you have the following web service solution stack (LAMP):
Linux OS : Debian
Web server: Nginx (Not Apache)
Database: MySQL
Application Programming Language: PHP
So here we go:
1. Buy the domain. Call it site-name.com.
2. Set the nameserver of the domain to point to the IP address of your VPS under ‘A’ record which stands for ‘Address’. For reference, there are other kinds of record like ‘CNAME’ and ‘MX’, but you don’t need to set them at this point.
3. Create a new user on VPS by command by following command.

sudo adduser username

This command also creates a new home directory for the user.
4. Create following directory structure under the home directory:

/home/username/www/site-name.com/public_html/

5. Make a testfile index.html with some content under the above directory “public_html“.
6. Create a new nginx .conf file on your VPS to route incoming request from the new domain to a file which you will host somewhere.
So the file /etc/nginx/sites-available should contain a new file, site-name.com.conf with settings configured to point to correct file. In this example it should point to: /home/username/www/site-name.com/public_html/index.html.
7. Add a symlink of the .conf file from sites-available directory in sites-enabled directory. Command will be something like:

sudo ln -s /etc/nginx/sites-available/site-name.com.conf /etc/nginx/sites-enabled/site-name.com.conf

8. Now reload nginx by the following command (you could also use reboot instead of reload, but reload does the work fine):

sudo service nginx reload

9. After this try to open the URL site-name.com in browser. It should display the content of index.html file.

Now if WordPress is to be installed:

10. Download the latest version of WordPress in public_html directory:

wget http://wordpress.org/latest.tar.gz

11. Extract the content of this compressed file:

tar -xzvf latest.tar.gz

12. The content should be dumped to public_html directory.
13. Now create a new database user from phymyadmin page.
14. You don’t need to manually edit the wp-config.php file under public_html directory.
15. Now open the URL site-name from the browser, and it should ask to setup. The wp-config.php file will be setup in this step.
You should now have yourself a nice wordpress site hosted under a new user account under your VPS. Congrats!

4 thoughts on “Steps to add a WordPress Site to an existing VPS

  1. You should mention that these steps are specific for the software bundle you use. Apache is the more common web server out there, not nginx.

  2. Pingback: Vineet Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *