Host a Website on VPS Without Control Panel
Virtual Private Server (VPS) is one of the most versatile options where web hosting is concerned. It can be used for almost all purposes from the deployment of web apps to running various complexities of websites or blogs.
The control panel itself isn’t a core part of VPS. In fact, it is actually considered an add-on. Although offering users a friendly way of interacting with the Operating System, you can fully operate your VPS account without a control panel.
The following review includes essential information, such as:
- Prerequisites
- How to Install a Web Server
- How to Create a Virtual Host
- Configure Apache
- Restart Apache
- Setup verification
- Upload your Website Files
- Install PHP and MySQL
- Connect your Website Database, if Needed
- Conclusion
- Frequently Asked Questions
Prerequisites
The control panel is a Graphic User Interface (GUI) driven method of handling your VPS. Without it, you will need to know the various commands necessary to install and configure the various components needed.
For today we’re going to look at what you need to host a website with the inclusive installation of a database. The components necessary will include the Apache web server, PHP module, and MySQL database.
You will need to have a VPN hosting account ready with an OS pre-installed, along with a domain name. For the purposes of this article I’m going to assume my domain name is called myexample.com.
How to Install a Web Server
The commands needed to install the Apache web server will vary depending on what OS you have chosen. Let’s look at some of the differences needed between a few common variants of OS:
Ubuntu
sudo apt update
sudo apt install apache2
CentOS
sudo yum update
sudo yum install httpd
Debian
sudo apt update -y
sudo apt install apache2 -y
OpenSUSE
sudo zypper update
sudo zypper install apache2
As you can see, the commands themselves are relatively simple. In fact, the examples I have shown include an extra step with each. The first line updates the package repository while the second installs the Apache web server.
How to Create a Virtual Host
If you plan on running multiple websites on your server you will need to work with virtual hosts. By default, Apache comes ready to handle these. However, you will need to create one configuration file for each virtual host.
Ubuntu
sudo vi myexample.conf
CentOS
sudo vi /etc/httpd/conf.d/vhost.conf
Debian
sudo vi /etc/apache2/sites-available/myexample.com.conf
OpenSUSE
sudo vi /etc/apache2/vhosts.d/myexample.conf
These commands will allow you to open a virtual host configuration file for editing based on your domain name. Once that file is open, enter the following code. It will be the same for all Linux platforms:
<VirtualHost *:80>
ServerAdmin admin@myexample.com
ServerName myexample.com
ServerAlias www.myexample.com
DocumentRoot /var/www/myexample.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Configure Apache
As with virtual hosts, Apache is managed through the use of configuration files (typically httpd.conf or apache2.conf). For the most basic configuration of Apache web server, you only need to set a few parameters in the configuration file.
Listen is used to bind Apache to a specific IP address or port. For example:
Listen 8000
ServerName lets you set the DNS host name or IP address/port. For example:
ServerName myexample.com:8000
ServerRoot identifies the home directory of the Apache installation. For example:
ServerRoot “d:/myexample/apache2”
DocumentRoot is where the server home directory is located. For example:
DocumentRoot “d:/myexample/apache2/htdocs”
<Directory “d:/myexample/apache2/htdocs”>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
In some instances Apache may work for you without these configurations being set. However, it is best to carry out this step for familiarization as well as to avoid any potential errors messages popping up.
Restart Apache
The following commands are not the only way of restarting the Apache web server. There are alternative ways as well.
Ubuntu
sudo service apache2 restart
CentOS
sudo systemctl restart httpd.service
Debian
sudo service apache2 restart
OpenSUSE
sudo systemctl restart apache2
Setup verification
To test if Apache web server has been correctly installed and configured, use the Apache binary as follows:
sudo apachectl -t
If there are any issues with the configuration, you will get error messages such as the following:
AH00543: apache2: bad user name username
The Apache error log may have more information.
If this occurs you will need to check your Apache web configuration files again. Once it works, you can proceed with the next step.
Upload your Website Files
The fastest and most simple way of moving your website files onto your VPS host is by using a FTP application. While some operating systems have default FTP clients, it is better to choose a more dedicated and secure FTP solution.
One such example is FileZilla, which is free. Whatever your choice, most solutions providers will have two versions of their application – the client and the server versions. YOu only need to download and install the client version.
Once installed, connect to your VPS host and you can begin transferring the files from there. A good FTP client like FileZilla offers you a GUI that helps make the process easier.
Install PHP and MySQL
Before you install either of these, make sure that your Linux distribution is up to date. This will help ensure the process goes smoothly. To update, run:
- sudo apt-get update
- sudo apt-get upgrade
Next we can go ahead and install both PHP and MySQL:
- sudo apt-get install php
OR
- sudo yum install php
- sudo apt-get install mysql-server
OR
- yum install mysql-server
Connect your Website Database, if Needed
If you’re running a website that needs the use of the database, now is the time to make sure it runs and then connect it. As with the other commands demonstrated so far, the one you use will depend on your Linux distribution.
For example, to start or stop the MySQL daemon:
sudo /etc/init.d/mysqld start
sudo /etc/init.d/mysqld stop
OR
sudo service mysql start
sudo service mysql stop
Once you’ve started MySQL, you will need to create a database in order to enter it’s details in your web application of choice. This needs to be done using the mysql tool which is a command line interface for executing MySQL instructions:
mysql -u root -p
If your installation of MySQL was correct and the command executes, you will note your prompt change to mysql>.
To create a database:
CREATE DATABASE mydatabase;
Next, create a user account and give it privileges for the database you created:
CREATE USER you@localhost IDENTIFIED BY ‘password’;
GRANT ALL PRIVILEGES ON * . * TO ‘you’@’localhost’;
FLUSH PRIVILEGES;
Depending on your usage of the account, you may wish to restrict it to specific privileges. This can be done by adjusting the permission type value. Examples of privilege types include SELECT, CREATE, and DELETE.
If you want to grant a user multiple privilege types, but not all, simply separate the privileges with a comma. Once you’ve created the database and user, you can then enter those details into your web application to get it to connect to the database.
Conclusion
This article only covers the very basics of operating a VPS hosting account without the use of a control panel. As you can see, it requires some extent of knowledge on Linux commands. This can raise some challenges to those unfamiliar with command line environments.
This relatively painful experience can be avoided simply by opting for a VPS hosting account that comes with a control panel. If you’re concerned about additional cost, ScalaHosting offers SPanel, which is extremely feature-packed and easy to use.
Best of all, the use of SPanel isn’t subject to licensing fees and it comes as a cost-effective option on ScalaHosting’s Managed Cloud VPS hosting plans. As an alternative, you can also opt to use cPanel but that will significantly increase the cost of your plan.
Hosting a website on a server with a control panel is one of the easiest tasks and can be accomplished in several clicks. Control panels are great for easy management of your server, but they require hardware resources and they set up your server with pre-setups which is drawback if you want to customize your server. Today we will learn how to host a website on VPS without any control panel installed.
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, you will see a page like this
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, like in the screenshot below.
Follow the instructions and you should have WordPress installed on your VPS server, and pointed to your domain. If you are one of our Linux Support clients we can set up your VPS by your requirements and we can install configure and optimize your favorite CMS or any other self-hosted application. We are available 24/7/365!