Advertisement
kazaaakas

How to Install Apache2 webserver with PHP,CGI and Perl Suppo

Feb 9th, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. Posted on October 6, 2008 by ruchi 46 Comments
  2. Sponsored Link
  3. The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows NT. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.Apache v2 is the next generation of the omnipresent Apache web server. This version -- a total rewrite -- introduces many new improvements, such as threading, a new API, IPv6 support, request/response filtering, and more.
  4. Install Apache2 in Ubuntu
  5.  
  6. sudo aptitude install apache2
  7.  
  8. This will complete the installation.
  9.  
  10. After installation Type the server’s IP address (or alias if you added the server to your /etc/hosts file) in your browser’s address bar or, if you are browsing on the server itself, type 127.0.0.1 or localhost. If an error occurs, then you will have to edit the apache2.conf file to ensure that Apache can fully resolve the server’s name.If you have any problem then you have to edit the apache2 configuration file using the following command
  11.  
  12. sudo nano /etc/apache2/apache2.conf
  13.  
  14. Add the following line somewhere
  15.  
  16. ServerName localhost
  17.  
  18. or
  19.  
  20. ServerName yourserverip
  21.  
  22. Save and exit the file
  23.  
  24. Now you need to restart Apache server using the following command.
  25.  
  26. sudo apache2ctl restart
  27.  
  28. Change default document root in Apache2
  29.  
  30. The main configuration file located at /etc/apache2/apche2.conf.If you want to change the default document root you need to edit the /etc/apache2/sites-available/default file and look for this line “DocumentRoot /var/www/” here you can change where ever you want to change.For example if you want to change /home/www the above line looks like this “DocumentRoot /home/www/”.
  31.  
  32. Save and exit the file
  33.  
  34. Now you need to restart Apache server using the following command.
  35.  
  36. sudo apache2ctl restart
  37.  
  38. Enable PHP support for apache2 webserver
  39.  
  40. If you want to enable php5 or php4 support to your apache webserver use the following commands to install require packages
  41.  
  42. For PHP5
  43.  
  44. sudo aptitiude install php5 libapache2-mod-php5
  45.  
  46. For PHP4
  47.  
  48. sudo aptitiude install php4 libapache2-mod-php4
  49.  
  50. You also make sure the php5 and php4 modules are enabled using the following commands
  51.  
  52. sudo a2enmod php5
  53.  
  54. sudo a2enmod php4
  55.  
  56. After installing php support you need to restart apache webserver using the following command
  57.  
  58. sudo apache2ctl restart
  59.  
  60. Test your PHP Support foe apache webserver
  61.  
  62. To check the status of your PHP installation
  63.  
  64. sudo nano /var/www/testphp.php
  65.  
  66. and insert the following line
  67.  
  68. <?php phpinfo(); ?>
  69.  
  70. Save and exit the file
  71.  
  72. Now open web browser at http://yourserveripaddress/testphp.php and check.
  73.  
  74. Enable CGI and perl support for apache2 server
  75.  
  76. You need to install the following package
  77.  
  78. sudo aptitude install libapache2-mod-perl2
  79.  
  80. Configure a cgi-bin directory
  81.  
  82. You need to create a cgi-bin directory using the following command
  83.  
  84. sudo mkdir /home/www/cgi-bin
  85.  
  86. Configuring Apache to allow CGI program execution is pretty easy. Create a directory to be used for CGI programs and add the following to the site configuration file (again between the <VirtualHost> tags).
  87.  
  88. ScriptAlias /cgi-bin/ /home/www/cgi-bin/
  89.  
  90. <Directory /home/www/cgi-bin/>
  91. Options ExecCGI
  92. AddHandler cgi-script cgi pl
  93. </Directory>
  94.  
  95. The first line creates an alias that points to the directory in which CGI scripts are stored. The final line tells Apache that only files that end with the *.cgi and *.pl extensions should be considered CGI programs and executed.
  96.  
  97. Test your Perl Program
  98.  
  99. cd /home/www/cgi-bin
  100.  
  101. sudo nano perltest.pl
  102.  
  103. Copy and paste the following section save and exit the file.
  104.  
  105. ###Start###
  106.  
  107. #!/usr/bin/perl -w
  108. print "Content-type: text/html\r\n\r\n";
  109. print "Hello there!<br />\nJust testing .<br />\n";
  110.  
  111. for ($i=0; $i<10; $i++)
  112. {
  113. print $i."<br />";
  114. }
  115.  
  116. ###End###
  117.  
  118. make sure you change permissions on it
  119.  
  120. sudo chmod a+x perltest.pl
  121.  
  122. Now open your web browser open http://yourserverip/cgi-bin/perltest.pl.It should be working.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement