Jul
5
Installing a Web Server on Your Old Laptop
July 5, 2009 | By: UbuntuLinuxHelp | 1 Comment
Posted in Linux Projects - Hands On
- Build a Web Developer PC and Enable Most Media Playback Using Ubuntu Linux
- Installing Compass on Ubuntu
- Installing a Web Server on Your Old Laptop
- Building a Web Developer / Designer PC Using Ubuntu Linux – Revisited
- Faster Internet With an Old Laptop – Ubuntu and Squid
- Faster Internet With an Old Laptop – Revisited
In an earlier post to this series, I talked about converting an old ancient IBM Thinkpad T22 Laptop into a proxy server (using Squid). While this did substantially improve my web surfing speed, it occurred to me that the laptop could be put to more use. One example is to install MediaWiki on it (to replace the Tomboy Notes application I use). In reality, I was surprised at the performance given the lack of hardware resources on this laptop, as such, I knew it could be put to more use.
One thing you'll notice in this post is that the command line does not use "sudo". This is because the last post configured the server to permit root logins via SSH. In fact, there is a lot of information in the last post that directly relates to (or effects) what we'll do in this one, again, please read it: Faster Internet With an Old Laptop – Ubuntu and Squid. Otherwise some of us might get a bit lost trying to complete the hands-on activities in this post. Also a reminder that this is an Ubuntu server 8.04 LTS, if using other versions of Ubuntu (or other Debian based distributions, you'll probably need to make a few adjustments).
In order to make this old laptop even more useful, in addition to the previously installed Squid proxy server, we're going to add an Apache webserver with PHP, MySQL database server and Mail server (SMTP/POP3). The mailserver is just for the future in the event it's needed or any PHP based package requires it (so you can skip that if you don't need it). More importantly, Apache and MySQL are needed so I can successfully install and use MediaWiki.
First SSH into your server. The command for me is:
ssh root@squid.localdomain (You'll need to substitute the hostname you chose for your server).
Let's get some packages for compiling, zip, perl, ssl, certificates and so on. Remember, because you logged in as root, you don't have to "sudo".
aptitude install binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libcompress-zlib-perl libdb4.3-dev libpcre3 libpopt-dev lynx m4 make ncftp nmap openssl perl perl-modules unzip zip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g++ build-essential
Let's get the database server installed and configured;
aptitude install mysql-server mysql-client libmysqlclient15-dev
During the installation of MySQL, you'll be asked to provide and confirm a new MySQL root password. DO NOT FORGET IT! (as the MySQL root password is not going to be the same as your system root password - Right?) You can use upper case and lower case letters, numbers and special characters. To check that MySQL is listening for connections, use the netstat command:
root@squid:~# netstat -tap | grep mysql
tcp 0 0 localhost.localdo:mysql *:* LISTEN 28746/mysqld
See how MySQL is only listening on localhost?
For future projects, I don't want the database server to listen only on the localhost, I want it to listen on any interfaces. This is simple to do when editing the configuration file:
nano /etc/mysql/my.cnf
Look for: bind-address = 127.0.0.1
And comment out (#) that line. The line should now look like this:
# bind-address = 127.0.0.1
Doing this does make it less secure, but this is on an internal network, not a public one. Also, note that the default port is 3306, if you ever need to change the port, this is the file you can edit. However, to keep it simple, leave the default port as is.
When done editing, Ctrl o will save the file and Ctrl x will exit nano.
Restart MySQL so the new setting takes effect:
/etc/init.d/mysql restart
Let's check to see if our settings work:
netstat -tap | grep mysql
You should see something similar to this:
root@squid:~# netstat -tap | grep mysql
tcp 0 0 *:mysql *:* LISTEN 28895/mysqld
Note that there is no mention of localhost!
I like using phpMyAdmin to manage the DB server via Firefox:
aptitude install phpmyadmin
When prompted, select the option "apache2"
After the install, you can visit the URL: squid.localdomain/phpmyadmin (substitute you own URL, which may be different from mine).
Use the login credentials that you created when installing and configuring MySQL:
Username = root
Password = The MySQL password (not the normal root password used to login).
If you've forgotten the MySQL root password, you can reset it. Here are the steps to fix the "forgot root MySQL password" issue (this has happened to me a few times):
Stop the DB server:
/etc/init.d/mysql stop
Restart MySQL without it accessing the user information (user tables):
mysql mysqld_safe --skip-grant-table &
Now connect to MySQL using the MySQL root account (you won't need a password):
mysql -u root
Finally change the password via these commands:
use mysql;
UPDATE user SET password=PASSWORD('enter-new-password-here') WHERE user = 'root';
flush privileges;
exit;
Currently I only intend to run MediaWiki to replace Tomboy notes (which I've probably mentioned a few too many times now), but perhaps I might add a couple other PHP based sites in the future. Some of them may require email connectivity. Let's put something in place now (Postfix, Courier).
aptitude install postfix procmail
When issuing the above command, I received the following output:
root@squid:~# aptitude install postfix procmail
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Building tag database... Done
The following packages are BROKEN:
sendmail
The following packages will be automatically REMOVED:
sendmail-bin
The following packages have been kept back:
apt apt-utils cron dash initscripts libcurl3-gnutls libkrb53 libssl0.9.8
libvolume-id0 linux-image-2.6.24-23-server linux-image-server
linux-server linux-ubuntu-modules-2.6.24-23-server python-apt sudo
sysv-rc sysvutils tasksel tasksel-data tzdata udev update-manager-core
The following NEW packages will be installed:
postfix
The following packages will be REMOVED:
sendmail-bin
0 packages upgraded, 1 newly installed, 1 to remove and 22 not upgraded.
Need to get 1160kB of archives. After unpacking 799kB will be used.
The following packages have unmet dependencies:
sendmail: Depends: sendmail-bin but it is not installable
Resolving dependencies...
The following actions will resolve these dependencies:
Remove the following packages:
sendmail
Score is 121
Accept this solution? [Y/n/q/?]
I selected Y (yes) to remove the (broken) sendmail package and install the remainder. After accepting the above solution, I saw the following (further) output:
Accept this solution? [Y/n/q/?] Y
The following packages are unused and will be REMOVED:
procmail sensible-mda
The following packages will be automatically REMOVED:
sendmail sendmail-bin
The following packages have been kept back:
apt apt-utils cron dash initscripts libcurl3-gnutls libkrb53 libssl0.9.8
libvolume-id0 linux-image-2.6.24-23-server linux-image-server
linux-server linux-ubuntu-modules-2.6.24-23-server python-apt sudo
sysv-rc sysvutils tasksel tasksel-data tzdata udev update-manager-core
The following NEW packages will be installed:
postfix
The following packages will be REMOVED:
sendmail sendmail-bin
0 packages upgraded, 1 newly installed, 4 to remove and 22 not upgraded.
Need to get 1160kB of archives. After unpacking 102kB will be freed.
Do you want to continue? [Y/n/?]
The install will give you some prompts (questions) to answer. Here's how I answered them:
General type of mail configuration:
Internet Site
System mail name:
squid.localdomain (Your's may be different, so make sure you input the correct name).
I noticed that the installation for procmail did not go through, so:
aptitude install procmail
We can always configure postfix later when needed, but let's do a quick tweak of it now:
dpkg-reconfigure postfix
For "General type of mail configuration", leave the setting we already made (Internet Site).
Also leave our "System mail name" as the one we just defined (squid.localdomain) - Again, your name may have been different.
For the "Root and postmaster mail recipient", we don't want to add any aliases, therefore leave this blank.
In the next prompt we see "Other destination to accept mail for (blank for none)". It should be pre-populated with something like this:
squid.localdomain, localhost.localdomain, , localhost
Yes, let's add this (by selecting "ok").
No, we do not want to "Force synchronous updates on mail queue".
The next section that asks about "Local Networks", populating the input fields with something like this:
127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
Select "ok".
"Use procmail for local delivery" - Select Yes!
We don't need a limit on mailbox files. In the next windows make sure the entry is "0" and select "ok".
"Local address extension character" prepopulated with "+", leave it as is, select "ok".
Finally, "Internet protocols to use", select "all" and "ok".
Start Postfix with /etc/init.d/postfix start, however if you need to make changes manually (to /etc/postfix/main.cf), remember to reload postfix with /etc/init.d/postfix reload
Installing courier:
aptitude install courier-authdaemon courier-base courier-imap courier-pop gamin libgamin0 libglib2.0-0
During the installation, you'll receive a prompt asking "Create directories for web-based administration", select "No".
Quick tweak: Let's configure postfix to drop mail to the users Maildir. We can issue the following command to do this:
postconf -e 'home_mailbox = Maildir/' && postconf -e 'mailbox_command =' && /etc/init.d/postfix restart
Finally let's get Apache and PHP installed. I'm going to install PHP as a module, not as CGI, because I want to be able to easily change the configuration settings using directives in Apache configuration files (such as httpd.conf) and .htaccess files.
First, let's get Apache going:
aptitude install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert
I received some errors in the output:
.
.
.
Get:3 http://ca.archive.ubuntu.com hardy/main libaprutil1 1.2.12+dfsg-3 [70.0kB]
Err http://ca.archive.ubuntu.com hardy-updates/main apache2-utils 2.2.8-1ubuntu0.5
404 Not Found [IP: 91.189.88.46 80]
Err http://security.ubuntu.com hardy-security/main apache2-utils 2.2.8-1ubuntu0.5
404 Not Found
Err http://security.ubuntu.com hardy-security/main apache2.2-common 2.2.8-1ubuntu0.5
404 Not Found
Err http://security.ubuntu.com hardy-security/main apache2-mpm-prefork 2.2.8-1ubuntu0.5
404 Not Found
Err http://security.ubuntu.com hardy-security/main apache2 2.2.8-1ubuntu0.5
404 Not Found
Err http://security.ubuntu.com hardy-security/main apache2-doc 2.2.8-1ubuntu0.5
404 Not Found
Fetched 478kB in 2s (180kB/s)
Selecting previously deselected package libapr1.
.
.
.
If you get this error, try updating the repositiries like this:
aptitude update
The reissue the installation command.
Now that Apache is installed, let's get PHP and related packages:
aptitude install libapache2-mod-php5 libapache2-php5 php5-common php5-curl php5-dev php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
From dealing with other web servers, I've often found that I need to add the appropriate directives to Apache's dir.conf file (because they will not all be included):
nano /etc/apache2/mods-available/dir.conf
You should see this line:
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
Change it to this:
DirectoryIndex index.html index.shtml index.xhtml index.htm index.php index.php3 index.pl index.cgi
We also need to enable the rewrite, include and SSL modules:
a2enmod rewrite && a2enmod include && a2enmod ssl
You'll get a prompt that tells you to run the command:
/etc/init.d/apache2 force-reload
You should get a success message like:
root@squid:~# /etc/init.d/apache2 force-reload
* Reloading web server config apache2 [ OK ]
Side note: If you need to disable a module, the command would be a2dismod, and an example would look something like: a2dismod ssl && /etc/init.d/apache2 force-reload I generally prefer to disable instead of delete as one never know if a module might be needed in the future (or if disabling causes an error). It's usually a simpler fix to re-enable a module.
Lets get FTP going:
aptitude install proftpd
You'll see a prompt asking you how to "Run proftpd". I'm selecting "Standalone" because I want the ability to restart proftpd (or stop it) if needed. It will create the directory /home/ftp on your server. Here's some of the output of that command:
Adding system user `proftpd' (UID 114) ...
Adding new user `proftpd' (UID 114) with group `nogroup' ...
Not creating home directory `/var/run/proftpd'.
Adding system user `ftp' (UID 115) ...
Adding new user `ftp' (UID 115) with group `nogroup' ...
Creating home directory `/home/ftp' ...
`/usr/share/proftpd/templates/welcome.msg' -> `/home/ftp/welcome.msg.proftpd-new'
ProFTPd is started from inetd/xinetd.
Side note: If you ever need to restart the FTP server (after changing a configuration), the command would usually be: /etc/init.d/proftpd restart
For those who followed on from the original Squid installation post, we now need to access Webmin. For me the Firefox URL is:
http://squid.localdomain:26395/ (remember, use your server's correct url and port number).
After logging in, select "Refresh Modules" and see an output similar to mine below:
Checking for usable Webmin modules ..
.. found 58 with installed applications, 46 not installed.
Now select "Servers" and you should see that:
Apache Webserver
Fetchmail Mail Retrieval
MySQL Database Server
Postfix Mail Server
ProFTPD Server
Procmail Mail Filter
have been added to the list. (Originally there was only Read User mail, SSH Server and Squid Proxy Server).
Finally, visit the URL of your nifty web server on Ubuntu, my URL would be:
squid.localdomain (once again, substitute the URL of your server).
And you'll see the "It works!" message.
By default root is denied the ability to log in via FTP. Because this is my local network, I'll allow root to access FTP. DO NOT do this is a public environment!
Still in Webmin, select "ProFTPD Server" (listed under "Servers"), then select the "Denied FTP Users" icon. This will open /etc/ftpusers, and display the following directives:
# /etc/ftpusers: list of users disallowed FTP access. See ftpusers(5). root daemon bin sys sync games man lp mail news uucp nobody
Find: root
and remove it from the list. Click "Save".
Now we'll need to allow root in the proftpd.conf via our command line, like this:
nano /etc/proftpd/proftpd.conf
Look for:
# Set the user and group that the server normally runs at.
User proftpd
Group nogroup
And underneath the above add:
# Permit root logins
RootLogin on
Side note: If you ever need to reconfigure proftpd (to use inetd instead of standalone for example), the command is: dpkg-reconfigure proftpd
In your terminal, restart FTP so that root will now be allowed:
/etc/init.d/proftpd restart
root can now login and transfer files via FTP.
To change pages that Apache serves, you should be uploading files to:
/var/www
Guess what? We're done!
While in the Webmin interface I noticed that I had to fix an issue from the last post:
Error: The Squid cache manager program /usr/lib/cgi-bin/cachemgr.cgi was not found on your system. Maybe your module configuration is incorrect.
I encountered this error when trying to access the "Cache Manager Statistics" under "Squid Proxy Server".
/usr/local/squid/etc/squid.conf
Fix:
aptitude install squid-cgi
Related posts:
- Installing ffmpeg-php on an Ubuntu 9.04 LAMP Server
- Faster Internet With an Old Laptop – Ubuntu and Squid
- Installing an Ubuntu Linux Hardy 8.04 LAMP and FFMpeg Server With a GUI – Installation of OpenSSH.
- Faster Internet With an Old Laptop – Revisited
- Installing an Ubuntu Linux Hardy 8.04 LAMP and FFMpeg Server With a GUI – LAMP installation with cgi-bin

(14 votes, average: 4.71 out of 5)
[...] Installing a Web Server on Your Old Laptop Posted by suvi under Webserver New tutorial added to HowtoMatrix database. Installing a Web Server on Your Old Laptop This entry is part 5 of 5 in the series Building a Web Developer / Designer PCIn an earlier post to this series, I talked about converting an old ancient IBM Thinkpad T22 Laptop into a proxy server (using Squid). While this did substantially improve my web surfing speed, it occurred to me that the [...] Link to the original site [...]