Today I’m going to show you how to set up a LEMP server (Linux NginX MariaDB PHP) on an Ubuntu 14.04. It’s a relatively easy process once you’ve done it a few times, but there are some things that can trip you up, so I thought I’d document it and present it here.
This assumes you’re using a fresh install of Ubuntu 14.04, and it’s not a crucial step in the process if your server is already set up. But we want to create an environment with a privileged user and prevent people from being able to login as root over SSH. This is just an extra precaution I like to do on servers I set up.
Log in to your user as root, and type in the following:
It doesn’t have to be “web” you can call it anything you want.
Add a password and there will be some prompts where you can add as much or as little information as you want for the account.
Then run the following command:
User privilege specification
and add the new account:
root ALL=(ALL:ALL) ALL
web ALL=(ALL:ALL) ALL
It should look like this:
Ctrl + X to exit, Y to save the file
Now we want to edit the SSH settings:
sudo nano /etc/ssh/sshd_config
Change the Port to something between 1025 and 65536. This just adds an extra step for attackers, and bots that scan for open port 22 won’t find your connection immediately.
Look for this line:
and change it to
This prevents people from logging into SSH as root.
As an additional step, let’s add the line:
so only the web user is allowed to log on to the server.
Restart the ssh server:
service ssh restart
Now before we log out, we want to test and make sure we can get back in.
ssh -p 4400 web@YourIPADDRESS
4400 is the port shown here, but it can be whatever you choose.
If you can log in fine, then you’ll be safe to exit out of your main session, and log back in as “web” (or whatever you used as a username).
Install the Web Server
first type in
sudo apt-get update
to update the system.
To install NginX:
sudo apt-get install nginx
In Ubuntu 14.04 it will automatically start up the service, and you should see this startup page:
Now your NginX server is set up so we’ll move on and modify it later.
Install the Web Server
We’re going to install MySQL on the server, but we’ll be using the MariaDB fork instead of the MySQL distribution, because it’s better in many ways.
For our install we’re using Ubuntu 14.04 and I want MariaDB 10, so here is how I set it up: