Setup Linux web server - Install and configure Apache in Slackware

If you are planning on setting up your own web server (http server) using Slackware Linux, then the Apache http server would be the perfect choice. It is a stable and secure web server and works very well with Linux. Apache http server is The World’s #1 Web Server Tops Linux Journal’s Reader’s Choice Awards.

Check Apache web server in Slackware Linux

Before we begin installing Apache http server, let's check does it already exist in our Slackware system. If you install a fresh Slackware server dedicated for web server, then it's ok. But if this is an already running Slackware server or a training server, we need to know whether Apache is already installed so we can choose to upgrade the current Apache server or to re-install a new package.

Apache http server come in a package called httpd. To check httpd package in Slackware, we can view installed packages list in /var/log/packages directory. Here is the example:

[email protected]:~$ ls /var/log/packages/ | grep httpd
httpd-2.2.10-i486-1
[email protected]:~$

We can also use Slackware pkgtool utility to check httpd package. However, we need root privilege to use pkgtool. So switch to root using su command and enter the correct root password. See step by step example below:

[email protected]:~$ su -
Password:
[email protected]:~# pkgtool

In Slackware pkgtool, choose View menu. Wait a few seconds for Slackware to list all packages in the system. When it's done, press h letter to view all packages starting with h. Use down arrow key and search for httpd package. See example screenshot image below:

Check httpd package using Slackware pkgtool screenshot image

Press OK to see details about httpd package. Write down the version if you want.

Check httpd package details screenshot image

You can use ps command to check httpd daemon status:

[email protected]:~# ps aux | grep httpd
root 6241 0.0 0.3 8568 3312 ? Ss 11:03 0:00 /usr/sbin/httpd -k start
apache 6242 0.0 0.1 8700 2020 ? S 11:03 0:00 /usr/sbin/httpd -k start
apache 6243 0.0 0.1 8700 2020 ? S 11:03 0:00 /usr/sbin/httpd -k start
apache 6244 0.0 0.1 8700 2020 ? S 11:03 0:00 /usr/sbin/httpd -k start
apache 6245 0.0 0.1 8700 2020 ? S 11:03 0:00 /usr/sbin/httpd -k start
apache 6246 0.0 0.1 8700 2020 ? S 11:03 0:00 /usr/sbin/httpd -k start
root 6250 0.0 0.0 2084 632 pts/1 R+ 11:03 0:00 grep httpd
[email protected]:~#

All the results above shows that apache has been installed in my Slackware system. If you your result shows that Apache is not installed in your system, you can continue reading this tutorial, which will guide you on how to install Apache web server in Slackware Linux.

Install Apache httpd package in Slackware Linux

There are two ways on how to install Apache web server in Slackware. You can install Slackware httpd package which comes with Slackware installer dvd or you can install httpd source from Apache website. The former is the easiest and hustle free while the latter is having advantage to customize installation and get the latest Apache httpd source released. We'll see both examples in this tutorial.

Install official Slackware httpd package

Here is the step by step instructions on how to install Slackware httpd package.

1) Insert and mount Slackware installer dvd.

[email protected]:~# mount /dev/hda /mnt/dvd/
mount: block device /dev/hda is write-protected, mounting read-only
[email protected]:~#

2) Slackware httpd package is in /slackware/n directory. Use installpkg command to install the package.


[email protected]:~# installpkg /mnt/dvd/slackware/n/httpd-2.2.10-i486-1.tgz
Installing package httpd-2.2.10-i486-1 ([OPT])...
PACKAGE DESCRIPTION:
httpd: httpd (The Apache HTTP Server)
httpd:
httpd: Apache is an HTTP server designed as a plug-in replacement for the
httpd: NCSA HTTP server. It fixes numerous bugs in the NCSA server and
httpd: includes many frequently requested new features, and has an API which
httpd: allows it to be extended to meet users' needs more easily.
httpd:
httpd: Apache is the most popular web server in the known universe; over
httpd: half of the servers on the Internet are running Apache or one of
httpd: its variants.
httpd:
Executing install script for httpd-2.2.10-i486-1...

[email protected]:~#

Note: You can download dhcpd package from Slackware package website if you have trouble with your Slackware installer dvd.

If you already setup Slackware slackpkg package management system, you can use it to install httpd web server. See example below:

[email protected]:~# slackpkg install httpd

Install httpd using slackpkg screenshot image

Install Apache httpd source in Slackware Linux

Here is the step by step instructions on how to install Apache httpd source in Slackware.

1) Download latest httpd source from Apache official website.

2) Change directory to /usr/local/src (change to your chosen directory) and extract the httpd source:

[email protected]:/usr/local/src# tar zxvf /home/luzar/Desktop/httpd-2.2.11.tar.gz

Note: Provide the right path where your httpd source location is.

3) Change to the new extracted httpd directory:

[email protected]:/usr/local/src# cd httpd-2.2.11/

4) Open config.layout file using text editor and insert text below (There are configurations for other Linux distributions, freeBSD, openBSD, etc but no Slackware). You can check all these configurations in the Slackware httpd package (use explodepkg) to be sure that you follow Slackware standard.

# Layout for Slackware Linux

