Cgi/perl scripts display as code in Monterey - apache

These scripts worked fine prior to upgrading to Monterey!
I have followed the tutorial from “etresoft” regarding editing the httpd.conf file and restarting Apache, but when executed the Perl script (code) displays in Safari. The scripts live in my Sites directory, and execute properly when run from there.
There are a suite of cgi/perl scripts that function to manage and present a family budget.
The first script opens a data file that contains various accounts: expenses (like groceries, utilities, etc.) and incomes. The script presents an HTML file with a large table, each line in the table documents an account, how much is due, and when. The script allows you to edit the various values. From this table page it is possible to call another script which will present those accounts due for the month and calculate the total amounts owed and the total incomes and the difference.
These are the edits made to /etc/apache2/httpd.conf:
Enabled the php and perl:
LoadModule php_modul/usr/local/opt/php#8.0/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
LoadModule perl_module libexec/apache2/mod_perl.so
Uncommented the LoadModule for userdir_module:
LoadModule userdir_module libexec/apache2/mod_userdir.so
Uncommented the Include line for httpd-userdir.conf:
User home directories
Include /private/etc/apache2/extra/httpd-userdir.conf
Saved the httpd.conf file.
This is the edit made to /etc/apache2/extra/httpd-userdir.conf:
Uncommented the Include line for *.conf
Include /private/etc/apache2/users/*.conf
I edited /etc/apache2/users/<your short user name>.conf. It now looks like this:
<Directory "/Users/rjklaus/Sites/">
AddLanguage en .en
AddHandler perl-script .pl
Options Indexes MultiViews FollowSymLinks Includes ExecCGI
DirectoryIndex index.html index.cgi index.php
AllowOverride None
Require host localhost
</Directory>
From a “Terminal” window I ran the following command:
chmod +a "_www allow execute" ~
I ran apachectl configtest and received a “Syntax OK”.
I next entered http://localhost/ into the Safari address bar. I did NOT see the “It works!” that I was told to expect. Instead I got:
/Users/rjklaus/Ray's%20Stuff/HTML%20Budget/test.pl
“HTML Budget” is a file (not a directory) in a subdirectory of “Ray’s Stuff”. The text string “test.pl” is not in that file. Test.pl is a short perl script in my Sites directory.
I am running perl v5.30.3 from /usr/bin/perl.
There are three versions of Apache2 located in /Users/Shared/ subdirectories labeled:
Previously Relocated Items,
Previously Relocated Items 1, and
Previously Relocated Items 2.

just to be sure, the cgi_module is enabled?
<IfModule !mpm_prefork_module>
LoadModule cgid_module lib/httpd/modules/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
LoadModule cgi_module lib/httpd/modules/mod_cgi.so
</IfModule>

Related

How to run multiple PHP version with XAMPP?

I have multiple projects based on PHP. Some require PHP version 5.x to run and other strictly require PHP 7.0 or above. I am working on these simultaneously. Is there a way to run multiple PHP versions such that I can switch between them when working on different projects.
Try these steps:
Stop LAMP if running.
Download libphp7.so if you don't have
https://github.com/prashant-techindustan/php7module_library/blob/master/libphp7.so
Edit /opt/lampp/etc/extra/httpd-xampp.conf (Comment out one of the following which is not needed):
LoadModule php5_module modules/libphp5.so
LoadModule php7_module modules/libphp7.so
Start LAMP
>> Open C:\xampp\apache\conf\extra\httpd-xampp.conf
>> Write Following code at Bottom of this (httpd-xampp.conf) file
ScriptAlias /php56 "C:/xampp/php56"
<Directory "C:/xampp/php56">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
>> Open C:\xampp\apache\conf\extra\httpd-vhosts.conf\httpd-vhosts.conf
>> Create a virchual host in Different post By Writing Following code
<VirtualHost *:8081>
UnsetEnv PHPRC
<FilesMatch "\.php$">
php_flag engine off
SetHandler application/x-httpd-php5_6
Action application/x-httpd-php5_6 "/php5_6/php-cgi.exe"
</FilesMatch>
DocumentRoot "C:/xampp/htdocs/myphp5_6_project"
</VirtualHost>
>> Create a folder "myphp5_6_project" in htdocs of xampp
>> Open C:\xampp\apache\conf\httpd.conf
>> Write Listen 8081 (any where or Below Listen 80 line)
>> Restart Apache Services

Testing CGI code on MacOS Sierra

I have some CGI code written in C that I've developed on an Ubuntu linux machine. It works fine, but I wanted to make some changes and update it while away on travel. Thought I'd set it up to test on my Mac laptop (macOS 10.12.1) using Xcode and Safari. Tried looking online for instructions on how to get apache to recognize the CGI code and found a few sites, but it still doesn't work.
Here's what I have so far:
I set up a directory /User/username/Sites to store the html pages that will call the CGI code through a form. (where "username" is my username)
I put the compiled CGI code in /Library/WebServer/CGI-Executables (Note: I also put them in /Users/username/Sites just in case)
Following the online instructions, in /etc/apache2/httpd.conf I uncommented the following lines:
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
AddHandler cgi-script .cgi
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Include /private/etc/apache2/extra/httpd-userdir.conf
Include /private/etc/apache2/extra/httpd-vhosts.conf
Also following the online instructions, I created the following file in /etc/apache2/users called username.conf (again, "username" is my username).
<Directory "/Users/username/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
When done with the above changes I restarted the apache server (also tried a full restart of the computer, but it didn't help).
I'm able to load the form page using http://localhost/~username/foo.html, but when I submit the form using the POST method to a code foo.cgi it just spits foo.cgi back at me and then safari dumps it in the download folder. Also tried writing a simple perl script and a simple cgi C code to just make a "hello world" web page and called it with http://localhost/~username/hello.pl (or .cgi). This gave me the same results, though for the perl script it spit the script itself back since it's just plain text.
There must be a step I'm missing, but haven't been able to find it. Any help would be greatly appreciated. Thanks!
DC
One step left out of the instructions I found online: need to also uncomment the line:
LoadModule cgi_module libexec/apache2/mod_cgi.so
in the httpd.conf file. Works now by putting the executables in the /Library/WebServer/CGI-Executables folder.
Besides all you did, I also added ExecCGI Includes to the Options line at the /etc/apache2/users/username.conf file. Restarted and worked. Config file looks like this:
<Directory "/Users/username/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks ExecCGI Includes
Require all granted
</Directory>

.htaccess is not working in xampp (ubuntu)

I can't get .htaccess to work in xampp under Ubuntu 13.04 and the server keep showing the 404 error page I tried to modify httpd.conf in /opt/lampp/apache2/conf/ with this code
<Directory "/opt/lampp/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
LoadModule rewrite_module modules/mod_rewrite.so
but still give the same error page
it looks like the server can't see the .htaccess file.
What to do .. ?
Make sure your htaccess file is in the right place (/opt/lampp/apache2/htdocs) and that it is readable (chmod 644 /opt/lampp/apache2/htdocs/.htaccess) and that the access file is set to ".htaccess":
AccessFileName .htaccess
By default, it's already ".htaccess" but it could have been changed.
Finally, try adding some gibberish to the top of your htaccess file (like "ashdakjhfdksjfhds"), if you get a 500 internal server error, that means your htaccess file is being read and the problem isn't your setup but the contents of the file.

Apache mod_rewrite enabled, but not working

Battling second day against problems with using mod_rewrite.
System OS: Windows XP
HTTP server: Apache 2.2 httpd
couple related lines from httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
DocumentRoot "N:/Web-dev/www"
<Directory "/">
Options Indexes +FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "N:/Web-dev/www">
Options Indexes +FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
.htaccess contains:
RewriteEngine on
RewriteRule ^alice.html$ bob.html
php info says
Loaded Modules core mod_win32 mpm_winnt http_core mod_so mod_actions mod_alias mod_asis mod_auth_basic mod_authn_default mod_authn_file mod_authz_default mod_authz_groupfile mod_authz_host mod_authz_user mod_autoindex mod_cgi mod_dir mod_env mod_include mod_isapi mod_log_config mod_mime mod_negotiation mod_setenvif mod_rewrite mod_proxy mod_php5
Both files are existing, loading alice.html, it still loads it, in rewrite.log, it shows:
127.0.0.1 - - [25/Apr/2011:11:01:27 +0300] [localhost/sid#7b5148][rid#2bc70b0/initial] (1) [perdir N:/Web-dev/www/] pass through N:/Web-dev/www/alice.html
I eaven tried to test, if it is reading .htaccess file, by adding some jibberish to rewrite engine command, and it proved:
[Mon Apr 25 10:47:04 2011] [alert] [client 127.0.0.1] N:/Web-dev/www/.htaccess: Invalid command 'ReDELETEMEwriteEngine', perhaps misspelled or defined by a module not included in the server configuration
But making same, to RewriteRule, changes nothing, like if it ignores those. I'm out of options, what to do!?
Making more tests, I get to strange results - added some DELETEME before RewriteEngine command - it fails with error, if I add anything afterwards, it ignores it, like if there would be no errrs!
Then I recall my experience with regex and text analysis, I wondered, if tampering with CRLF would do any good, and uncovering, what is current file new line symbols, uncovered that they where CR's. As I know, Apache is unix based software, I thought, it could misunderstood those, so I converted them to LF's and that was it, everything worked afterwards!
Note to future - make sure, with your editor (EditPlus, Notepad++, etc), that your .htaccess new line symbols are multiplatform compatible (CRLF), or at least unix compatible (LF), if working with apache!

How do you configure the Apache server which ships Mac OS X?

Mac OS X ships with apache pre-installed, but the files are in non-standard locations. This question is a place to collect information about where configuration files live, and how to tweak the apache installation to do things like serve php pages.
Apache Config file is: /private/etc/apache2/httpd.conf
Default DocumentRoot is: /Library/Webserver/Documents/
To enable PHP, at around line 114 (maybe) in the /private/etc/apache2/httpd.conf file is the following line:
#LoadModule php5_module libexec/apache2/libphp5.so
Remove the pound sign to uncomment the line so now it looks like this:
LoadModule php5_module libexec/apache2/libphp5.so
Restart Apache: System Preferences -> Sharing -> Un-check "Web Sharing" and re-check it.
OR
$ sudo apachectl restart
Running
$ httpd -V
will show you lots of useful server information, including where the httpd.conf file can be found.
To get SSI/includes (mod_include) to work I found I had to edit /private/etc/apache2/users/myusername.conf and change AllowOverride None to AllowOverride All.
Then add the following in a .htaccess file in the root of your site:
Options +Includes
AddType text/html .html
AddOutputFilter INCLUDES .html
httpd.conf is in /private/etc/apache2
Enable PHP by uncommenting line:
LoadModule php5_module libexec/apache2/libphp5.so
/etc/httpd/users contains user-specific configuration files which can be used to override the global configuration. For example, adding "AddHandler server-parsed html" to the <Directory> block in the /etc/httpd/users/*.conf file that corresponds to one user will enable mod_include parsing of HTML files for that particular user's $HOME/Sites directory, but nowhere else.