Apache Hosting Website Title Image

Welcome to small tutorial series of hosting website on linux machine. Linux distro we used for this setup is Ubuntu OS. However, this can be implemented in any linux distro.

At the end of this tutorial you will be able to host your php and mySQL based website on linux machine The tutorial is divided into two parts. In first part, we discuss about basic components and their installation part. In next section, we shall write sample php code for basic website and host it under apache2.


For this tutorial three components would be required to be installed.

  • Apache2 : apache2 is open-source HTTP server. It is still most popular web-server used worldwide today.
  • php and php sqlite component: PHP is server side scripting language. PHP and its component will help you to interact with backend mySQL database for your website.
  • mySQL: mySQL is database solution in which you shall be storing your data in table.

Install apache2

Apache is open source web-server software that powers much of the web today. It is maintained by apache-http-project. Explore more here :

Open your terminal and type in commands

sudo apt-get update
sudo apt-get install apache2

For fedora based system

sudo dnf install apache2

To check if apache2 is installed properly

Open browser and navigate to

By default apache runs on 80 port and hence you need not provide the port number in your browser.
Or ip-address of your server. For example

Check proper apache2 installation image
To change port address, you need to edit the configuration file at /etc/apache2/ports.conf and change the Listen 80 to your desired port number. After edit you need to restart the apache2 server.
sudo service apache2 restart
apache webserver port config image

Install mySQL

mySQL is database management solution that helps you to store and retrieve data in tables. Since in this tutorial we shall be using php, we will also need to install php5-mysql component.

mysql -uroot 

If you set the password during installation open with -p parameter

mysql -uroot -p
Check mySQL isntalled properly image

Install PHP

PHP is open source web server scripting language. It is backend scripting language that will help you to interact with the mySQL database. For example if you want to show the tabular employee list stored in your mySQL database in your website, with the help of PHP you can interact with mySQL, retrieve the employee list and render in html page. Php5-mysql library helps you in this regard. PHP provides multiple auxiliary libraries for different needs. Php5-mysql is one among them and we shall use that in our tutorial.

To search the libraries that are available

apt-cache search php5-

Search php available libraries image
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
sudo apt-get install php5-sqlite

To check if php is installed correctly, make file /var/www/html/info.php and add content


Restart apache2

sudo service apache2 restart

Open web browser and navigate to

If you are using remote server replace ip with server’s ipaddress.Upon success, you should see following webpage

check apache and php installed properly image


Now you are ready with the basic setup required for this tutorial. In next section we code sample webpage in php that would retrieve the information in mySQL table. Then we host it under apache2.
That's all for now. Do leave suggestions, comments or questions in the comment section below. If you liked the tutorial, share with your friends and spread the word.

You can navigate to next section : HOSTING WEBSITE ON LOCAL LINUX MACHINE PART 2 : Code and Deployment