prefix: /usr
exec_prefix: ${prefix}
bindir: ${prefix}/bin
sbindir: ${prefix}/sbin
libdir: ${prefix}/lib
libexecdir: ${prefix}/lib/libexec
mandir: ${prefix}/man
sysconfdir: /etc/httpd
datadir: /var/www
installbuilddir: ${datadir}/build
errordir: ${datadir}/error
iconsdir: ${datadir}/icons
htdocsdir: ${datadir}/htdocs
manualdir: ${datadir}/manual
cgidir: ${datadir}/cgi-bin
includedir: ${exec_prefix}/include/httpd
localstatedir: /var
runtimedir: ${localstatedir}/run
logfiledir: ${localstatedir}/log/httpd
proxycachedir: ${localstatedir}/cache/httpd

5) Save config.layout file when you are done. The next step is we are going to run configure. See the example below:

[email protected]:/usr/local/src/httpd-2.2.11# ./configure --enable-layout=Slackware --enable-module=most --enable-mods-shared=most --enable-ssl=shared

6) Run make

[email protected]:/usr/local/src/httpd-2.2.11# make

7) Run make install

[email protected]:/usr/local/src/httpd-2.2.11# make install

That's it. Now we have Apache httpd installed in our Slackware server now. It's time to start the httpd service.

Start, stop and restart httpd (http daemon - Apache service) in Slackware Linux

All Slackware daemons can be found in /etc/rc.d/ directory. Slackware Apache daemon is rc.httpd. If you don't have rc.httpd in /etc/rc.d directory, you can copy the script below:

#!/bin/sh
#
# /etc/rc.d/rc.httpd
#
# Start/stop/restart/graceful[ly restart]/graceful[ly]-stop
# the Apache (httpd) web server.
#
# To make Apache start automatically at boot, make this
# file executable: chmod 755 /etc/rc.d/rc.httpd
#
# For information on these options, "man apachectl".

case "$1" in
'start')
/usr/sbin/apachectl -k start
;;
'stop')
/usr/sbin/apachectl -k stop
killall httpd
rm -f /var/run/httpd/*.pid
;;
'restart')
/usr/sbin/apachectl -k restart
;;
'graceful')
/usr/sbin/apachectl -k graceful
;;
'graceful-stop')
/usr/sbin/apachectl -k graceful-stop
;;
*)
echo "Usage: $0 {start|stop|restart|graceful|graceful-stop}"
;;
esac

Change /etc/rc.d/rc.httpd permission to make it starts during reboot:

[email protected]:/etc/rc.d# chmod 755 rc.httpd

Here is the command to start Apache httpd service in Slackware:

[email protected]:~# /etc/rc.d/rc.httpd start
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[email protected]:~#

Here is a command to restart Apache httpd service in Slackware:

[email protected]:~# /etc/rc.d/rc.httpd restart
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[email protected]:~#

Here is a command to stop Apache httpd service in Slackware:

[email protected]:~# /etc/rc.d/rc.httpd stop
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[email protected]:~#

We have to start Slackware httpd service to use Apache web server. In the example above, we have warning every time we start, restart and stop httpd service. This warning indicates that our dns is not properly configured but we still can test our web server using localhost. So let's test our Apache httpd server right away. Open web browser and type http://localhost in the url (you can also use ip address 127.0.0.1, which is the loopback ip address). If you have lynx, you can type lynx localhost to check our web server from the command line terminal. Press enter and you should have the same result as the example below:

[email protected]:~$ lynx localhost

Example testing Apache httpd web server using lynx screenshot image

Configure Apache httpd server in Slackware Linux

Slackware httpd server configuration files can be found in /etc directory. The main http server configuration file is httpd.conf. We can customize our web server by editing this file. Here are the most basic configuration that you need to edit in the httpd.conf file:

Add index.php, index.htm and index.xhtml in the DirectoryIndex:

<IfModule dir_module>
DirectoryIndex index.html index.php index.htm index.xhtml
</IfModule>

Set your email address to receive any problems with the server:

ServerAdmin [email protected]

ServerName gives the name and port that the server uses to identify itself. If your host doesn't have a registered DNS name, enter its IP address here. You can also set as localhost like in the example below:

ServerName localhost:80

You also need to remove comment(#) from the line below:

# Various default settings
#Include /etc/httpd/extra/httpd-default.conf

to be like this:

# Various default settings
Include /etc/httpd/extra/httpd-default.conf

That is the basic configuration that you need to do. Everything else is up to you. There are several other things to setup for the content management system. You can find specific setting for apache httpd.conf in joomla and Drupal tutorials. When you finished, save and exit.

Create a new html file to test our new Apache httpd configuration just for fun. Below is the example:

[email protected]:/etc/httpd# cd /var/www/htdocs/
[email protected]:/var/www/htdocs# cat > index.html
<html>
<head>
<title>Slackware Apache httpd configuration testing.</title>
</head>

<body>
<h1>This is a testing page.</h1>
<p>It works alright!</p>
</body>
</html>

Now we can restart httpd service again and test the new configuration. Here is the command:

[email protected]:/etc/httpd# /etc/rc.d/rc.httpd restart

Here is the result:

[email protected]:/var/www/htdocs# lynx localhost

Check Apache web server screenshot image

One thing to remember, in the future when restarting httpd after upgrade to the latest slackware httpd package, the httpd.conf file will be override. So you might not be able to view some of your websites. However, Slackware does not delete the old httpd.conf configuration file. What you need to do is just copy your configuration to the new file and restart httpd service again.

That's all. Good luck.

Comments

1

Hi All,

This is laxman and my email id is [email protected]. Could you please send the tutorial for creating multiple instance in apache web server.

Thanks,
Laxman

Add new comment