Guide to setup servers(VPS, e.t.c.) without any control panel

GUIDE TO SETUP YOUR SERVER WITHOUT ANY CONTROL PANEL

I have stumbled upon so many guides(websites) online in an effort to host my websites on VPS/ Dedicated server without using any control panel. But though most of them are useful, none of them was actually a complete all in one guide. So i have taken it upon my self to create this complete guide to help anyone out there who might need something like this.

In this guide, I am using a DEBIAN LINUX SERVER and I assume that you have basic knowledge on how to log into your VPS/ Dedicated server as root user . (if you don’t know what this is, please don’t try this !). If you don’t have an SSH client yet, you can download Putty by clicking here.

STEPS TO TAKE:

  1. Updating.
  2. Installing fail2ban (to help protect against bots trying to guess our SSH password)
  3. Installing Apache2.
  4. Installing MySQL.
  5. Installing and Configuring PHP5 and Getting MySQL Support.
  6. Virtual Hosting Configuration ( so that we can host multiple websites on the same server ).
  7. Installing PHYMyAdmin.
  8. Fail Safe If and When PHPMYadmin Does not work.

REQUIREMENTS:

  1. An SSH Client
  2. Debian 7 wheezy installed on your server
  3. Root access to your server

After you have successfully logged into your VPS or Dedicated server as root user through SSH, follow the below steps.

(To run a command, simply tap the enter key on your keyboard after you have finished typing the command. IT IS IMPORTANT TO PAY ATTENTION AND READ WHAT IS BEING WRITTEN OUT BY THE SERVER CAREFULLY WHEN RUNNING COMMANDS OR INSTALLATION. SO YOU CAN RESPOND APPROPRIATELY)

STEP 1 UPDATING YOUR SERVER

Run the following Commands;

apt-get update
apt-get upgrade
apt-get unattended-upgrades

STEP 2 INSTALLING fail2ban

Run the following Command

apt-get install fail2ban

(NOTE: If or When prompted by the server to enter Y/N, type Y and then tap enter).

STEP 3 Installing Apache2

Run the following Command

apt-get install apache2

STEP 4 Installing MySQL

Run the following Command

apt-get install mysql-server mysql-client

While the installation is in progress, you will be prompted to set a Password for root user of MySQL. Type in a Strong Password that you can remember.

STEP 5 Installing and Configuring PHP5 with MySQL Support

Run the following Command

apt-get install php5 libapache2-mod-php5 php5-mysql php5-curl php5-gd

Next we restart apache2 and MySQL server so that the new configuration will come into effect.

Run the following Command

service mysql restart
service apache2 restart

STEP 6 Virtual Hosting Configuration

(Please use your own domain and server ip when following this example.)

For example lets say, I want to host http://www.example.com and http://www.myexample.com and the IP of my server is 111.222.333.444

Its always advised to keep the directories that we host the sites on in a well organised manner.

We now tell Apache2 to listen to only the desired IP address (111.222.333.444 in my example)

Now by using your favourite editor, edit this file /etc/apache2/ports.conf

Run the following Command

nano /etc/apache2/ports.conf

If you don’t have nano editor installed yet, I advise that you install it by running the below command.

apt-get install nano

If you have installed nano successfully. Now run the Command to edit the file;

nano /etc/apache2/ports.conf

Now look for NameVirtualHost *:80 in the file

and change NameVirtualHost *:80 to below

NameVirtualHost 111.222.333.444:80

NOTE! Replace 111.222.333.444 with your actual server IP!

Now tap Ctrl O on your keyboard to save. Tap enter on your keyboard. And then tap Ctrl X to exit the editor.

Now we are ready to Host websites, as i told you above I want to host http://www.example.com and http://www.myexample.com

so lets create the Directories in an well organized manner,

Run the following Command

mkdir -p /srv/www/example.com/public_html
mkdir -p /srv/www/example.com/logs

mkdir -p /srv/www/myexample.com/public_html
mkdir -p /srv/www/myexample.com/logs

NOTE! Replace my example domains with your actual domain or domains!

Next we create the virtual config file for each site in /etc/apache2/sites-available/
Run the following Command

nano /etc/apache2/sites-available/example.com

and type the following code in it


ServerAdmin any-email-address-you-use@anydomain.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log

Obviously you have to change the IP, DOMAIN AND EMAIL ADDRESS to your own.

And the next site myexample.com

Run the following Command

nano /etc/apache2/sites-available/myexample.com

and type the code into it..


ServerAdmin any-email-address-you-use@anydomain.com
ServerName myexample.com
ServerAlias www.myexample.com
DocumentRoot /srv/www/myexample.com/public_html/
ErrorLog /srv/www/myexample.com/logs/error.log

again, change the IP, DOMAIN AND EMAIL ADDRESS to your own.

Now to enable the websites

Run the following Command

a2ensite example.com
a2ensite myexample.com

NOTE! again, change the DOMAIN OR DOMAINS to your own.

Next, let’s reload Apache2 so that all the above setting takes effect.

