Linux Apache MySQL PHP (LAMP) Server to host our own website

The most popular configuration to host our own website is certainly the Linux + Apache + MySQL + PHP combination (Alias LAMP server). Although it is possible to do the same using Windows (WAMP) or with others applications too, I will only focus on LAMP.

Apache is the most popular HTTP server; coupled with the world’s most popular Open Source database, MySQL and the very popular scripting language PHP, you should not doing a big mistake here using this combo.


To install it, just install all these applications:

sudo apt-get install apache2 mysql-server php5 php5-mysql

During the installation, you will need to set MySQL root password and to select the Web Server to reconfigure (Apache in our case)



Either you want to build your own website from scratch or you could use some Content Management System (CMS), like WordPress, Drupal, or Joomla, which is like a template that you can customize and fulfil (Like this blog).

In any case, you will need to build a specific folder in /var/www, install what ever you want in it and provide a Virtualhost to inform Apache to deliver this folder depending on the url asked, as briefly discussed in my previous post to help you set a Static IP and explain the server/router should response.

Let’s say you want to host 2 websites, one blog and one photo gallery, here is how you should do:

1) Create the folders

sudo mkdir /var/www/myblog
sudo mkdir /var/www/gallery

(You can call the folders as you wish)

2) Add whatever CMS, services you want inside

3) Give proper permission to these folders

As we have created the 2 previous folders using sudo command, the owner is now root…which will cause access issues. To avoid that, we need to change the owner of these 2 folders by www-data.

sudo chown -R www-data:www-data /var/www/myblog
sudo chown -R www-data:www-data /var/www/gallery

chown is to change owner, -R option is for recursive, if you want to do it on full folder, you need to add -R, and www-data:www-data is to assign the folders to the user AND group www-data.

4) Create the needed virtualhost (Vhost) files

The apache virtualhost files are the key to know which folder/service to deliver when an user request a certain domain name.

For example, you may want that redirect to the folder /var/www/myblog and that the sub-domain redirect to /var/www/gallery or may be to have a second domain name directly, it’s in fact not very difficult with the Virtualhost.

You will need to create the conf file in /etc/apache2/site-available and then active this virtualhost (Actually you could directly create the conf file in /etc/apache2/site-enabled, thus already active but this solution is less flexible if you want to turn on/off sometimes some websites)

– Create the virtualhost:

sudo nano /etc/apache2/site-available/myblog

In my presented case, the Virtualhost of that will redirect to the folder /var/www/myblog will look like (With comments after the ###, you could remove them if you want)

<VirtualHost *:80> ### all the request on port 80
        ServerAdmin  ### Useful for error landing page to display your email
        ServerName    ### What will be the main URL to link with (Domain, sub-domain,...)
        ServerAlias   ### Any others URL? Could have different domain name here

        DocumentRoot /var/www/myblog   ### Where is located your website  
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        <Directory /var/www/myblog>  ### Where is located your website
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all

The remaining lines will not need much changes normally.

And you could do the same for your second website

– And now activate your 2 virtualhosts:

sudo a2ensite myblog
sudo a2ensite gallery

where myblog and gallery are the names of the virtualhost files created previously.

And finally restart apache:

sudo /etc/init.d/apache2 restart

If no error message, you should be all set.

PS: Don’t forget to create an A redirection on your domain name registrar to your IP and allow connection from port 80 into your router.

Exploits of a Mom


Loves to discover web-based apps to install on his own server@home and write articles about it


Add a comment


We accept it prudent for your government to take 12-18 months to examine and assess the impact of these changes. Are we talking a process of years to get back to what Home Capital used to do in mortgage originations.v
Written on Sun, 10 Nov 2019 08:16:13 by Jude
Здесь вы можете заказать копию любого сайта под ключ, недорого и качественно, при этом не тратя свое время на различные программы и фриланс-сервисы. Клонированию подлежат сайты как на конструкторах, так и на движках: - Tilda (Тильда) - Wix (Викс) - Joomla (Джумла) - Wordpress (Вордпресс) - Bitrix (Битрикс) и т.д. телефон 8-996-725-20-75 звоните пишите viber watsapp Копируются не только одностраничные сайты на подобии Landing Page, но и многостраничные. Создается полная копия сайта и настраиваются формы для отправки заявок и сообщений. Кроме того, подключается админка (админ панель), позволяющая редактировать код сайта, изменять текст, загружать изображения и документы. Здесь вы получите весь комплекс услуг по копированию, разработке и продвижению сайта в Яндексе и Google. Хотите узнать сколько стоит сделать копию сайта? напишите нам 8-996-725-20-75 звоните пишите viber watsapp
Written on Wed, 16 Oct 2019 14:30:28 by Neoomor
Manually setting up a LAMP based server is quite difficult and time taking. You have to go through a lot of trouble for this. Why not instead use some platform, like Cloudways PHP MySQL hosting ( ), where the platform automatically setups the server.
Written on Tue, 16 Oct 2018 12:20:22 by olidev