How to Host a Website (on a Linux Machine)

How to Host a Website (on a Linux Machine)

As well as there being a way to host your website from home on your Windows machine, you can also do the same on Linux. So, let’s take a look at how we can install Apache, PHP, and MySQL on your Linux system (LAMP).

How to install LAMP

Start by launching your Linux terminal:

terminal

Then run the following command in the terminal:

install apache

When you’re installing your LAMP software, you may be asked to confirm your MySQL password for the root user, so make sure you have this to hand in order to proceed.

If you make any changes to your Apache configuration, you’ll need to enter the following command:

restart apache

Alternatively you can amend the configuration through your local .htaccess file.

How to check PHP

To ensure that your PHP server is working correctly, create a test version of your PHP file in your web server’s root directory like so:

info.php

Now launch your PHP test page by visiting http://localhost/info.php

This will display your PHP version, configs, and any installed modules you have. You can install more PHP modules using Ubuntu. If you’re not sure which modules you can install, you can download the graphical package manager here.

How to check MySQL

As we said previously, some (well, most) CMS platforms like WordPress use MySQL databases, so you’ll need to check that your MySQL installation works as intended in order to proceed.

Launch the terminal and check your MySQL installation by typing ‘service mysql status’. An example can be seen below:

mysql status

If for any reason the above does not appear for you, you can restart the MySQL server by typing ‘sudo service mysql restart’.

Once your MySQL command line is available, you can manage your databases. Use the admin information you entered earlier when you installed MySQL:

mysql root

Now you’re free to create your databases, or do anything you want with MySQL:

create db

Most of the time your databases will be automatically created by your CMS platform, but if you want to manually make any changes, you’ll need MySQL.

If you’re not 100% comfortable with databases, you can use PHPMyAdmin which is user-friendly and allows you to manage your databases hassle free.

Further information on setting up your LAMP server can be found here.

Configuring your Domain Name (DNS)

If you’ve purchased a domain name, e.g. www.mywebsite.com then you’ll want to link that to your hosting, as you normally would with a web hosting provider, to your domain name provider.

Your domain’s DNS will have an A record pointing to an IP address – if you’re not sure how to access this, contact your domain name provider for further information (this is where you purchased your domain name from).

Once your DNS records have been setup, you can query your DNS by using a tool such as dig:

dig

Configuring Apache

Once you’ve configured your domain name, you need to tell Apache about it in order to accept requests, and which directory to use. Before we begin, we need to setup the directory for your domain name, create a test index.html file, and setup permissions:

apache

In order to be able to see the page created, you’ll need to setup a virtual host file:

sudo cp and nano

Then edit the file to display the following (replace the examples with your actual information):

server admin

You’ll then need to tell Apache to reload in order to see your changes, so reconfigure it by using the following:

reload

Navigate to your local hosts file (/etc/hosts) and add a line with your IP address and domain name from earlier – remember to correctly enter your details otherwise the server will not be able to connect:

host

Now you can go to your domain name, e.g. www.mywebsite.com and see your website live on the world wide web!



Leave a Reply

Your email address will not be published.

*
*
*