Run the following Command

service apache2 restart

STEP 7 Installing PHPMyAdmin

Run the following Command

apt-get install phpmyadmin

you will be prompted to select the type of web server, Please select Apache2 with your up,down and sideways keys on your keyboard and tap enter on your keyboard. (MOST TIMES, IT IS ALREADY PRE-SELECTED, SO JUST TAP ENTER WHEN THE DIALOGUE COMES UP. BUT BE SURE LOOK IF THE RED MARK IS BESIDE APACHE2)

phpMyAdmin will then ask whether to execute common configuration task or not. Because phpMyAdmin must have a database installed and configured before it can be used, so you better to execute it. Select Yes.

Next enter password for administrative user. (THIS IS THE PASSWORD YOU CHOOSE WHEN INSTALLING MYSQL ABOVE)

Next define MySQL application password phpmyadmin.

Then enter the same password once again to confirm.

Now open up your browser and access your newly installed phpMyAdmin using this address:

http://your-server-ip/phpmyadmin

If you see 404 not found page, then we will be editing apache2 config , and tell the path of phpmyadmin to it.

Run the following Command

echo "Include /etc/phpmyadmin/apache.conf >> /etc/apache2/apache2.conf"

Now try opening http://your-server-ip/phpmyadmin again.

If you still see 404 not found page.

Run the following Command

nano /etc/apache2/apache2.conf

Scroll down to the very bottom of the long page with your down key on your keyboard. And type in the following;

Include /etc/phpmyadmin/apache.conf

Then Ctrl O to save. Tap the enter key and then Ctrl X to close.

But if this is already at the bottom of that page (Include /etc/phpmyadmin/apache.conf), then don’t type in anything. Simply Ctrl X to close.

Run the following Command

service apache2 restart

try opening http://your-server-ip/phpmyadmin again.

It should now display phpMyAdmin login page. Login for the very first time using root as username and the password you defined earlier. Once logged in, you can then create new database, new database user and assign proper privilege of that user to the database.

STEP 8 Fail Safe

You won’t need this step if the above PHPMYADMIN WORKED FOR YOU AND IS ACCESSIBLE. But if the above PHPMYADMIN did not work for you, then follow this step to create your database and user from the command line. (NOTE: This step is prefferable if your server RAM is small and you want to save space. Then you can use the step without even bothering about installing PHPMYADMIN. If you have already installed PHPMYADMIN and want to remove it and use this step to save space, then run the following commands one after the other (NOTE! When running phpmyadmin removal commands, you will be prompted to remove the database along with it, please select NO or N. Or Type N;

dpkg -P phpmyadmin
rm -f /etc/apache2/conf.d/phpmyadmin.conf
apt-get autoremove phpmyadmin
service apache2 restart

Then run this command next to open the below file in nano editor

nano /etc/apache2/apache2.conf

When the file opens, go to the very bottom of the file using your up, down and sideway keys and look for this

Include /etc/phpmyadmin/apache.conf

When you find it, select it with your up, down and side way keys, then delete it with back space. Then save and exit. You should know how to save and exit by now if you have been following this tutorial.

NOW LETS BEGIN THE ACTUAL FAIL SAFE PROCESS.

I assume you have logged into your SSH client with a user that has root access.

Run this command

mysql -u username -p

REPLACE username with your actual SSH root user name. You will be prompted for your MYSQL Password, type it in and tap the enter key. (This is the password you used to install MYSQL)

Next create your database by running the following command.

create database databasename;

Replace database name with your actual database name of choice.

Next create user by running the following command.

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

Replace newuser with your database username of choice and replace password with the password you want to use for that specific user.

Now grant all privileges to the user you just created on the database you just created.

Run this command

GRANT ALL PRIVILEGES ON databasename.* TO 'newuser'@'localhost';

Replace databasename and newuser with the actual database name and username you just created.

Now the contents of this domain example.com, should be uploaded in this path /srv/www/example.com/public_html/ and that of myexample.com in /srv/www/myexample.com/public_html/

Login with filezilla ftp client with your IP and using port 22. You can download filezilla by clicking here. Search for this part after login /srv/www/example.com/public_html/ (Replace example.com with your own domain).

NOW YOU ARE ALL DONE. But there’s still a tricky part. Now how do you create tables that you need in the database without PHPMYADMIN? Well you can actually do that easily by running a php script. For those that don’t know how to do this, i will write a small tutorial.

Now copy this below code and paste it into a notepad.

Replace newuser, password and databasename with your own information. Now save the notepad with “database.php” (Save it exactly like this with the quotes). Next, copy the below code into another notepad and save it with “createtables.php” (Save it exactly like this with the quotes).

The above is just a sample php script to create a new table called user that has five columns named username, password, firstname and lastname. But it works if you run it. If you study the above sample very well, you can gain the knowledge you need to create your own php script to create as much tables as you need.

I hope this guide is useful. If you have any questions, do not hesitate to contact me.

Leave a Reply