Setting Up Apache 2.4, MariaDB, and PHP 7 with Ubuntu 16.04 on a Digital Ocean VPS


  • Setup Digital Ocean droplet
  • Create an SSH key
  • Login and adjust sshd_config file
    • Set PermitRootLogin no
    • Set PasswordAuthentication no
    • Restart SSH systemctl restart sshd.service
    • View status of SSH systemctl status ssh.service
  • Create a user: adduser user
  • Add user to sudo group: usermod -aG sudo user
  • Setup user's .ssh directory and authorized_keys file
    • mkdir ~/.ssh
    • chmod 700 ~/.ssh
    • sudo cp /root/.ssh/authorized_keys ~/.ssh/
    • chown user:user ~/.ssh/authorized_keys
    • chmod 600 ~/.ssh/authorized_keys
  • Test ability to login via SSH using newly created user
  • Setup firewall using ufw
    • Allow SSH: sudo ufw allow 22
    • Allow Web Server: sudo ufw allow proto tcp from any to any port 80,443
    • Enable: sudo ufw enable
    • Check status: sudo ufw status
  • Download, install, and setup Apache 2.4
    • Install: sudo apt-get install apache2
    • Start after reboot: systemctl enable apache2
    • Check status: systemctl status apache2
    • Set KeepAlive Off in /etc/apache2/apache2.conf
    • Disable mpm_event module: sudo a2dismod mpm_event
    • Enable mpm_prefork module: sudo a2enmod mpm_prefork
    • Enable mod_rewrite module: sudo a2enmod rewrite
    • Add ServerName directive to /etc/apache2/apache2.conf using public IP or FQDN
    • Check config syntax: apache2ctl -t
    • Disable default VirtualHost: sudo a2dissite 000-default.conf
    • Remove default web page: sudo rm /var/www/html/index.html
    • Restart Apache: sudo systemctl restart apache2.service
  • Download, install, and setup MariaDB in place of MySQL
    • Install: sudo apt-get install mariadb-server
    • Check status: systemctl status mysql
    • Start after reboot: sudo systemctl enable mysql
    • Secure the service: sudo mysql_secure_installation
  • Download, install, and setup PHP 7
    • Install: sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql php-gd php-json php-cli php-curl php-mbstring php-xml php-xmlrpc
    • Set DirectoryIndex index.php index.html in /etc/apache2/mods-enabled/dir.conf

Additional Steps to Setup Server

Helpful Links



Comments:


Gravatar of Kyle Jones

Knowledge Base is a repository for various notes, guides, and thoughts on a wide range of IT related topics. Read more...

Sponsored By:


Web development services by Say Web Solutions. Visit website.