Skip to content

Instantly share code, notes, and snippets.

@primetoxinz
Created February 24, 2018 00:36
Show Gist options
  • Save primetoxinz/dc0dadcc1f747b97892b7e3f006d5352 to your computer and use it in GitHub Desktop.
Save primetoxinz/dc0dadcc1f747b97892b7e3f006d5352 to your computer and use it in GitHub Desktop.
Server Setup
  • Create VirtualBox VM for Ubuntu using the Ubuntu Mini.iso 16.04

  • Go through the basic installation process for Ubuntu

  • Restart into the installed OS

  • Login into the created user odu_user

  • Install Vim sudo apt install vim

  • Edit /etc/network/interfaces

    • Comment out iface enp0s3 inet dhcp
    • Add
    address         10.0.2.15
    netmask         255.255.255.0
    gateway         10.0.2.2
    broadcast       10.0.2.255
    dns-nameservers 8.8.8.8 8.8.4.4
    pre-up iptables-restore < /etc/iptables/rules.v4 
    
  • Now configure iptables to allow ssh, loopback and http connections

    • Add the initialization rule sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT.

    • Add a loopback accept rule sudo iptables -A INPUT -i lo -j ACCEPT

    • Add a SSH accept rule on port 22 sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

    • Add a HTTP accept rule on port 80 sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

    • Set all unfiltered packets to drop sudo iptables -P INPUT DROP

    • Save the iptables rules to /etc/iptables/rules.v4 which is loaded by the network interface config

  • Install openssh server, sudo apt install openssh-server

  • Move to the host machine and access the VM via ssh ssh odu_staff@localhost -p 2222

    • 2222 is the VirtualBox port I used for the host -> guest connection, it was being really weird
  • Create the grad, ugrad and staff groups

    sudo groupadd ugrad  
    sudo groupadd staff
    
  • Edit /etc/sudoers Add line %staff ALL=(ALL:ALL) ALL to give all members of the staff group sudo privileges

  • Remove original user odu_staff from sudo group so the staff group actually matters

    • sudo gpasswd -d odu_staff sudo
  • Add two more users odu_ugrad and odu_grad to their respective groups

    • sudo useradd -m odu_ugrad -g ugrad
    • sudo useradd -m lodu_grad -g grad
  • Add three directories sudo mkdir /grad, sudo mkdir /ugrad, and sudo mkdir /everyone

  • Set permissions for each directory

    sudo chown root:grad /grad
    #1770 sets the sticky bit while giving read and write permissions to the owner and assigned group 
    sudo chmod 1770 /grad
    #ugrad
    sudo chown root:ugrad /ugrad
    sudo chmod 1770 /ugrad
    #everyone
    #1777 also sets the sticky bit and allow anyone to read and write
    sudo chmod 1777 /everyone
    
  • Setup LAMP

    • Install the Apache Server sudo apt install apache2

    • Install the MySQL server sudo apt install mysql-server

    • Add ServerName odu.edu to end of file to suppress warning message

    • Restart apache sudo systemctl restart apache2

    • Add 8080 -> 80 port into the VM to allow accessing the webpage

    • Initialize the MySql Server mysql_secure_installation, go through the prompt

    • Install PHP sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

    • Remove /var/www/html/index.html so the php index is the one used by default

    • Create /var/www/html/index.php for the php code

    • Open http://odu.primetoxinz.com:8080 in a browser to view the default webpage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment