How to install, configure and work a LAMP stack with FTP access

Thursday, February 11, 2010 by BBTUNA
How to set up your LAMP stack.

First off I will talk about what exactly a LAMP stack is.

LAMP stands for Linux Apache MySQL PHP (this can sometimes be replaced with Python). Lets break this down.

Linux- Linux/ Unix is the leading OS for web servers due to low resource usage allowing for faster load times and high up-time.

Apache- Apache is the actual service that Hosts the website and turns your box into a usable webhost.

MySQL- is a dynamic database that is able to hold almost any information. This stores information that is then pulled by PHP or another server side language.

PHP- A high powered dynamic internet language derived from the GPL (General Programing Language) Perl. This is used to display dynamic content.

Now that we have a brief understanding of what exactly we are doing we will now be able to begin.

Before I get started as to how to do everything I would like to mention I am running Ubuntu Server Edition 7.04 (32 bit). I am also assuming you have basic understanding of Linux/ Unix along with general computing knowledge.

Once logged on to our Linux box we will need to download and install our Apache server, surprisingly enough it is incredibly simple. Just type:

sudo apt-get install apache2 mysql-server php5 libapache2-mod-php5 php5-xsl php5-gd php-pear libapache2-mod-auth-mysql php5-mysql

This will take a few moments to install and download.

Once that is up and working we will restart the LAMP server by using:

sudo /etc/init.d/apache2 restart


Now lets make it work! We will configure Apache by using a simple Linux based text editor called nano. (I am using nano in this tutorial instead of vi for the simplicity of nano to a beginner). Unlike so many other services you do not need to directly configure your apache config. And before we move on we will need to make a new directory so type in the following:

sudo mkdir /home/[username here]/www/
sudo chmod 755 /home/[username here]/www/


With that made lets do some small bits of configuring. We will use our nano editor to edit our sites available list by running the following:

sudo cp /etc/apache2/sites-available/default / etc/apache2/sites-available/mysite
sudo nano etc/apache2/sites-available/mysite


That bit there copies the file “default” and renames it “mysite” and the second line opens it for editing. Here is what we need to change:

Change this:

DocumentRoot /var/www

Options FollowSymLinks
AllowOverride None



To:

DocumentRoot /home/[username here]/www

Options FollowSymLinks
AllowOverride None



Now hit ctrl + O to save. Then ctrl + Z to close the file.

Next we use a pretty little Linux trick that deactivates the “default” site with “mysite”

sudo a2dissite default && sudo a2ensite mysite

And finally you will need to restart your Apache server just as we did before.

SO! Lets test it out! We will need to give our new web server something to display so lets keep it simple with the following script:

echo 'Hello! It is working!' > /home/[username here]/www/index.html

Done that? GREAT!

Now lets take a look open up a web browser and type in the internal address of that machine (if you are testing this on the same machine it is installed on the universal internal IP for localhost is 127.0.0.1)
So as a URL you would type http://address-of-machine As an example mine was http://192.168.1.67
If it works you should see the message “Hello! It is working!”

Lets advance a little bit though. This is all fine and dandy if you are on a LAN with this machine, but what about over the World Wide Web? Well this is automatically listening on port 80, unfortunately most ISPs HATE people using this port so I will show you how to change the listen port of the server. Simple use nano to change the apache port list.

sudo nano /etc/apache2/ports.conf

It will by default say

Listen 80


Listen 443


change this to:

Listen 8000


Listen 443



Perfect! Now after you restart the Apache service once more we will be listening on a unrestricted port! The only thing that has changed is the way we access the webpage. Instead of typing http://192.168.1.67 we now type http://192.168.1.67:8000
Log into your router forward port 8000 to the internal address of the LAMP stack and we are good to go.

You now have a fully functional LAMP stack that will host anything just as a paid host will (it won’t have a domain name as you need to set that up which will not be covered in this tutorial)

To make this a little more complete I am going to go one step further and show you how to gain FTP access to your new LAMP stack!

We will now download a service called proftpd. Do this by typing:

sudo apt-get install proftpd


Simple enough, just as a side note I recommend installing it as a standalone. Now to our lovely friend NANO and do some configuring!
Find the line that defines the following:

# Use this to jail all users in their homes
#DefaultRoot ~

and change it to:

# Use this to jail all users in their homes
DefaultRoot /home/[username here]/www

Just note exactly what we did. We changed it so that anyone who logs into the FTP will only have FTP access over the web server files AND we had to uncomment (remove the ‘#’).
Before I forget I want to say we edit the FTP config with the following:

sudo nano /etc/proftpd/proftpd.conf


Also note that most ISPs block port 21 (FTP port) so we will change that as well.

So find the line:

# Port 21 is the standard FTP port.
Port 21

And change it to:

# Port 21 is the standard FTP port.
Port 2121


Now forward the port 2121 to your LAMP stack as well. Following that we will restart the FTP service by typing:

sudo /etc/init.d/proftpd restart


LETS TRY CONNECTING!
Open FTP and connect to the address of you LAMP stack on port 2121
So for example on MS command based FTP it would be:

open 192.168.1.68 2121

and log in using the credentials to your Linux box.

TA DA! Now you have a working webhost with full FTP access!
Posted in | 0 Comments »

0 comments:

Post a Comment

About Me

Blog Archive