
20 May How To Set Up a LAMP Web Server From Scratch on Ubuntu 16.04
In this setup guide, we will show you the fast way to rapidly deploy a functioning web server on Ubuntu 16.04. The web server we will be deploying is the very popular LAMP stack. LAMP stands for Linux, Apache2, MySQL, PHP. We will be utilizing Postfix as a Send-Only SMTP Server.
Purchase the base VPS
We prefer Digital Ocean as our VPS (virtual private server) provider. Digital Ocean utilizes SSD (Solid State Hard Disks) in their machines. These are known for better reliability, uptime and most of all SPEED! For websites with less than 1000 visitors per month, get a VPS that is 2GB 1CPU. For sites with 1000-6000 visitors per month get the 4GB 2CPU VPS.
Obtain Your Initial Credentials
By default, once you purchase a VPS from Digital Ocean they will send you an email containing your root login with your encrypted password string. We recommend making your new password very strong. We will cover that in the next steps. Take note of your credentials, you will need them later.
Get a Copy of PuTTY
PuTTY is a SHELL communication tool often used by developers to configure, manage and maintain Linux web servers. We like the way PuTTY operates so this is the one we will run with. You can download PuTTY here.
Connect to your new VPS
Open your new PuTTY application. You will be prompted for the server IP address. Use the IP address that was emailed to you by Digital Ocean and enter it where we show the your.ip.here designation. Make sure your port is set to 22 and you have SSH selected. Once you are ready, click on open.
Log In
Once connected, you will be prompted for the username. This by default will be root. The password you will use is the one that was emailed to you earlier. Copy the password from your email and to paste it into PuTTY you will use the right click button. Once initially logged, UNIX will prompt you to change your password. Please make your password as secure as possible.
Commands
In order to keep this post as short and user-friendly as possible, we are going to list only the bare essential commands that are needed to have a basic web server with a brief description. Follow these step by step in the order we say to do them. Any deviation will have you starting over from scratch. Trust us! If you are an experienced web developer, feel free to modify these and add security checkpoints along the way.
This will run the standard update protocol on your LAMP server to get the latest updates and code distributions.
This will install the base Apache2 web server
— Note: Answer Y to the prompt —
This will test the configuration of your Apache2 installation. You should see a [RUNNING] in green
This will open up your apache configuration file
— AT BOTTOM OF FILE ADD: ServerName YOUR.IP.ADDRESS —
— wHEN FINISHED EDITING HIT CTRL+X and then Y to save and exit —
This will restart Apache after your configuration changes
This will explain what Apache is and add
This will update your rules
— Now open a web browser and paste your IP address in the browser. You should see the following screen —
This will install CURL
This will install Cthe MySQL Server answer Y and create your password for ROOT this is very important so REMEMBER IT!
This will setup your MySQL server and secure it. Best practice is to answer them in this order: N Y Y Y Y
This will install php and the extensions needed
— Answer Y and proceed —
Swap the priority of .html and .php save and close the file ctrl+x Y
Restart Apache
THis will run a quick Apache system test. You should observe a message in Adcive: active (running)
Installs Cache and Less
Installs CLI
This adds a .php file in the web server to check if php is running see next step on what to paste into this file
<?php phpinfo(); ?>
Paste this code into the file Then save and close the file.
— IN BROWSER ACCESS: http://your_server_IP_address/info.php TEST IF PHP IS RUNNING You should see a page similar to the one below. Notate the PHP version —
This will remove the info.php testing file from your server
This will remove the info.php testing file from your server
Run update
Installs mbstring and get text
answer Y to the question and answer the config phpMyAdmin questions like this
- For the server selection, choose apache2.
- Select yes when asked whether to use dbconfig-common to set up the database
- You will be prompted for your database administrator’s password
- You will then be asked to choose and confirm a password for the phpMyAdmin application itself
Installs mcrypt extension
Installs mbstring extension
Restarts Apache
IN BROWSER ACCESS: https://domain_name_or_IP/phpmyadmin TEST IF PHPMYADMIN IS RUNNING
Modify the phpMyAdmin configuration file to allow for .htaccess overrides
ADD: AllowOverride All UNDER DirectoryIndex index.php
Restart Apache
Postfix installation
Leave all settings default
Configure Postfix
FIND THE LINE inet_interfaces = ALL AND REPLACE WITH inet_interfaces = loopback-only
Restart Postfix
Send a test email from the command line
You should receive a test email. Check your spam as well.
Final update of the server
Final upgrade of the server. Select Y when prompted
Installls ZIP and UNZIP
Enables reqrite in Apache
Restart Apache
Installs SSL Engine
Reboots the server and makes it ready for production
Important: This installation guide is meant as a quick deployment solution. You will need to take additional steps to lock down the server and add your desired security methodologies and encryption methods. Use at your own risk