This guide explains how to host a website on your own Fedora or Ubuntu Linux system by installing Apache2 (httpd), PHP and MySQL. However, it’s strictly for personal use so for professional hosting, you should probably turn to dedicated hosting services.

 

Installing Apache

For Fedora systems, open a terminal and:

su -
(enter root password)

yum install httpd

For Ubuntu systems, open a terminal and:

sudo apt-get update
sudo apt-get install apache2

We don’t need apache to be running yet, so:
sudo service apache2 stop

Installing PHP

Fedora:

yum install php php-common php-cli php-mysqlnd

Ubuntu:

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-cli

Installing MySQL

Fedora:

yum install mysql mysql-server
(this will install MariaDB)

systemctl enable maria.service
systemctl start maria.service
mysql_secure_installation

Hit Enter when it asks for password,
Hit Enter when it asks to set a password
Type and retype a password for root
Press Y and Enter for every other question.

Ubuntu:

sudo apt-get install mysql-server libapache2-mod-auth-mysql
(it will ask you to set a password for user root)

sudo mysql_install_db
sudo mysql_secure_installation

Enter the password for user root and hit Enter
If you don’t want to change it, press n and hit Enter
For every other question, press Y and hit Enter

For Ubuntu there’s one last step:

sudo nano /etc/apache2/mods-enabled/dir.conf

Edit the config file from this:

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

to this:

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

Starting up

Fedora:

systemctl enable httpd.service
systemctl start httpd.service
touch /var/www/html/test.php
nano /var/www/html/test.php

Add the following code:

Now open a browser and point it to http://your.server.ip.address/test.php

Ubuntu:

Make sure everything is started:

sudo update-rc.d mysql defaults
sudo update-rc.d apache2 defaults
sudo service mysql start
sudo service apache2 start

Testing your server:

sudo touch /var/www/html/test.php
sudo nano /var/www/html/test.php

Add this code:

Point a browser to http://your.server.ip.address/test.php
This is it. You can go ahead and install any application based on PHP and MySQL (like WordPress). If you already own a domain, you can set up a subdomain to point to your IP address so it can be accessed from a browser. Or, you can use a free subdomain from no-ip or afraid.org freedns (google it).

HowTo host a website on a Fedora or Ubuntu system
Tagged on: