Setting up a VPS to host a website can be real challenge, because there are so many aspects that should be taken into account: Apache, PHP, Perl/cgi, and MySQL. The instructions mentioned in this article will be useful for both WordPress and other websites. You will find out how to prevent some common dangers and improve your skills.
Choose VPS provider
This is the first, and a very important step. Select a reliable VPS provider with consistent customer support. It should provide basic VPS options at affordable prices. As soon as you have signed up for the service and paid, VPS will be implemented immediately, and you will receive your login information with an email letter.
SSH to the VPS
As soon as you get a new VPS system you will need to log in. Use SSH as the user “root” to the provided IP address. Replace ssh root@X.X.X.X with your IP address.
Change the root password
Experts recommend changing your root password as soon as possible. You have default initial password in your email, but it’s not secure until you change it. If you do everything correctly, you will receive a message: “passwd: all authentication tokens updated successfully”.
Update System Packages
Now you can go further and update all basic OS packages before installing Apache or PHP. You can use Yum program for that: this default package manager works for Linux and CentOS. Then install web server (Apache), code interpreters (PHP & Perl/CGI), and Database Server (MySQL) – all that can be done by one command in Yum.
If you need to host only one website, you can store files in /var/www, but there’s no point in wasting the power of VPS. You can simply specify settings of multiple websites on VPS using Apache Virtual Hosts.
Create a user per website and host data for every single website in user’s ‘public_html’ folder within their home folder. This way, files can be easily managed, and you ensure extra security. If one websites appears to be compromised, others won’t suffer. Perform the following steps:
- Create a user called ‘example’, create their ‘public_html’ folder, specify permissions for it.
- Next you need to edit ‘/etc/httpd/conf/httpd.conf’.
- Change the X.X.X.X with your server’s IP address and anywhere you see example.com to your domain name. Don’t forget to alter the home directory paths for your username instead of /home/example/. If you need to host another domain, just add another virtual host section.
- Clear your local DNS cache or wait a bit after changing DNS A record. You will get a default apache webpage in domain. This will be a default page as you have not placed any files in the public_html directory.
MySQL provides a root account separate from the system and a password that you will get. Launch MySQL and ensure it is set to start automatically. Then connect with MySQL server to specify root password. Create a MySQL user and specify user access to the database for every site that will need a database. Change ‘example’ and ‘NEWPASSWORD’ for your username and password (remember it). You will use them when setting up a website.
Additionally, you can enable a firewall on your VPS. IPTables Firewall is available by default on CentOS, but is disabled, so specify firewall rules and enable it. Edit /etc/sysconfig/iptables only when the firewall is stopped. If you haven’t used IPTables before, this file may not exist, so you will need to create it.
Setup WordPress on a VPS
When you have configured Apache and MySQL, it’s time to upload your website in public_html directory. You can do with any CMS you use, for instance, WordPress. Installation guides are the same for most common blogging platforms. First, you will need to download the freshest version of CMS from its website and a SFTP client. Unzip the ‘latest.zip’ and open SFTP client to establish connection between your server and the user created for the website. Change example.com with your website and username.
Select all files in WordPress directory and upload them into the public_html directory. Then open the browser and insert your URL. Follow instructions to finish the setup of WordPress. Now you’re ready to use your website as usually. Repeat these steps for every domain you want to host on the VPS.