I am trying to run a simple cgi script which resides on my iMac (Yosemite installed) from a Windows 10 computer.
Here is the say_test01 script (note that I tried with .cgi at the end but it also didn't work)
#!/bin/bash
echo -e "Content-type: text/html\n"
cat << junk
<html>
<head>
<title>
saying
</title>
</head>
<body>
junk
#-----------------------
osascript -e "set volume 8"
say -v Whisper This is just wrong!
osascript -e "set volume 4"
say -v Whisper This is OK!
#-----------------------
cat << junk
</body>
</html>
junk
On the iMac I am running Apache v2.4.16.
On the iMac, from the terminal, I can enter ./say_test01 and I can hear the voice say the phrase.
Again, on the iMac, but from a browser, when I enter the localhost/cgi-bin/say_test01 all I see are the contents of the file.
I understand, from reading other threads, that this is because the system doesn't know which application is associated with this file.
When I run from a browser on my Win10 PC the command 192.168.1.55/cgi-bin/saysomething I either see the contents of the file displayed or I get the error message "This site can't be reached".
So I am looking for some help in figuring this out...
In the httpd.conf here are some excerpts:
These lines have the '#' removed:
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule cgi_module libexec/apache2/mod_cgi.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule alias_module libexec/apache2/mod_alias.so
Here is the Directory section:
<Directory "/Library/WebServer/CGI-Executables">
AddHandler cgi-script .cgi
Options FollowSymLinks +ExecCGI
AllowOverride None
Require all granted
</Directory>
And finally this line has the '#' removed
Include /private/etc/apache2/extra/httpd-userdir.conf
In the httpd-userdir.conf file, the following line has the '#' removed
Include /private/etc/apache2/users/*.conf
In the /etc/apache2/users directory I have the file Name.conf which has the following code
<Directory "/Users/Name/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
I have not touched the virtual host file because I don't think (?) it applies here.
My ultimate goal is to pass parameters from another computer (raspberry pi) perhaps using python code to a cgi script so that the iMac can 'say' what I want... (e.g. today's weather, lights have just turned on...etc)
Any suggestions on how I can get this working?
Edit:
Using the suggestion of looking at the error log I saw that my httpd.conf had an error. The line Options FollowSymLinks +ExecCGI gave me an error message saying that I needed to have the '+' in front of all options or no options! So I changed the line to Options +FollowSymLinks +ExecCGI. It now works well.
I now send a http GET statement from my ISY994i (Insteon controller) to the Raspberry pi3. On the pi I have setup a HTTPServer which waits for the GET statement. Once received, it triggers a python script on the pi which parses a weather xml file (which I previously created for my iRule app, using wunderground.com as the source) and extracts the current day's weather forecast, which is a text descriptive paragraph; it then re-formats the text forecast so that the iMac can say it properly; and finally, using urllib2, it triggers the iMac to 'say' the weather. I am still encountering a problem, on the pi, setting up the HTTPServer to run automatically on a reboot but it works well when I start it manually. I will open a new question to get help resolving this.
The first thing to point out is that scripts run through the web server are unlikely to have permissions to make things happen like having the computer speak. The web server user won't have permission to access that part of the system. You would be better off doing this through ssh.
However, in order to get you being able to run scripts through the web server, as asked, here goes:
You need to add the .cgi extension to your script. You have your handler set up for the .cgi extension:
AddHandler cgi-script .cgi
So it's only going to work for scripts that have that extension. Currently you have none. I know you say you tried it, but it's definitely not going to work without it. So put it back in, and see if it works now. If it doesn't, don't take it off again. It's needed. Let me know how you get on.
Related
I setup apache2 on a mac (big sur), and it works for an html page. But I installed python3 on the machine, yet if I try to load a .py file in the home directory my web browser the system treats it like I'm running a local program and opens it in an editor.
I can't find any doc on how to get python3 to run as cgi in the apache server. Any help?
UPDATE: I added to the httpd.conf file:
Options +ExecCGI
AddHandler cgi-script .py
Now it spits back the file as just plain text, even though it ends in ".py" but still won't execute.
UPDATE: I removed the # from the load cgi lines. Now it responds "Forbidden: you do not have permission to access this resource". The file is 755, and all other files in the home directory are accessible.
I had to put
<Directory "/...the directory/">
Options +ExecCGI
</Directory>
At the bottom of the httpd.conf file. Then I had further problems with a "malformed header". I checked the error log and it was seeing the actual content of the python script, so it must have been running the script. I added
print("Content-Type: text/html\r\n\r\n")
as the first output in the program and that fixed it. The \r\n\r\n tells it that i am done with headers and onto the body.
While I am running my first program in Apache /2.4.7 (ubuntu) it shows error as Follows:
Not Found The requested URL /hello was not found on this server. Apache/2.4.7 (Ubuntu) Server at 127.0.0.1 Port 80.
I tried changing apache2.conf as below:
Options ExecCGI Indexes
FollowSymLinks <------
AllowOverride None
Require all granted
AddHandler cgi-script .py <--------
Still not able execute my program ?
Thanks
Based on the little info provided, there are a couple things to try:
Seems like you are trying to load a Python script, so include the extension of the script filename in the URL. As in: http://127.0.0.1/hello.py
Check for owner and permissions for the script. Does Apache have access to execute them?
I have difficulties making my .htacces work on my Ubuntu 14.04 LTS. I know it is a hidden file and all; I've searched everywhere and people seem to have the same problem. I've made a virtual host on my machine and all. Can someone please help me ?
ErrorDocument 404 /pages/error.php?code=404
ErrorDocument 403 /pages/error.php?code=403
You need to make sure the following things are true:
You need to check what DocumentRoot is set to. When an url beginning with a slash is detected, it will try to load that file relative to the document root. (docs) The file <documentroot>/pages/error.php must thus exist.
You need to make sure that .htaccess files are allowed by the main Apache configuration. The easiest way to test this is by entering garbage into your .htaccess file, saving it and reloading a page. You'll get an internal server error if Apache reads the .htaccess file. Otherwise the page loads as expected. To enable .htaccess files, the AllowOverride directive must allow something (see next bullet point). Additionally, check in httpd.conf if AccessFileName is set to something different than .htaccess. Change it as necessary, then RESTART APACHE. (docs)
For ErrorDocument, AllowOverride must be at least set to FileInfo. See the docs. Go to your main config file (httpd.conf), probably apache/Apachex.y.z/conf/httpd.conf. Search for the <Directory ...> block that corresponds to your http root, and look around if it contains an AllowOverride directive. Add FileInfo as one of the arguments, save the file and RESTART APACHE.
I have Laravel finally configured (for the most part) on my linux EC2 instance, but right now I can't get to any routes past my home page. All I get back is that *.net/people is not on the server. Anybody have any tips?
If you are using apache, check if your .htaccess is working. For example add 'deny from all' line at the beginning of file. If not - check your httpd.conf. Find <Directory /> block, if there is AllowOverride None line, change it to AllowOverride All and restart your apache.
I added the code below to my .htaccess file to enable caching files for 3 days. After that my website wasn't available anymore and I got a message displayed that told me it's an Internal Server Error
The code:
# 3 DAYS
<FilesMatch "\.(html|css|js|gif|jpg|jpeg|png|ico|swf)$"> Header set Cache-Control "max-age=259200, proxy-revalidate" </FilesMatch>
The message:
Internal Server Error
The server encountered an internal
error or misconfiguration and was
unable to complete your request.
Please contact the server
administrator, webmaster#exampple.com
and inform them of the time the error
occurred, and anything you might have
done that may have caused the error.
More information about this error may
be available in the server error log.
What is wrong with the FilesMatch or what else could cause the Internal Server Error?
Thanks
I had this issue a while ago, You can solve it by typing
"sudo a2enmod headers" in the command line
this is another solution
http://diogomelo.net/node/24
To enable this module, log in as root, and create a symbolic link from mods-available/headers.load to mods-enabled. After that, reload apache and it's done. To do so, I've used this commands.
su -
cd /etc/apache2/mods-enabled/
ln -s ../mods-available/headers.load headers.load
sh /etc/init.d/apache2 force-reload
After that procedure the issue is solved.
It has to be on multiple lines, not all in a single line. This one works fine for me:
<FilesMatch "\.(html|css|js|gif|jpg|jpeg|png|ico|swf)$">
Header set Cache-Control "max-age=259200, proxy-revalidate"
</FilesMatch>
This is another possible solution, after applying multiple lines do this simple possible solution.
Problem:
You may have copied and pasted the htaccess instructions directly from a sample code on a website or a slide presentation or somewhere else which creates a problem with the text encoding format.
Solution:
Copy the code again but this time paste it on a simple notepad or text editor and then, copy and paste it again into the ataccess file. This will remove any encoding problem.
Another problem you can have which returns error 500 it's you don't have enabled the AllowOverride directive correctly on the Apache conf file.
Example:
<VirtualHost *:80>
ServerName yoursitename
DocumentRoot /var/www/html/site
<Directory /var/www/html/site>
Options -Indexes +FollowSymLinks +MultiViews
Require all granted
AllowOverride None
</Directory>
ErrorLog /var/log/apache2/error_site.log
On that sample there's one AllowOverride none which blocks all .htaccess modifications you can do.
You can remove that AllowOverride None or modify it allowing only the directives do you need. On the example you placed with AllowOverride FileInfo will be ok.
More info about the AllowOverride directive here: https://httpd.apache.org/docs/2.4/es/mod/core.html#allowoverride