This article explains some very basic linux commands an facts needed when setting up and working with a web server. Note that this article isn’t covering all about Debian, in fact covers a very few but important knowledge one may need.

This article contains information mainly for beginners.

Some useful facts

  • under Linux, everything is a file. Even a device, such as a HDD or port
  • files have no extension. In fact the can have but files aren’t recognized by extension. Thus, in a file named ‘aaa’ you can put a wav sound, a text, or anything binary. File names are case-sensitive!
  • you can add/remove software (packages) with apt-get. There are no two similarly named packages in Linux. These programs/packages usually hold their config files under /etc
  • there are programs or services. Programs are like a text editor. You can run many instances and you can exit them. Services are running in background (eg. ftp, apache).
  • the main system is text-based. You must write at the command prompt to interact with the system. BTW everything is very simple and archaic…

To log in or log out

Logging in is automatically initiated. Without logging in you can’t do anything, even you can’t stop the server (except pressing the power button to initiate shutdown)

To log out use:

logout

To start/stop/reboot the machine

Use one of the following:

reboot
halt
shutdown -h now

To see what’s here (files and directories here)

ls
ls -l
ls --help

To change directory

cd lower_dir
cd /absolute_dir/dir/dir

You may want to see more files/directories so install the Linux’s Norton Commander-like app, Midnight Commander:

apt-get install mc
mc

See the free space

df
df -h

Change the permissions over files and dirs

chmod 0xxx filedir
chmod --help

You can read more about permissions at wiki.debian.org.

To manage running services

If you change a service’s config, you must restart the service.

/etc/init.d/xxxxx restart
/etc/init.d/xxxxx stop
/etc/init.d/xxxxx start
service xxxxx restart
service xxxxx stop
service xxxxx start

Replace xxxxx with the service name.

[To be continued…]

With a Samba server installed and running on Linux, we can access partly or the whole system via LAN.

Install Samba:

apt-get install samba

Follow the install wizard and enter “workgroup” or the group your network uses.

The outside access can be configured for a special directory and for a special user or it’s possible to see the entire system. The latter can be used for administration purposes via LAN, but it’s not recommended for production servers or for paranoiac users.

Set up restricted access

  1. (On the server) add a directory for samba shares
    mkdir /samba

    (Change the /samba directory according to your needs)

  2. Add a usergroup for samba
    groupadd sambagroup
  3. Give the directory to the group
    chgrp sambagroup /samba
  4. Change the rights
    chmod 0777 /samba
  5. Add a user
    useradd -g sambagroup winuser
  6. Give the user a password
    passwd winuser
  7. Add samba password. This will be the password to access the server.
    smbpasswd -a winuser
  8. Enable user in samba
    smbpasswd -e winuser
  9. Add the following to /etc/samba/smb.conf. Change the SambaShareName to a nice one.
    [SambaShareName]
    path = /samba
    writable = yes
    public = no
    valid users = winuser
    force create mode = 0777
    force directory mode = 0777
  10. Restart the Samba server (every time you make changes to /etc/samba/smb.conf, the Samba server needs to be restarted).
    /etc/init.d/samba restart

Set up full access

It’s not a problem to give full access to the whole system if the server isn’t accessible from outside the router or the local area network is accessed only by the developer(s).

  1. Add samba password
    smbpasswd -a root
  2. Enable user in samba
    smbpasswd -e root
  3. Add the following to /etc/samba/smb.conf
    [SambaShareName]
    path=/
    writable=yes
    public=no
    valid users=root
    force create mode = 0777
    force directory mode = 0777
  4. Restart the Samba server
    /etc/init.d/samba restart

Note: in a Windows system, you will see the server as “SambaShareName”. Change this name accordingly.

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.