Step by step procedure to install and configure Apache webserver in Linux. It also includes troubleshooting steps for errors during install.
In this tutorial we are going to see how to install and configure Apache webserver in Linux. Apache is most widely used webserver which is developed and maintained by Apache Software Foundation. Its a open source software and available for free to download and use.
What is webserver
Webserver is aimed to serve web pages to its clients. In our daily life websites we visit from browsers are hosted on webservers! Webserver commonly runs on port 80 (http protocol) and 443 (https protocol, more secured). Communication between webserver and its client over https protocol is encrypted and hence secured.
Apache webserver is open source webserver developed by Apache Software Foundation. It is named as Apache HTTP Server Project and details can be viewed here. Lets see how to setup Apache webserver on Linux box.
If you have configured YUM repositories then you can install ‘httpd’ package. If you dont have YUM or apt-get repositories configured you can download latest Apache source, compile and then install it.
Number of errors and their solutions :
Error : configure: error: APR not found.
Solution : Install apr and apr-utils packages (download here if you dont have yum)
Error : configure: error: no acceptable C compiler found in $PATH
Solution : Install gcc package
Error : configure: error: pcre-config for libpcre not found.
Solution : Install pcre package (download here, unzip, /configure –prefix=/usr/local/pcre, make, make install)
Finally you should be able to install it using : ./configure –prefix=/apache, make, make install (you can change /apache directory to diff where it will be installed)
Post installation you will have /var/www/html/ directory in which you should place your html pages which can be fetched from browser. httpd service will come to an existence.
If you keep files and directories in /var/www/html/ then its listing will be shown in browser like this example we saw in another post. We will put below html file in /var/www/html/ for test :
# cat test.html
<h4>This webserver is installed by kerneltalks.com</h4>
# service httpd status
httpd (pid 27920) is running...
Now, try to fetch that page from browser. Use your server IP as website address i.e. http://IP/test.html
You will be greeted with such page! Your webserver is up and running. Accepting and serving requests from browsers.
Apache config files
Apache configuration file located at /etc/httpd/conf/httpd.conf In this configuration file you can set your error file path, SSL certificate path, SSL cert key file path, port, IP (virtual hosts), access log path etc. There are lot more customization can be done using this file but I stated only general tweaking parameters.
Apache log files can be found at :
- /etc/httpd/logs/access_log : all access logs logged here.
- /etc/httpd/logs/error_log : All errors logged here. They also includes start stop service messages.