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. Apache webserver is also a part of LAMP stack. Read more about LAMP 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.
How to start / stop Apache webserver
To start Apache webserver
# service httpd start
# service apache2 start #If you are running Apache2
To stop Apache webserver
# service httpd stop
# service apache2 stop #If you are running Apache2
How to load Apache2 modules
One of the common issues found is when php module is not loaded in to Apache webserver,
.php links on webserver will download files in browser instead of display them. To correct this you need to load php module in Apache.
To load php or any other module in Apache, you need to add it in file
/etc/sysconfig/apache2 in below line :
APACHE_MODULES="actions alias auth_basic authn_file authz_host authz_groupfile authz_core authz_user autoindex cgi dir env expires include log_config mime negotiation setenvif ssl socache_shmcb userdir reqtimeout authn_core php5"
Here you can see we are loading php5 module in our Apache2 webserver. Then you need to restart Apache2 webserver. Once done, check if php module is loaded or not. Use command
apache2ctl -M to check loaded modules in Apache.
# apache2ctl -M
You can see our php5 module is loaded in Apache.