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.
Apache is open source web-server software that powers much of the web today.
It is maintained by apache-http-project. Explore more here :https://httpd.apache.org/
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 http://127.0.0.1
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
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
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.
If you set the password during installation open with -p parameter
mysql -uroot -p
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 check if php is installed correctly, make file /var/www/html/info.php and add content
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
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.