Getting started with Apache Server on Ubuntu

Sagar Poudel
Jan 7 · 3 min read

Before we get started, let’s add another user to the server. It is always a good practice to avoid using root to access the server via ssh.

Create a new user

Use the following command to add a new user:

adduser <username>

Enter the password and other info to complete the process.

Now, we need to add the newly created user to the group ‘sudo’

The command to accomplish this is:

usermod -aG sudo <username>

Configure SSH

After the user is created successfully, we now need to configure some SSH informations. This will let the user access the server via SSH.

To switch the current user from ‘root’ to a new user, su ( switch user ) command is used.

Lets go to home directory and create a new folder, .ssh:

cd ~

mkdir .ssh

After these commands, we need to make sure that the folder has correct permissions set up. Run the following command that changes the files permission.

chmod 700 .ssh

After this, we need to dump public keys into authorized_keys section in order to be able to SSH in into the server.

touch .ssh/authorized_keys

chmod 600 .ssh/authorized_keys

Use this table to reference the permission types and codes associated with them

Finally, lets generate a key using the following command:

ssh-keygen -t rsa

In order to view the content of newly generated public key, we can use cat command.

cat <key_name>.pub

Last but not the least, copy over the text spitted out by the cat command into the authorized_keys. And with that, we can now SSH into the server using the new user credentials.

Install Apache

Now, lets install apache server and host a webpage. First we need to check for upgrades and then install apache.

sudo apt update

sudo apt install apache2

We can check the status of the server using the following command:

systemctl status apache2

Output of the previous command should look something like this

Additional Configurations

sudo apt-get install mysql-server

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

These commands will install mySQL and PHP onto the server.

Wrapping up

If you want to change the priority according to which the files are served, we need to edit a configuration file located at:


Lastly, we need to restart the server for the changes made to be reflected.

sudo systemctl restart apache2

Awesome books to learn more:

Follow us on Twitter 🐦 and Facebook 👥 and Instagram 📷 and join our Facebook and Linkedin Groups 💬.

To join our community Slack team chat 🗣️ read our weekly Faun topics 🗞️, and connect with the community 📣 click here⬇

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇


The Must-Read Publication for Aspiring Developers & DevOps Enthusiasts. Medium’s largest DevOps publication.

Sagar Poudel

Written by



The Must-Read Publication for Aspiring Developers & DevOps Enthusiasts. Medium’s largest DevOps publication.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade