CGI Script displayed as Plain Text in Apache2 (localhost) - html

I currently have to do a web server in Apache2 that consists on a Login/Register web, and I have to call a CGI Script to validate the input data from the user. Well, when I call the script with the submit button, the CGI Script appears as Plain Text, and I don't know what else to do to fix it.
I have tried uncommenting CGI Modules in /etc/apache2/httpd.conf, setting a default directory for CGI Scripts, uncommenting the AddHandler for CGI and changing Options values in my localhost directory and in the CGI directory adding ExecCGI in them all. But it still does not work, it just appears as plain text.
P.S.: I followed this tutorial (http://httpd.apache.org/docs/2.2/howto/cgi.html) and also looked for the solution here in StackOverflow, but I got nothing working for me.
Edit: Also thank you for helping if you do :)

The problem was the directory configuration, so I kept the default http.config file, that has a preset ScriptAlias for the /cgi-bin/ directory to the following directory:
/Library/WebServer/CGI-Executables
Then I enabled the CGI Module by uncommenting the line (removing the '#' before the line) in the httpd.conf file from apache2:
LoadModule cgi_module libexec/apache2/mod_cgi.so
Finally I saved the file, and then I restarted the Apache2 server using the command:
sudo /usr/sbin/apachectl restart
Then I just pasted the .cgi script in the CGI-Executables directory, setting the permissions of the file as chmod a+x.
To run the script now you just have to access
localhost/cgi-bin/script.cgi
Thank you for the help anyways!

Related

How to create opt/bitnami/apps/myapp/conf/httpd-prefix.conf and include /opt/bitnami/apps/myapp/conf/httpd-app.conf

Please guys help out, am using google compute engine for the first time and using bitnami. I have successfully spin up a server, and connected with ssh but am stock here https://docs.bitnami.com/virtual-machine/components/nodejs/#how-to-create-a-custom-nodejs-application
Can anyone help me explain how:
1.- Create and edit the /opt/bitnami/apps/myapp/conf/httpd-prefix.conf file and add the line below to it:
Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
2.- Create and edit the /opt/bitnami/apps/myapp/conf/httpd-app.conf file and add the content below to it. This is the main configuration file for your application, so modify it further depending on your application's requirements.
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
NOTE: 3000 is the default port for the Express server. If you have
customized your application to use a different port, change it here as
well.
3.- Once you have created the files and directories above, add the following line to the end of the main Apache configuration file at /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf, as shown below:
Include "/opt/bitnami/apps/myapp/conf/httpd-prefix.conf"
According to the Bitnami guide shared by you, you should follow the following steps (I added more detailed information):
1.- Create directories
For that, you should run the following commands:
sudo mkdir -p /opt/bitnami/apps/myapp
sudo mkdir /opt/bitnami/apps/myapp/conf
sudo mkdir /opt/bitnami/apps/myapp/htdocs
2.- Create two files
For that, you can run the following commands:
touch /opt/bitnami/apps/myapp/conf/httpd-prefix.conf
touch /opt/bitnami/apps/myapp/conf/httpd-app.conf
3.- Add content to the first file
You can edit the file using any text editor, for example nano
nano /opt/bitnami/apps/myapp/conf/httpd-prefix.conf
The above command opens the text editor, you should copy/paste or write the following line:
Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
Close the editor using Ctrl+X(you will be prompted to save your file if you have not)
4.- Add content to the second file
You can edit the file using any text editor, for example nano
nano /opt/bitnami/apps/myapp/conf/httpd-app.conf
The above command opens the text editor, you should copy/paste or write the following line:
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
Close the editor using Ctrl+X(you will be prompted to save your file if you have not)
5.- Edit Apache config file
Once you have created the files and directories above, add the following line to the end of the main Apache configuration file. Open the file (again using nano):
nano /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf
The above command opens the text editor, you should copy/paste or write the following line:
Include "/opt/bitnami/apps/myapp/conf/httpd-prefix.conf"
Close the editor using Ctrl+X(you will be prompted to save your file if you have not)
6.- Restart apache
For that execute
sudo /opt/bitnami/ctlscript.sh restart apache
7.- Start the Express server
cd /opt/bitnami/apps/myapp/htdocs
./bin/www
Alternatively, use the following command to start the server and keep it running even after your server session ends. Replace FILE with the correct filename for your application.
forever start FILE.js

Form action downloads ruby script instead of running it

I'm trying to send an email from a form made in HTML (haml). I've created a script called mailto.rb and I've set it as an action inside the form. The problem is that instead of running the code inside, when I press submit it just downloads the file (mailto.rb).
%form{:action => "mailto.rb", :method => "post"}
This is the code from the beginning of the form.
In HTML it would be:
<form method="post" action="mailto.rb">
Also, I've added the path to the ruby executable file on the first line of the ruby file.
#!~/.rbenv/shims/ruby
I know that It would be easier to use rails, but I'm not allowed. I have to use a ruby script.
PS: I'm using Middleman, and I work on localhost.
The idea is you can't POST request a static file with middleman. Same if you middleman build your application and pass everything to nginx/apache2. You'll get a 405 error
For example to use your script with nginx you have to install and use spawn-fcgi and fcgiwrap. Spawn a socket or a port from your ruby file and configure nginx to fastcgi_pass to fcgiwrap socket.
To use it with apache2, add your site to /var/www/html and put this in vhost:
AddHandler cgi-script .rb
<Directory /var/www/html>
Options +ExecCGI
</Directory>
Symlink cgid.conf and cgid.load to your mods-enabled folder and restart apache2.
Check error log for other problems, but it should work.
EDIT: In this case I'll choose apache2 over nginx. As a 3rd solution you should consider writing a rack script and pass it to unicorn.

how to run html on python openshift server

I have an OpenShift server running python. However when I call php via SSL the php interpreter starts running. It suggests that there might be a way to run php as well. However, HTML if fair enough for me. Now, I do not know how to be able to reach html files on my server as when I am trying I always get 404 not found. I've read about a solution of placing a .htaccess file:
AddType application/x-httpd-php .html
I am not exactly sure where to place this file but placing in the folder of the .html file still not helps.
Could you please help me how I can make .html files reachable at an OpenShift server running Python? How about php?
Put the .html file in your app-root/repo/wsgi/static folder (or in that folder in your git repository). if you want it to be displayed like app-domain.rhcloud.com/file.html, you will have to use a .htaccess file in your wsgi folder that rewrites file.html to static/file.html

How to get AWStats to generate static HTML files?

I want to get AWStats running on my webserver that runs Debian 4.4.5-8 with Apache 2.
There are several websites that all have their own configuration file, similar to this:
Include "/etc/awstats/awstats.model.conf"
LogFile="/var/customers/logs/myname-example.com-access.log"
LogType=W
LogFormat = 1
LogSeparator=" "
SiteDomain="example.com"
HostAliases="*.example.com"
DirData="/www/myname/awstats/example.com/"
What I expect is that HTML files are written to /www/myname/awstats/example.com/ which I can then access through Apache. However when I run /usr/share/awstats/tools/buildstatic.sh what happens is that .txt files are written to that directory and HTML files that I want are written to /var/cache/awstats. The error file in /tmp remains empty.
Why is this happening and how do I make it work the way I want?
DirData is not supposed to be read directly by the Web Server. It is used by awstats.pl.
The fact is that /var/cache/awstats is hardcoded in buildstatic.sh so you have to change the two lines mentioning it:
mkdir -p /var/cache/awstats/$c/$Y/$m/
and
-dir=/var/cache/awstats/$c/$Y/$m/ >$TMPFILE 2>&1

403 forbidden error cgi

I have a public html folder with my html pages and CGI script written in c. Within that, I have my cgi-bin folder with my GCI executable. However when I try to access my cgi page in my browser, it gives me the forbidden error. I'm using firefox and a linux system. I've looked around for the correct permissions but resources often advise different combinations. Any help is appreciated!
With a FTP client, or with console, check the rights to execute for the file. The apache process sould be able to execute it.
If this is right, and it still not work, then you have to properly configure the server.
As per your design ( 8 years ago on 2021), you did not provide permission for your cgi directory in the web server (possibly APACHE) configuration file.
Example in *nix:
Lets say your cgi-bin directory is actually is in /usr/home/your-name/cgi-bin
Then you have to add this to your that domains cgi section of your servers (ie Apache 2.4++) configuration file.
ScriptAlias /cgi-bin/ "/usr/local/www/ceo/cgi-bin/"
<Directory "/usr/local/www/ceo/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
And of course don't forget to turn on CGI module ( remove the #).