Servers play a major role in the world wide web. For every single page that is viewed on the browser,a connection is established to a server located elsewhere in the world and the HTML page is downloaded from it. Sometimes, it becomes highly critical to maintain servers and run projects on them. The present post is for beginners of Linux and I would like to give some insights into setting up and maintaining web server in Linux.
Configuring a web server is quite easy.
To configure a server, make sure apache2 is installed in Linux. The server runs as a service and continuously listens to the users who connect to the server and download data. To access server,the process apache2 should be enabled. Use the following commands to know the status of the server, start, stop and restart respectively.
There are two parts or folders in the web server, htdocs and cgi-bin.
cgi-bin (cgi stands for code graphic interface):
In ubuntu, cgi-bin is located in /usr/lib/cgi-bin, whereas in Suse, it is in /var/www/cgi-bin. The cgi-bin contains the source code of those files which are not visible to the end user, who is browsing the website. For example, if you are using a form to calculate some results,and you would like to share only the functionality of the code and hide all the implementation details and source code, then the code needs to be located in cgi-bin. The files in cgi-bin do not have read and write permissions and have only execute permissions. You can either have a php, or a perl-cgi to execute the code.
Enabling php or perl-cgi in the web-server:
To enable the php or perl-cgi, execution of cgi code for perl or php needs to be enabled. In the file
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Options MultiViews Indexes SymLinksIfOwnerMatch +ExecCGI
and restart the server by
Enabling database connectivity for perl-cgi or php:
You may also have a database connectivity to your php or perl-cgi code through mysql. In such cases, you need to have mysql installed on your system.
The following are the commands to know the status, start, stop and restart mysql daemon respectively.
Also make sure that the right packages are installed for mysql binding for perl-cgi or php
To view logs in web-server:
The error logs can be viewed in /var/log/apache2/errorlog. The error log contains details of errors while executing code on the server.
/var/log/apache2/accesslog is the access log file that contains details about the IP addresses of the systems that accessed our server.