How to Set Up a LAMP server on Linode
- Why Linode and CentOS?
- Getting Started
- Connecting to Your Server
- Naming Your Server
- Final Server Setup
- Creating a Second User
- Securing Your Server Connections
- Lock Down Remote Access
- Setting up Your Firewall
- Installing Fail2Ban
- Installing Apache
- Installing MySQL
- Installing PHP
- Setting Up Your Domain
- Where to Go From Here?
Running your own web server is the ultimate level of technological freedom. Having a server to call your own allows you to do all kinds of things:
- Keep all of your files backed up in the cloud
- Host an email server
- Open a remote connection to your home network
- Run a private or public API
- And so much more!
In this tutorial, you’ll get a CentOS server set up with Linode, a cloud hosting company similar to Rackspace or Amazon Web Services. You’ll configure your server with a few bells and whistles and implement some simple security measures to help minimize your risk to outside attackers.
Note that Linode is a paid service and you’ll need to sign up for an account and pay to provision a new server instance to continue.
Why Linode and CentOS?
In contrast to Amazon’s AWS, Linode is a straightforward, fixed-cost hosting package. It fills the need for people who just need a small server up and running in minutes. Contrast this to getting an AWS EC2 instance for computing coupled with an EBS instance for disk storage, configuring them to talk to each other, routing traffic correctly, securing them, and so forth.
And most importantly, Linode is faster for basic operations.
CentOS stands for “Community Enterprise Operating System” and is considered to be an Open Source alternative to the highly popular Red Hat Enterprise Linux distribution used in most large companies. It offers the robustness and scale of Red Hat with the user-friendly features and great out-of-the-box support that Fedora and Ubuntu are known for.
Head to linode.com and click Sign Up in the top right corner of the header bar below:
Fill out the standard account details, such as user name, address and credit card info.
Select the first plan available: Linode 1024. This base option is enough to power a simple web site and is enough to get you started for the purposes of this tutorial. You can always instantly upgrade later should you run out of storage or bandwidth.
Click Continue, agree to the Terms of Service – after reading them, of course :] – and complete your order!
Creating your account can happen instantly, or it may take up to 15 minutes, depending on the options you selected during set up. Once you are notified that your account is ready to go, log in to Linode again and you’ll be prompted to pick an initial setup for your server.
The first question you’ll come across is picking a Data Center. It’s important to pick a location that is relevant to your usage. Typically you’ll want a location close to your users or close to your office to get the best response times.
Click Place this Linode here on the location you prefer, as shown below:
If you can’t be troubled to decide, pick Dallas as it’s middle of the road in the USA!
Next you’re provided with several options for customizing your server. Pick CentOS 6.4 from the Distribution drop-down. Next, since you’re paying for this server, you want to get the most out of it to meet your needs so set the Swap Disk to 512MB and max out the remaining Deployment Disk Size as shown in the screenshot below:
This configuration sets up your server with the most disk space possible for your configuration level.
Finally, create a root password for your server — make sure it’s a a good one! — then click Rebuild.
Your server is now being built to order! Watch the Host Job Queue section; once all of the tasks have completed with a “Success” result and the spinner dust settles, click the big Boot button in the Dashboard section shown below:
You now have your very own piece of real estate on the Internet! :]
You’re now ready to configure the server to your liking, including connecting to it remotely, securing the system, setting up LAMP, and getting a basic webpage up and running.
Time to get to work!
Connecting to Your Server
Click on the Remote Access menu at the top of the page; under the Public Network section you’ll see a list of instructions on how to connect to your server. Fire up Terminal (on a Mac) or a program like PuTTy (on a PC) and type in the appropriate command shown in the SSH Access row.
Note: SSH stands for Secure Shell; it’s a protocol just like HTTP and FTP that’s used to securely connect to another computer. Typically, you’ll use Terminal and SSH to connect to other computers that don’t provide a visual interface to the OS.
Each time you connect to a server, SSH checks that the server’s key is the same as last time. Since this is the first time you’ve logged into your server, SSH prompts you to check the key and add it to its key database. Since you’re an expert computer user and nothing could possibly go wrong — famous last words, perhaps? — just type yes and hit Enter, like so:
Now, simply enter the root password you created when you set up the server, and you’ll be sitting at the command prompt, as shown below:
Naming Your Server
The first thing you need to do is give your server a meaningful name — like a newborn baby!
The name can be anything, but it should be unique. Many times servers are named after collection of things that are near and dear to the creator of the server – like planets, Roman or Greek gods, cities, or Pokemon characters.
In corporate environments, server names are typically more boring but their name serves a purpose as it usually includes the server location and function. For example, “prodweb01” could mean “production web server #1”.
Choose a server name that has meaning to you. This tutorial pays homage to the lovable fallen planet, Pluto, so just replace ‘pluto’ with your server name in the examples that follow. There are three steps to set your server name — make sure you execute them in order and don’t skip one by mistake!
Enter the following command at your shell prompt:
echo "HOSTNAME=pluto" >> /etc/sysconfig/network
This above command updates a critical network file /etc/sysconfig/network on your server with your chosen server name.
Enter the second command as follows:
This sends an alert to all processes listening for updates from the
hostname process on the server that the servername has changed.
Finally, you’ll need to edit a configuration file on the server. Enter the third and final command as below:
This launches the nano text editor. /etc/hosts controls how Internet traffic is routed into and through your server.
Using the text editor, arrow down to the bottom of the file and add a new line. Enter the IP address of your server, hit the Tab key, then enter the name of your server. You can find your server’s IP address from the Linode dashboard (under the Remote Access tab).
For example, if your server’s IP is 192.168.99.42, enter
192.168.99.42 pluto in the hosts file. Hit Control-X (not Command-X) to exit the editor; press y to save your changes, then hit Enter to overwrite the existing hosts file.
Note: If your server will host a domain (like howtosetuplinode.com), then you’ll have to specify your servername in the hosts file as “server-name.domain-name.extension”. This is known as a fully qualified domain name, or FQDN. This tutorial does not require a FQDN, so if you don’t have a domain yet, don’t worry.
To test your new setup, exit your current SSH session:
Then SSH back in again, using the same command you used earlier. Your prompt should now show your new server name, like so:
Also try to ping your server like this:
It should ping your local machine, proving it works. Hit Ctrl-C to stop ping and return to your SSH session.