5 Jan / 2013

Set up a web development Linux server (Debian)

At first glance localhost seems to be a good solution for developing PHP web apps, but it has some drawbacks, as:

  • switching between projects isn’t so easy for moderately complex websites, especially when working with databases, having fixed directory structure, etc.)
  • it’s difficult to change the server (Apache) configuration
  • it’s difficult to switch between projects
  • some features can be tested only on a physical (or virtual) server(s) (memcached, network file systems, mysql-based ftp login, etc.)

Setting up a Linux server it’s easier than I thought first… OK, at the beginning I read tons of documentation and spent many hours to find information on the internet to set up and configure everything as needed.

The server will have these features (packages installed):

  • Apache 2
  • PHP5 (+gdi, MYSQL)
  • MYSQL
  • FTP
  • Samba to access the server directly from Windows

Here we start…

This article is based on a Debian 6 installation. Over time – as Debian evolves – differences in the namings and setup process may change.

You can use a virtual machine (recommended) or a physical computer.

What do you need for a virtual machine?

  • download and install the vmware player from vmware.com.
  • download the latest Debian net install ISO file (32-bit or 64-bit)
  • start the vmware player, create a new virtual machine by following the wizard. To read more about creating the vmware virtual machine, read this article.

What do you need for a physical machine?

  • an older computer (a second-hand it’s good if purchased), having a decent processor, at least 512mb of RAM and a decent HDD (10-20Gb it’s enough for simple development)
  • connect the computer to the network and use a temporary monitor for installing the OS
  • write a CD with the desired Debian (32/64-bit) and start installing

For both virtual/physical configurations you will need a network router. Connect your computer and the physical Linux server to this router. Later you may want to change the router’s settings in order to have access to the server from outside of your LAN.

Next, for both cases, virtual or physical server, install the Debian OS.

Take a blank paper or create a new text file on an another machine and note everything you enter (names, passwords, etc.) during the installation!

  1. Boot from the CD and wait for the Installer boot menu. Choose “Install”.
  2. Choose “English” for the installation process
  3. Choose your exact location. It’s important to set up correctly the time zone and to reach automatically the nearest servers for the extra packages that will be installed lately
  4. Configure locales. Choose “United States – en_us UTF-8”. Note that it’s best to use UTF-8
  5. Select the keyboard layout. As programmer, you may want the default “American English”
  6. The installer will begin to install the basic packages then prompts for the network config. Use any “hostname” you want
  7. For “Domain name” you may write anything or leave it blank
  8. Enter and re-enter the root password. If you wish to use the server only inside LAN, you may enter a weak password because you will enter this password frequently in the future. If you wish to reach the server also from the internet, a strong password is recommended!
  9. Create a non-root user; enter the names and passwords.
  10. Set-up the disk partitioning as you wish. The easiest way is to use “Guided – use entire disk” – “All files in one partition”
  11. Wait for the “installing the bases system” finishes and the choose the “Debian archive mirror country”.
  12. An important step, choose what extra packages to install on the system. The best choice is to install ONLY the “Standard system utilities”. Don’t install the “Graphical desktop environment” as you will not use this and it will eat up only valuable system resources.
  13. Choose “Yes” when asking to install GRUB boot loader.

At this point the system should restart without problems. Log in with the username ‘root’ and given  password. If everything works, the first stage it’s finished.

Before using the server, a lot of stuff has to be installed. Until now, we installed the system without anything extra to let you choose and install only the packages you want to use later.

Install the basic packages and configure network

Basically the server doesn’t needs a separate, physical monitor because it will be accessed remotely. So you can place the physical machine everywhere, preferable far away from living spaces to exclude the electron smog and noise created by running machine. To access remotely the server, use the putty.exe (download the putty.exe from putty.org and copy to c:\windows folder). But first let’s configure the access:

Install SSH

SSH is needed to access the server remotely via putty.

apt-get install ssh

Install Midnight Commander

apt-get install mc

To start the Midnight-commander, enter ‘mc’. You will need this app to edit configuration files more easy.

Set up a fixed IP address for the server

Start mc. Go to /etc/network and edit the interfaces file.

First comment out the line

# iface eth0 inet dhcp

then add to the end of the file:

iface eth0 inet static
address 192.168.1.xxx
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

Notes:

  • we assume that your router is configured as 192.168.1.x. If there are other values in the network configuration, change the values accordingly.
  • replace xxx with the desired number for the server. Make sure that no other devices are set up with the xxx number.
  • replace the 192.168.1.1 with the router’s address

Reboot the server. If some processes fail to start, check the interfaces file and/or reboot the router. If everything seems to be OK, you may check the ip address from your Windows machine by starting cmd and typing

ping 192.168.1.xxx

If it’s working, we’re finished in the front of the server so we can access it remotely via putty:

  • At your Windows machine: Start -> run-> putty.exe (works only if you previously downloaded and copied putty.exe to c:\windows)
  • Enter the 192.168.1.xxx address to “Host name (or IP address)”. Use “Port” 22
  • Make sure “SSH” is checked
  • Give a name at “Saved Sessions”
  • Optionally you may change at Window -> Translation the “remote Character Set” to UTF-8
  • Save the session for future use
  • Click the “Open” button (A dialog may pop up about a missing registry value)

At this point you should see the server’s login prompt. Use the root/password combination to log in, it should work fine.

Notes regarding login-logout and restarting/stopping the remote server:

  • use logout to log out
  • use reboot to restart the server
  • use halt to stop the server

(Read more about useful Linux commands and facts).

Installing the packages needed for the web server

Install Apache

apt-get install apache2

Enable the rewrite engine (for using SEO-friendly url’s)

a2enmod rewrite

To set up domains/subdomains on LAN, please read this article.

Install MySQL

apt-get install mysql-server mysql-client

To log in into MySQL and execute SQL commands, use:

mysql -uroot -p

Install PHP5

apt-get install php5

You may want to install extra PHP packages:

apt-get install php5-mysql
apt-get install php5-gd
apt-get install php5-imagick

Important note: in order to activate the PHP5 plugin in Apache, you must restart the Apache service

service apache2 restart

or

/etc/init.d/apache2 restart

It’s best to restart the server before testing the installations…

To test the web server, open a browser on the Windows machine and type 192.168.1.xxx and press enter at the address bar. Yo should see “It Works!“. If you see a blank page or ‘The page cannot be found’, there is an error that may be:

  • the ip address isn’t the server’s address (check with cmd -> ping 192.168.1.xxx)
  • the Apache service isn’t running on the server (check with ps aux | less)
  • the Apache service is running, but after some installation(s) something wasn’t restarted (restart the server)

There’s more…

At this point you have a very basic, but working web server. In order to start developing, you will need a Samba of FTP access to edit the php files on the server. Please follow the Samba or FTP articles to set up these.

Leave a Reply

Your email address will not be published. Required fields are marked *

Blue Captcha Image
Refresh

*