Creating a simple Apache web-server & how to use the basics of MySql

Hello, in this post I will go through on how to setup a Apache web server and how to create a simple mysql database.

NOTE: It is always good to backup your important files. Backing up files everyday will save you from a lot of trouble later should any of your storage devices fail or any installation erase them.

NOTE: It is STRONGLY recommended to have good passwords. Easy passwords will compromise your own/clients data and cause serious problems later down the road.


Step 1: Install Apache web-server on your computer/server

We’ll begin by using the sudo apt-get install command and install the web-server through the terminal. It’s also good to check that all your libraries and other packages are up to date at the same time.


sudo apt-get update -y && sudo apt-get upgrade -y && sudo apt-get install apache2 -y


After this if no errors show up in the last lines of your terminal, you have succeeded with the installation.


Now type:

ip addr


into your terminal and find your IP address. When you’ve found it, you can use it or either your http://localhost inside your browser to connect to the website. Localhost is meant for anyone on the same LAN as you, while the IP is meant more for a external user to be able to connect to it (as long as your correct ports are open).

Congratulations, you now have a basic web-server open!


Step 2: Create user homepage

We will now create a simple homepage for the Apache web-server.

First we Need to enable the creation of a user directory. To do this simply type:

sudo a2enmod userdir
sudo /etc/init.d/apache2 restart


Now we need to create the public_html folder where you will place/create/modify your website for the user.
first head to your home folder with the cd command and then type:

mkdir public_html


Now you have a public html folder. To access it type


to get your current username

Now use that and add it to http://localhost/~yourusername

You will find a empty folder if you open that link


Now the user sebastian has a html folder that he can create any html for. Creating a index.html file inside the folder will make it the landing page instead of this folder structure.

EXTRA: Let’s create a simple html5 webpage.

Navigate into public_html by typing

cd public_html

after opening the terminal. Now type

nano index.html

There are many templates out on the internet for simple html5 webpages, so you can easily find a ready one. I’ll just put some basic stuff into mine. Copy paste this into the blank text file.

<!doctype html>
<title>Sample Page</title>
<meta charset="utf-8">
<h1>Header 1</h1>
<p>Paragraph 1</p>

Hit ctrl+O and save the file. Then hit ctrl+x to close the nano text editor. Head to your webpage again with

Step 3: Install MySQL database & PHPMyAdmin

Now we shall install MySQL database & PHPMyAdmin.

First type:

sudo apt-get install mysql-server phpmyadmin


Now you have it installed, but we still need to configure it. Once the installation is done, a graphical user interface should open and ask for you to create a password for the MySQL database user called root (not your OS root user!!!). Give it a good password and type it again when asked to confirm it.

Capture9 Capture10

After this you will be asked to select which server you want to use. Select apache2 and hit enter.


It will now complete the configuration.


Hit <Yes> and follow the steps. Give your password you created earlier and then give phpmyadmin a unique password. Hit enter and confirm the password again. You now have MySQL and phpmyadmin installed!


Step 4: Create a simple MySQL table

Now we will create a simple table in MySQL. First we need to open the terminal and then login. Type:

mysql -u root -p


Type your password in and then type:


This will create a database called USERS. Here will for example put our user info when they register on our website.

Now type:

CREATE TABLE users (id INT, name VARCHAR(20), email VARCHAR(20));


Now you have a table with the fields user ID, Name and E-mail.

Let’s check the table and then add some users to test it out. When you have a automated system the website will automatically add users to the MySQL database, but that’s not the point of this tutorial.



You will see that we have a table called users. Let’s add some.

INSERT INTO users (id,name,email) VALUES(1,"Foobar","");
INSERT INTO users (id,name,email) VALUES(2,"Foobar2","");
INSERT INTO users (id,name,email) VALUES(3,"Foobar3","");

Now we have 3 users. But typing


won’t give us anything. We have to type:

SELECT * FROM users;

to see all the users.


And there you have it, a fully working MySQL database with a simple users table.


I hope you learnt something today! Have a good day and thanks on my behalf to you!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s