Learning Linux webserver deployment has been a great experience. I should have started my blog with this post because building a webserver using LAMP made my website possible! I originally took this project on to quench my thirst for learning new things. After building and rebuilding hosted virtual webservers for myself and others, I have a solid grasp on the process. The struggle of establishing and maintaining my webservers has given me a great sense of achievement. This is the basic process I follow mixed with my growing experience on the topic.
Build the server
As I stated, I use a hosted virtual server. The first step in this process is to pick which hosting service to use. There are plenty of options that offer competitive pricing per hardware specifications! The list is long but to give you general idea there is Linode, DigitalOcean, Atlantic, Google’s Cloud platform and Amazon AWS. Also if you are intrigued by running a wordpress site there are more cookie cutter deployments like Godaddy, Site5 and even WordPress.com that require less technical knowledge. I personally chose Linode because at the time they were offering the most competitive deal! Once the account was setup I deployed my Linode. To do this. select your Linode and then click deploy image. Here you can select which version of Linux to deploy, disk size and root password. I chose Debian. At this point, I could boot the server and log in via SSH!
Once Connected its time to update and start installing LAMP. First, update the server with command:
- sudo apt-get update && sudo apt-get upgrade
Next create a new user to avoid running all commands directly as the root user. It is also helpful to give this user sudo privileges which will allow it to temporarily run commands as root much like the elevated command prompt in windows. Here is a great guide for doing this process which I will skip over.
- adduser newusername
That is basically it for deploying and building out your initial server. There are some extra steps I would recommend to secure your server from external attacks. I will post about this another time.
The basic installation of LAMP is quick and simple. Linux has already been installed which covers the “L”. Now it is time for Apache2, MySQL, and PHP. Here are the basic commands assuming your are connected as the newuser that was created previously.
- sudo apt-get install apache2
This command installs Apache2. There are several optimizations that can be made to the apache.conf file to increase it’s performance based on your virtual servers specifications. But I am going to keep it simple. I also am confident an array of guides already exist on this. So, now install MySQL!
- sudo apt-get install mysql-server
This will prompt you to enter a new root password. This is for the root MySQL user though so it can be different from the servers root user password. Next, do the quick MySQL secure setup.
- sudo mysql_secure_installation
The MySQL Secure utility will appear and guide you through removing anon accounts, disabling remote login and removing the test database. Again, there are options to optimize the mysql.cnf file to boost performance based on the webservers hardware. Also at some point a database will need to be created or imported if you want to setup a WordPress site. In an attempt to keep this short, I will skip this and move on to installing PHP.
- sudo apt-get install php5 php-pear
- sudo apt-get install php5-mysql
These two commands install PHP and the MySQL extension for PHP. Yet again, there are more configurations that can be made to the php.ini file to optimize performance.
It’s time to celebrate because building a webserver using LAMP has been completed! The basic framework for hosting your own site on your own server is laid out. There are more steps to be done which I will create separate posts for. Configuring name based virtual hosts is a must and allows your webserver to host several sites. Installing PHPmyadmin is also useful and much easier for myself to navigate MySQL. Also securing your VPS is a great idea.