LAMP Server Setup: Part 1, The Basics

NyxCharon

Active Member
LAMP Server Setup
Part 1: The Basics​

LAMP?
What is LAMP you say? LAMP stands for Linux, Apache, MySQL, PHP. It's a typical setup for most web servers, and through this guide I'll show you how to do the initial setup. With this setup you'll be able to host your own site without having to pay anyone else hosting fees each month. DNS (Domain Name System) can be handled by your registar(more on that later) or can be done yourself (That's another part ;) )


Now, why would I want to go and do all of this?

Glad you asked. Well, for the first part, it's free. Windows Server 2008 ranges from $150 USD to the thousands depending on the number of servers you need to setup. Anyone who just wants a relativity small website and has little traffic might only need 1-3, so a couple hundred bucks. Or, you can install Apache on ANY distro of your choice, for free. This might be why Apache dominates a large part of the market. Some noteworthy Apache users include youtube, apple, yahoo and wikipedia.

Secondly, customability. You are no longer bound by your hosting company on what you can and can not upload, what tools you want, rules, restrictions, etc. Your only restrictions on what you can do this way is what is legal in your country. As far as tools,etc, well you can now choose and use whatever you like! You are not forced to use any specific OS. You can for the most part use any linux distribution to accomplish this task as long as you can setup everything properly, which allows you to be fairly comfortable with the OS in question.

Thirdly, security. In windows, you are usually logged in as a Administrator. A few linux OS's do make use of this setup as well, though not many. Most make use of a package called sudo. Sudo allows you to do administrative tasks, as long as you know the administrator password, without having to log in as a administrator or as it's known in the linux world as root. The administrative account is then locked. This means that anyone who wishes to break in must find a list of the accounts on the server, determine who has which privileges, then from there figure out a password for your account, and hopefully (as long as the password isn't the same) figure out the root password. Makes life a bit difficult. Next, since you host the webserver, if there is a break in, you'll be able to find out what went wrong and fix it immediately, instead of waiting for the web host to find out and fix it themselves. Which, depending on your web host, could take a small amount of time, or a extremely long amount of time. If you are not comfortable with this, you probably would have stopped reading by now :P

Initial Setup
Now that all the introductions are out of the way, let's get to business. First, we need to find a distro to host out server on. I use Crunchbang Linux for this purpose. You're going to want something lightweight, with little bloatware on, so try to find yourself a smaller distro, or if possible one with a net install option, so you can pick and choose what packages are installed. For this reason, I don't really suggest Ubuntu or any of the other novice linux distros for use. If you still want to use one of them, that's fine and it's your choice, merely a suggestion. Going a bit farther your are going to want something that uses a lightweight window manager (WM) to help free up resources. So Gnome and KDE are a no go. Something like openbox, Xfce, LXDE, etc. Or if you know what your are doing, you can do everything without X and a WM! You'll be working straight from the console terminal, and that's it.

Distro chosen, let's move on. Time to install the various packages needed. Most people will be using apt-get, however some distro's use different package managers, so I’ll include variations to try if yours doesn't use the first one listed.
Open up a terminal and type:
Code:
sudo apt-get install apache2 mysql-server php5 php-pear php5-gd php5-mysql php5-imagick php5-curl curl phpmyadmin rsync cronolog

Other common variations:
Code:
sudo rpm -i  apache2 mysql-server php5 php-pear php5-gd php5-mysql php5-imagick php5-curl curl phpmyadmin rsync cronolog
sudo dpkg -i  apache2 mysql-server php5 php-pear php5-gd php5-mysql php5-imagick php5-curl curl phpmyadmin rsync cronolog
sudo apt-rpm install  apache2 mysql-server php5 php-pear php5-gd php5-mysql php5-imagick php5-curl curl phpmyadmin rsync cronolog

So, what does all of that mean? Let's break it down. First, sudo. Sudo, as was explained before, is a way for you to execute a program or command as root, without being logged into the root account, for security reasons. Next apt-get/rpm/dpkg/apt-rpm. These are all the various package managers that any given distro could use, at least the most common ones. You'll notice some have a -i or install afterward, that's a argument or flag, that instructs the program what to do. In this case, -i stands for install. Taking it further, -u would update a given package. In apt's case, install or update are the arguments you can specify. There are of course many more, but that's all we need to know for this guide. Afterwords, all the names of the packages that are needed are listed. As you can see, you can just list them all out. If you wanted, you could install them all individually. In non-technical words, these set of commands would sound something like “Hey administrator! Can you go get these packages for me and then install them?”

Moving on if you get a error saying a certain package can't be found, you are going to need to do a google search for the repository for the package and add it to your sources list, again which the method in that this is done again varies distro to distro. From here, you'll begin downloading and installing each package. You'll be asked various setup questions, mainly passwords. Remember, we are setting up a site here, that anyone can access. Make great use of capital letters, numbers, and symbols, all in a long password. Don't use the same password for anything, to minimize the damage done if there ever is a problem. And please, please, do not store them in a text file or any file for that matter. If you've never been prompted in a terminal before, basic navigation is done via the arrow keys, enter confirms a selection/prompt, and space toggles selections.

Once this is done, give your system a quick reboot. Once you've rebooted, Apache should automatically be started. To verify, type 127.0.0.1 in the URL bar and hit enter. You should see a test page appear. The various commands for managing Apache are
Code:
sudo apachectl start
sudo apachectl restart
sudo apachectl stop
Alternatively:
Code:
sudo /etc/init.d/apache2 start 
sudo /etc/init.d/apache2 restart 
sudo /etc/init.d/apache2 stop
If Apache isn't starting at boot up for some reason, or you don't want it to be, your are going to need to manage the daemons that start at bootup. The method to do this again varies from distro to distro, so a google search will find the solution to that.

Well, what now?
So, Apache is running, what do we do now? Well, we are going to want to start writing some content for out site whether that be php, cgi,html,etc. For a complete in depth understanding of each of those languages, your are going to want to consult a good book or website. Alternatively, there are programs that take the coding out of the equation and just let you drag and drop and customize as you wish. I'll be covering the basics in another tutorial. On the other hand, to test your server at any time from the host computer, just type in 127.0.0.1 in the URL bar of any browser. If you want to access it from another computer on your LAN(Local Area Network), type ifconfig in the terminal of the host, and make note of the IP. Type this IP in the url bar on any other computers browser to preview the site. Your various files go in the /var/www folder, or you can always create a symlink(Symbolic link) to a place in your home folder for easy access

What's to come?
Quick review: We know what lamp stands for, we've picked a distro, and done basic setup and installation of packages. We did a small overview of basic security. We can view our site on the LAN from any computer on that LAN. From here, we'll be hardening the system, setting up BIND with a domain name, and going over basic HTML,PHP, and CGI programming and implementation.
 
Last edited:
Back
Top