How to run cgi script on apache server

后端 未结 3 794
遥遥无期
遥遥无期 2020-12-11 08:40

This is my program:

[root@localhost cgi-bin]# locate first.pl 
/home/Ram/Desktop/work/first.pl
/usr/local/apache2/cgi-bin/first.pl
[root@localhost cgi-bin]#          


        
相关标签:
3条回答
  • 2020-12-11 09:14

    You basically need to change two files after installing apache2 on linux.

    Go to terminal and set the following configs:

    1. sudo vim /etc/apache2/sites-enabled/000-default.conf and add the follwing:

      <Files ~ "\.(pl|cgi)$">
          SetHandler perl-script
          PerlResponseHandler ModPerl::PerlRun
          Options +ExecCGI
          PerlSendHeader On
      </Files>
      
    2. sudo vim /etc/apache2/apache2.conf and add the following:

      <Directory /var/www/cgi-bin/> AddHandler cgi-script .cgi .pl Options FollowSymLinks ExecCGI AllowOverride None </Directory>

    After adding these two config changes, write a perl script, place it in the cgi-bin directory, and then give it sufficient privileges (sudo chmod 755 <filename>)

    Finally, restart apache2: sudo apache2ctl restart

    Screenshots:

    0 讨论(0)
  • 2020-12-11 09:22

    Yes, the above process works but the easy way is:

    1. Enable the CGI- sudo a2enmod cgi
    2. Restart the Apache and it works -service apache2 restart
    3. Run the cgi file http://localhost/cgi-bin/1.sh

    Best Of Luck !!

    0 讨论(0)
  • 2020-12-11 09:30

    In your web configuration (httpd.conf or your virtual host configuration file) you should have the following fragment:

    ScriptAlias /cgi-bin/ /etc/local/apache2/cgi-bin/
    <Directory "/etc/local/apache2/cgi-bin">
       Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
    </Directory>
    

    restart the server, don't forget to chmod +x /usr/local/apache2/cgi-bin/first.pl and then load http://localhost/cgi-bin/first.pl

    This assumes that either there are no virtual hosts in your config, or that the virtual host you configured is the default one. See the apache docs if needed.

    0 讨论(0)
提交回复
热议问题