How to Install Apache2 webserver with PHP,CGI and Perl Support in Ubuntu Server
Sponsored Link
Install Apache2 in Ubuntu
sudo aptitude install apache2
This will complete the installation.
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
sudo nano /etc/apache2/apache2.conf
Add the following line somewhere
ServerName localhost
or
ServerName yourserverip
Save and exit the file
Now you need to restart Apache server using the following command.
sudo apache2ctl restart
Change default document root in Apache2
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/”.
Save and exit the file
Now you need to restart Apache server using the following command.
sudo apache2ctl restart
Enable PHP support for apache2 webserver
If you want to enable php5 or php4 support to your apache webserver use the following commands to install require packages
For PHP5
sudo aptitiude install php5 libapache2-mod-php5
For PHP4
sudo aptitiude install php4 libapache2-mod-php4
You also make sure the php5 and php4 modules are enabled using the following commands
sudo a2enmod php5
sudo a2enmod php4
After installing php support you need to restart apache webserver using the following command
sudo apache2ctl restart
Test your PHP Support foe apache webserver
To check the status of your PHP installation
sudo nano /var/www/testphp.php
and insert the following line
<?php phpinfo(); ?>
Save and exit the file
Now open web browser at http://yourserveripaddress/testphp.php and check.
Enable CGI and perl support for apache2 server
You need to install the following package
sudo aptitude install libapache2-mod-perl2
Configure a cgi-bin directory
You need to create a cgi-bin directory using the following command
sudo mkdir /home/www/cgi-bin
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).
ScriptAlias /cgi-bin/ /home/www/cgi-bin/
<Directory /home/www/cgi-bin/>
Options ExecCGI
AddHandler cgi-script cgi pl
</Directory>
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.
Test your Perl Program
cd /home/www/cgi-bin
sudo nano perltest.pl
Copy and paste the following section save and exit the file.
###Start###
#!/usr/bin/perl -w
print "Content-type: text/html\r\n\r\n";
print "Hello there!<br />\nJust testing .<br />\n";for ($i=0; $i<10; $i++)
{
print $i."<br />";
}###End###
make sure you change permissions on it
sudo chmod a+x perltest.pl
Now open your web browser open http://yourserverip/cgi-bin/perltest.pl.It should be working.
<blockquote cite=”again between the tags”>
Am I miss something here?
Word of an adivce: Don’t edit apache.conf. Add your custom configuration in /etc/apache2/conf.d/ directory. This will help you maintain your configuration (you can split it into logical files) and make upgrades to newer Ubuntu version smoother. Also, web site specific configuration is done in /etc/apache2/sites-available – create your own site and enable it. As with custom configuration, custom websites will make upgrades to newer Ubuntu version painless.
sudo aptitude install libapache2-mod-perl is not functionaly. but i tested : sudo apt-get install libapache2-mod-perl & its runing now. maybe is there anything wrong of the site.
Thanks, this was helpful.
would someone show me what there /etc/apache2/sites-available/default file I need help on how it should look
I still can’t start my php … it is still asking me to download instead of displaying the page. Any solutions for that ?
hey, thanks for the info. that was helpul. =)
Hi very good instructions, the server is up and running. The only problem is with CGI. In the step “Configure a cgi-bin directory”. You say to add text to the site configuration file (again between the tags. Is that the apache2.conf file, and if so I don’t see any tags.
Sorry if this is a stupid question.
this tag located in /etc/apache2/sites-available/default file.
I did all that was told in the instructtion (I have omitted the PHP- istallation part as I need CGI perl for the time being), but can’t run the CGI script given in the exampl or any other CGI script.
getting the followint “404 Not Found” error:-
The requested URL /home/www/cgi-bin/perltest.pl was not found on this server.
Apache/2.2.9 (Ubuntu) Server at 127.0.1.1 Port 80
In case ur wondering I have given the correct IP of the server as shown in the error mssg.PlZZZZZ Help!Thanks
Thanks a lot buddy.
This really helped me.
I cant follow this
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 tags).
ScriptAlias /cgi-bin/ /home/www/cgi-bin/
Options ExecCGI
AddHandler cgi-script cgi pl
Is this what you are asking me to add
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 tags).
ScriptAlias /cgi-bin/ /home/www/cgi-bin/
Options ExecCGI
AddHandler cgi-script cgi pl
Thanks for the help. Took a couple of times to go through but it works. Thanks again!
Works fine after i found out the reason for why i didn’t get the php working, i have missed a apace server restart.
I get error
Forbidden
You don’t have permission to access /cgi-bin/ on this server.
its working now
http://192.168.90.20/cgi-bin/perltest.pl
file name.
and no space / Line befor #!/usr/bin/perl -w
Thanks !!
Hi, I followed your instruction in the cgi section (or at least I believe I did), but my browser keeps wanting to download the pl file instead of executing it. I’ve had the same problem with other binary files too. Please help
Thank you, it works now
It rocks !!!!
yahoooo! works!!!
Thanks a lot,very helpful.Works fine 🙂
With apache 2 and Ubuntu 10.4 the sites-enabled file already includes the
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
and there is a usr/lib/cgi-bin DIR where I added the perl script and ran it..
Then I had to look to see that the numbers were part of the script :P!
Great Thread! Thanks!
Worked a treat. Thank you.
Thank you!
i am error open http://yourserverip/cgi-bin/perltest.pl
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request
can you help me
Anyone know of a step-by-step that will work?
What and where is the,”site configuration file.”?
I’m sure it’s a version thing but my www directory is /var/www not /home/www.
This page wouldn’t exist if the apache page explanation wasn’t just as bad. I’ve tried a few different ways to get this to work.
I have lot’s of scripts that I would like to execute from an html document. Apache is installed and working, what next? All I can get it to do is try to download the file/bash script. Any help would be good, specific help would be great.
Thanks All.
…I LOVE LAMP!
little error in this line:
sudo aptitiude install php5 libapache2-mod-php5
Dear sir,
We have configured Apache2 on an Ubuntu 10.04 Machine in my LAN with a static IP of 192.168.1.125
The default page of the Apache2 is available on entire LAN member PC’s with the URL address http://192.168.1.125.
We have installed Web with default directories as explained in your tutorial http://www.webmo.net/support/installation.html
But able to access webMO through the browsers in LAN or the server PC…
Cam you explain me how to configure this as virtual host, which will enable us to access WebMO through browsers in LAN PC’s?
Problem Details:
tried to install webMo on Ubuntu 10.04 as explained in your tutorial using default directories….but unable to access webMo form a browser. it give following error message… how can i configure this installation as virtual host and access it through browser?. (apache2 is configured and default page is accessible)
======================
Error message,
Not Found
The requested URL /~web/cgi-bin/webmo/login.cgi was not found on this server.
Apache/2.2.14 (Ubuntu) Server at 192.168.1.125 Port 80
====================================
ServerName ?
DocumentRoot /path/to/your/project/root ?
?
AllowOverride All
Order deny,allow
Allow from all
ScriptAlias /cgi-bin/ /home/www/cgi-bin/
Options ExecCGI
AddHandler cgi-script cgi pl
Regards,
VK. Adarsh