How to Host a Website on VPS Without Control Panel
Prerequisites
To follow this tutorial, you will need the following requirements:
a VPS
a domain name pointed to your server
Install Web Server
On Ubuntu
apt update
apt install apache2 php-{bcmath,bz2,gd,intl,mcrypt,mbstring,mysql,xml,xmlrpc,zip}
apt install libapache2-mod-php
On CentOS
yum update
yum groupinstall 'Web Server'
yum install apache2 php-{bcmath,bz2,gd,intl,mcrypt,mbstring,mysql,xml,xmlrpc,zip}
Enable Apache at boot then start it now, navigate to your IP address on your web browser, you will see the default page.
On Ubuntu
systemctl enable apache2
systemctl start apache2
On CentOS
systemctl enable httpd
systemctl start httpd
Create Virtual Host
To host only one website on a server, we don’t have to create a virtual host, we can simply make sure that Apache is running and upload our files to /var/www/html and the site will be online at once. But, in this tutorial, we will create a virtual host with domain name domain1.com, please replace it with your actual domain name.
Let’s create a file for the virtual host configuration with the following command:
On CentOS:
nano /etc/httpd/conf.d/domain1.com.conf
On Ubuntu:
nano /etc/apache2/sites-available/domain1.com.conf
Insert the following lines to the configuration file.
<VirtualHost *:80>
ServerAdmin webmaster@domain1.com
ServerName www.domain1.com
ServerAlias domain1.com
DirectoryIndex index.php index.html
DocumentRoot /var/www/html/domain1.com/public_html
LogLevel warn
ErrorLog /var/log/httpd/domain1.com_error.log
CustomLog /var/log/httpd/domain1.com_access.log combined
</VirtualHost>
Since /etc/httpd/conf.d/*.conf files are already included in /etc/httpd/conf/httpd.conf, there is no more step in CentOS
On Ubuntu/Debian, we have to enable the virtual host first by performing this command:
a2ensite domain1.com
Restart apache
On CentOS:
systemctl restart httpd
On Ubuntu:
systemctl restart apache2
Now, let’s create a file in /var/www/html/domain1.com/public_html, don’t forget to replace the domain1.com with your actual domain name.
mkdir -p /var/www/html/domain1.com/public_html
nano /var/www/html/domain1.com/public_html/home.html
Then, insert the following line to the home.html file
<html><center><h1>This is loaded from domain1.com</h></center></html>
Verify the setup
Navigate you domain1.com on your web browser.
Install CMS
Now that you have a simple website running on Let’s continue to another step, install a CMS on your domain.
In this tutorial, we are going to install WordPress, the most popular CMS built on PHP and MySQL.
Download WordPress
To download WordPress, execute the following commands:
wget wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mv wordpress/* .
On Ubuntu:
chown -R apache: /var/www/html/domain1.com/public_html
On CentOS:
chown -R www-data: /var/www/html/domain1.com/public_html
Install MySQL
The official WordPress distribution only supports MySQL and MariaDB database storage engine. We will install MySQL/MariaDB on our server now.
Ubuntu:
apt install mysql-server
CentOS:
yum install mariadb-server
When installing WordPress, a new MySQL database is required with username and password. We will create it using the following details:
username: rose_wpuser
database name: rose_wpdb
database password: DkaYrbfLH4Dubc2B
In this tutorial, we assume that your MySQL root user is not having a password, so you need to invoke “mysql” command to get into MySQL shell
If your MySQL instance is having a password, you need to invoke this command:
mysql -u root -p
MariaDB [(none)]> CREATE DATABASE rose_wpdb;
Query OK, 1 row affected (0.67 sec)
MariaDB [(none)]> GRANT ALL ON rose_wpdb.* to rose_wpuser@localhost IDENTIFIED BY 'DkaYrbfLH4Dubc2B';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.06 sec)
MariaDB [(none)]> quit
At this point, we are ready to continue with the WordPress installation. Let’s navigate to our domain name in a web browser, enter the database details in the installation