Skip to content

Instantly share code, notes, and snippets.

@DardanIljazi
Created November 11, 2018 01:16
Show Gist options
  • Save DardanIljazi/50dc13d19abc5bdfe8e633432225cbfa to your computer and use it in GitHub Desktop.
Save DardanIljazi/50dc13d19abc5bdfe8e633432225cbfa to your computer and use it in GitHub Desktop.
SharedHosting.md

Webserver installation and configuration with Nginx - PHP-FPM MariaDB - PHPMyadmin

Date: 10.11.2018

This document explains how to install a debian web server from scratch. It was intended to be done for an exam in Centre Profesionnel du Nord Vaudois (CPNV, Switzerland).

The final webserver has those features:

  1. Each user has one or more website
  2. Each user has a ssh access (so he can use scp)
  3. Each user has his own database (accessible by phpmyadmin)

Download Debian

  1. Browse www.debian.org in your browser
  2. Click on Getting Debian in the navbar
  3. Click on Download an installation image
  4. And click on the amd64 link

Debian pre-installation basics (optional)

The section below will explain you some principles if you want to make your server production oriented Pay attention that we don't take any responsibility about any security flaw that could occur by following all our instructions. For more secure solutions go to More reliable solutions section.

If you only want to use the configuration for personal use or a only few websites, you can freely go to the next Debian Installation section.

Minimal RAM

Knowing how much RAM your server should have is not easy to quantify because it depends on many factors.

It depends on the:

  • Minimum memory required by the system
  • Type of site hosted (showcase website, e-commerce, web application, intranet / extranet aso..)
  • Number of hosted websites
  • Resources that websites take by default
  • Visitors on websites at a moment T
  • Many other parameters like cache aso ...

To get an idea about a real (little) server having 4 websites on it (1 is dynamic and the 3 others are showcases website) here is what we have:

htop, screenshot taken approximatively at 23:00 on the 10.11.2018 after rebooting the server

htop, screenshot taken approximatively at 23:00 on the 10.11.2018 after rebooting the server

We notice:

  • Approximatively 1000MB (~50%) are used. This comes frome the OS itself and the running processes
  • The clamav process (antivirus) takes a lot of memory itself (~28%)

Even if those facts are not enough, we can say that it is therefore important to take into account all factors (minimum memory required by the server, type of wesite, number of websites, visitors ..).

The best solution is to test it in production and see how it reacts. If needed websites can also be moved to other server.

Debian installation

Basic installation

  • Choose - install
  • Language - English
  • Region - Other->Europe->United Kingdom
  • Default language settings - United Kingdom - en_GB.UTF-8
  • Key map settings - United Kingdom

Host configuration

  • Host name - SharedHosting
  • Domain name - let it blank
  • Root password - ROOT_PASSWORD
  • New user - USER
  • New user password - PASSWORD

Disk configuration

partition disk - Separate /home, /var, /tmp partitions and use LVM

Package manager

Use network mirror - yes -> United Kindom -> ftp.uk.debian.org
http proxy info - let it blank

Software selection

  • Uncheck all and just keep Only SSH server and standard system utilities

GRUB boot loader

  • yes -> /dev/sda

Install finished

Basic installation

The easy way (script)

A ready-to-use script has been created for the project:

Github Code

  1. Follow the link above (github)
  2. Create the file basicinstall.sh with root rights on your server (nano basicinstall.sh)
  3. Paste the code in it and save it
  4. Make the basicinstall.sh runnable with chmod +x basicinstall.sh
  5. Run it with ./basicinstall.sh

What the script does:

  1. Install dependencies
    • Nginx
    • Mariadb
    • Php-fpm
    • Phpmyadmin
  2. Create a folder /var/www/default structured like this:
    • /var/www/default
      • createuser.sh --> Script that should be used to create new user/website
      • index.php --> A default page copied to each new user folder when newly created
      • www.conf --> Default php-fpm configuration file that will be copied and modified per each user
  3. Structure the web folders as follow:
    • /var/www/
      • user1/
        • website1user1.com
        • website2user1.gov
        • ...
      • user2/
        • website1user2.ch
      • user3/
        • website1user3.org
  4. Create a redirection to phpmyadmin by putting /phpmyadmin after his domain name
    • userX:
      • userXwebsite.com/phpmyadmin
  5. Make user website folders accessible by ssh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment