How to Configure CGI in Ubuntu?












1















I am very new to Apache in Ubuntu. I recently installed Apache2 on Ubuntu and I am trying to configure CGI. I added the following lines in apache2.conf file:



ScriptAlias  /cgi-bin/ /home/router/cgi-bin/

<Directory /home/router/cgi-bin/>
Options ExecCGI
AddHandler cgi-script cgi pl
</Directory>


And I saved and restart apache2, but when I type the following in browser:



http://192.168.1.1/cgi-bin/file1.cgi 


I get the following error:



You don't have permission to access /cgi-bin/file1.cgi on this server.









share|improve this question



























    1















    I am very new to Apache in Ubuntu. I recently installed Apache2 on Ubuntu and I am trying to configure CGI. I added the following lines in apache2.conf file:



    ScriptAlias  /cgi-bin/ /home/router/cgi-bin/

    <Directory /home/router/cgi-bin/>
    Options ExecCGI
    AddHandler cgi-script cgi pl
    </Directory>


    And I saved and restart apache2, but when I type the following in browser:



    http://192.168.1.1/cgi-bin/file1.cgi 


    I get the following error:



    You don't have permission to access /cgi-bin/file1.cgi on this server.









    share|improve this question

























      1












      1








      1


      0






      I am very new to Apache in Ubuntu. I recently installed Apache2 on Ubuntu and I am trying to configure CGI. I added the following lines in apache2.conf file:



      ScriptAlias  /cgi-bin/ /home/router/cgi-bin/

      <Directory /home/router/cgi-bin/>
      Options ExecCGI
      AddHandler cgi-script cgi pl
      </Directory>


      And I saved and restart apache2, but when I type the following in browser:



      http://192.168.1.1/cgi-bin/file1.cgi 


      I get the following error:



      You don't have permission to access /cgi-bin/file1.cgi on this server.









      share|improve this question














      I am very new to Apache in Ubuntu. I recently installed Apache2 on Ubuntu and I am trying to configure CGI. I added the following lines in apache2.conf file:



      ScriptAlias  /cgi-bin/ /home/router/cgi-bin/

      <Directory /home/router/cgi-bin/>
      Options ExecCGI
      AddHandler cgi-script cgi pl
      </Directory>


      And I saved and restart apache2, but when I type the following in browser:



      http://192.168.1.1/cgi-bin/file1.cgi 


      I get the following error:



      You don't have permission to access /cgi-bin/file1.cgi on this server.






      apache2 cgi






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 11 '16 at 3:33









      user5499177user5499177

      1314




      1314






















          2 Answers
          2






          active

          oldest

          votes


















          2














          Firstly, I would not run CGI from your /home/ directory. Permissions are not set up for that, for web servers, and can lead to some headaches at times, both with permissions configurations and other issues.



          Secondly, I would suggest *creating a dedicated directory within /var/www/ (such as cgi-bin) where your CGI scripts get put, and use that in the Apache configuration.



          sudo mkdir -p /var/www/cgi-bin/
          sudo chown $USER:www-data /var/www/cgi-bin/


          The above commands will create the directory and set up permissions so that you can write to the directory, and the webserver can read the directory and have access to do things inside the directory.



          From there, drop your CGI there, make sure it's owned in a similar way (sudo chown $USER:www-data /var/www/cgi-bin/*) and then set your Apache configuration to use /var/www/cgi-bin instead of /home/router/cgi-bin.





          If for some reason you must use /home/router/cgi-bin, then you need to do several things: permit www-data and all users to traverse up to the cgi-bin directory, and give www-data access to the directory itself.



          sudo chgrp www-data /home/router/cgi-bin
          sudo chmod +rx /home/
          sudo chmod +rx /home/router/
          sudo chmod 750 /home/router/cgi-bin/


          The problem with this is you have to open your home directory just enough so that the 'other' category of users can reach into the directory structure and traverse it. This is a security hole, because any other user shouldn't be permitted to traverse the file system into your home directory in this way, as it could lead to data leakage or theft of personal data. (This is why most guides for web servers suggest NOT using home directories, and instead dedicated directories in /srv/ or /var/www/ for web server document directories)






          share|improve this answer































            0














            I've just set up a new LAMP server using Ubuntu 18.04.01, which installs or upgrades (I'm not sure which) to Apache2 v 2.4.29. This is a bit new to me as the Apache configuration files have changed again, but I think the procedure below is right.



            The cgi load module was not enabled so I had to do that first by running a2enmod. (Check the available modules for the correct name.) This sets up a symlink from the enabled folder to the file in the available folder.



            The cgi configuration module was already enabled - I thought this a bit odd, but that's what it was. The configuration module has a conditional statement that checks whether the load module is available and if so sets the Scriptalias to /usr/bin/cgi-bin. I have read that this is not a good idea, as in the previous answer, and it is better to make a /var/www/cgi-bin directory for your scripts, so I did that.



            Next, I put my php script into the new directory I had created at /var/www/cgi-bin. It only had to be read only - I chmod'ed it to 444, and it worked.



            Over the years the apache2.conf file has got smaller and, as explained in the docs, the developers have tried to make it more easily configurable by getting it to call in the other bits.






            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f797226%2fhow-to-configure-cgi-in-ubuntu%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              Firstly, I would not run CGI from your /home/ directory. Permissions are not set up for that, for web servers, and can lead to some headaches at times, both with permissions configurations and other issues.



              Secondly, I would suggest *creating a dedicated directory within /var/www/ (such as cgi-bin) where your CGI scripts get put, and use that in the Apache configuration.



              sudo mkdir -p /var/www/cgi-bin/
              sudo chown $USER:www-data /var/www/cgi-bin/


              The above commands will create the directory and set up permissions so that you can write to the directory, and the webserver can read the directory and have access to do things inside the directory.



              From there, drop your CGI there, make sure it's owned in a similar way (sudo chown $USER:www-data /var/www/cgi-bin/*) and then set your Apache configuration to use /var/www/cgi-bin instead of /home/router/cgi-bin.





              If for some reason you must use /home/router/cgi-bin, then you need to do several things: permit www-data and all users to traverse up to the cgi-bin directory, and give www-data access to the directory itself.



              sudo chgrp www-data /home/router/cgi-bin
              sudo chmod +rx /home/
              sudo chmod +rx /home/router/
              sudo chmod 750 /home/router/cgi-bin/


              The problem with this is you have to open your home directory just enough so that the 'other' category of users can reach into the directory structure and traverse it. This is a security hole, because any other user shouldn't be permitted to traverse the file system into your home directory in this way, as it could lead to data leakage or theft of personal data. (This is why most guides for web servers suggest NOT using home directories, and instead dedicated directories in /srv/ or /var/www/ for web server document directories)






              share|improve this answer




























                2














                Firstly, I would not run CGI from your /home/ directory. Permissions are not set up for that, for web servers, and can lead to some headaches at times, both with permissions configurations and other issues.



                Secondly, I would suggest *creating a dedicated directory within /var/www/ (such as cgi-bin) where your CGI scripts get put, and use that in the Apache configuration.



                sudo mkdir -p /var/www/cgi-bin/
                sudo chown $USER:www-data /var/www/cgi-bin/


                The above commands will create the directory and set up permissions so that you can write to the directory, and the webserver can read the directory and have access to do things inside the directory.



                From there, drop your CGI there, make sure it's owned in a similar way (sudo chown $USER:www-data /var/www/cgi-bin/*) and then set your Apache configuration to use /var/www/cgi-bin instead of /home/router/cgi-bin.





                If for some reason you must use /home/router/cgi-bin, then you need to do several things: permit www-data and all users to traverse up to the cgi-bin directory, and give www-data access to the directory itself.



                sudo chgrp www-data /home/router/cgi-bin
                sudo chmod +rx /home/
                sudo chmod +rx /home/router/
                sudo chmod 750 /home/router/cgi-bin/


                The problem with this is you have to open your home directory just enough so that the 'other' category of users can reach into the directory structure and traverse it. This is a security hole, because any other user shouldn't be permitted to traverse the file system into your home directory in this way, as it could lead to data leakage or theft of personal data. (This is why most guides for web servers suggest NOT using home directories, and instead dedicated directories in /srv/ or /var/www/ for web server document directories)






                share|improve this answer


























                  2












                  2








                  2







                  Firstly, I would not run CGI from your /home/ directory. Permissions are not set up for that, for web servers, and can lead to some headaches at times, both with permissions configurations and other issues.



                  Secondly, I would suggest *creating a dedicated directory within /var/www/ (such as cgi-bin) where your CGI scripts get put, and use that in the Apache configuration.



                  sudo mkdir -p /var/www/cgi-bin/
                  sudo chown $USER:www-data /var/www/cgi-bin/


                  The above commands will create the directory and set up permissions so that you can write to the directory, and the webserver can read the directory and have access to do things inside the directory.



                  From there, drop your CGI there, make sure it's owned in a similar way (sudo chown $USER:www-data /var/www/cgi-bin/*) and then set your Apache configuration to use /var/www/cgi-bin instead of /home/router/cgi-bin.





                  If for some reason you must use /home/router/cgi-bin, then you need to do several things: permit www-data and all users to traverse up to the cgi-bin directory, and give www-data access to the directory itself.



                  sudo chgrp www-data /home/router/cgi-bin
                  sudo chmod +rx /home/
                  sudo chmod +rx /home/router/
                  sudo chmod 750 /home/router/cgi-bin/


                  The problem with this is you have to open your home directory just enough so that the 'other' category of users can reach into the directory structure and traverse it. This is a security hole, because any other user shouldn't be permitted to traverse the file system into your home directory in this way, as it could lead to data leakage or theft of personal data. (This is why most guides for web servers suggest NOT using home directories, and instead dedicated directories in /srv/ or /var/www/ for web server document directories)






                  share|improve this answer













                  Firstly, I would not run CGI from your /home/ directory. Permissions are not set up for that, for web servers, and can lead to some headaches at times, both with permissions configurations and other issues.



                  Secondly, I would suggest *creating a dedicated directory within /var/www/ (such as cgi-bin) where your CGI scripts get put, and use that in the Apache configuration.



                  sudo mkdir -p /var/www/cgi-bin/
                  sudo chown $USER:www-data /var/www/cgi-bin/


                  The above commands will create the directory and set up permissions so that you can write to the directory, and the webserver can read the directory and have access to do things inside the directory.



                  From there, drop your CGI there, make sure it's owned in a similar way (sudo chown $USER:www-data /var/www/cgi-bin/*) and then set your Apache configuration to use /var/www/cgi-bin instead of /home/router/cgi-bin.





                  If for some reason you must use /home/router/cgi-bin, then you need to do several things: permit www-data and all users to traverse up to the cgi-bin directory, and give www-data access to the directory itself.



                  sudo chgrp www-data /home/router/cgi-bin
                  sudo chmod +rx /home/
                  sudo chmod +rx /home/router/
                  sudo chmod 750 /home/router/cgi-bin/


                  The problem with this is you have to open your home directory just enough so that the 'other' category of users can reach into the directory structure and traverse it. This is a security hole, because any other user shouldn't be permitted to traverse the file system into your home directory in this way, as it could lead to data leakage or theft of personal data. (This is why most guides for web servers suggest NOT using home directories, and instead dedicated directories in /srv/ or /var/www/ for web server document directories)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 11 '16 at 12:00









                  Thomas WardThomas Ward

                  44.1k23122174




                  44.1k23122174

























                      0














                      I've just set up a new LAMP server using Ubuntu 18.04.01, which installs or upgrades (I'm not sure which) to Apache2 v 2.4.29. This is a bit new to me as the Apache configuration files have changed again, but I think the procedure below is right.



                      The cgi load module was not enabled so I had to do that first by running a2enmod. (Check the available modules for the correct name.) This sets up a symlink from the enabled folder to the file in the available folder.



                      The cgi configuration module was already enabled - I thought this a bit odd, but that's what it was. The configuration module has a conditional statement that checks whether the load module is available and if so sets the Scriptalias to /usr/bin/cgi-bin. I have read that this is not a good idea, as in the previous answer, and it is better to make a /var/www/cgi-bin directory for your scripts, so I did that.



                      Next, I put my php script into the new directory I had created at /var/www/cgi-bin. It only had to be read only - I chmod'ed it to 444, and it worked.



                      Over the years the apache2.conf file has got smaller and, as explained in the docs, the developers have tried to make it more easily configurable by getting it to call in the other bits.






                      share|improve this answer




























                        0














                        I've just set up a new LAMP server using Ubuntu 18.04.01, which installs or upgrades (I'm not sure which) to Apache2 v 2.4.29. This is a bit new to me as the Apache configuration files have changed again, but I think the procedure below is right.



                        The cgi load module was not enabled so I had to do that first by running a2enmod. (Check the available modules for the correct name.) This sets up a symlink from the enabled folder to the file in the available folder.



                        The cgi configuration module was already enabled - I thought this a bit odd, but that's what it was. The configuration module has a conditional statement that checks whether the load module is available and if so sets the Scriptalias to /usr/bin/cgi-bin. I have read that this is not a good idea, as in the previous answer, and it is better to make a /var/www/cgi-bin directory for your scripts, so I did that.



                        Next, I put my php script into the new directory I had created at /var/www/cgi-bin. It only had to be read only - I chmod'ed it to 444, and it worked.



                        Over the years the apache2.conf file has got smaller and, as explained in the docs, the developers have tried to make it more easily configurable by getting it to call in the other bits.






                        share|improve this answer


























                          0












                          0








                          0







                          I've just set up a new LAMP server using Ubuntu 18.04.01, which installs or upgrades (I'm not sure which) to Apache2 v 2.4.29. This is a bit new to me as the Apache configuration files have changed again, but I think the procedure below is right.



                          The cgi load module was not enabled so I had to do that first by running a2enmod. (Check the available modules for the correct name.) This sets up a symlink from the enabled folder to the file in the available folder.



                          The cgi configuration module was already enabled - I thought this a bit odd, but that's what it was. The configuration module has a conditional statement that checks whether the load module is available and if so sets the Scriptalias to /usr/bin/cgi-bin. I have read that this is not a good idea, as in the previous answer, and it is better to make a /var/www/cgi-bin directory for your scripts, so I did that.



                          Next, I put my php script into the new directory I had created at /var/www/cgi-bin. It only had to be read only - I chmod'ed it to 444, and it worked.



                          Over the years the apache2.conf file has got smaller and, as explained in the docs, the developers have tried to make it more easily configurable by getting it to call in the other bits.






                          share|improve this answer













                          I've just set up a new LAMP server using Ubuntu 18.04.01, which installs or upgrades (I'm not sure which) to Apache2 v 2.4.29. This is a bit new to me as the Apache configuration files have changed again, but I think the procedure below is right.



                          The cgi load module was not enabled so I had to do that first by running a2enmod. (Check the available modules for the correct name.) This sets up a symlink from the enabled folder to the file in the available folder.



                          The cgi configuration module was already enabled - I thought this a bit odd, but that's what it was. The configuration module has a conditional statement that checks whether the load module is available and if so sets the Scriptalias to /usr/bin/cgi-bin. I have read that this is not a good idea, as in the previous answer, and it is better to make a /var/www/cgi-bin directory for your scripts, so I did that.



                          Next, I put my php script into the new directory I had created at /var/www/cgi-bin. It only had to be read only - I chmod'ed it to 444, and it worked.



                          Over the years the apache2.conf file has got smaller and, as explained in the docs, the developers have tried to make it more easily configurable by getting it to call in the other bits.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 12 at 17:31









                          RoryRory

                          11




                          11






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f797226%2fhow-to-configure-cgi-in-ubuntu%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                              Mangá

                               ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