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

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.

Related

Cgi/perl scripts display as code in Monterey

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>

How to Enable CORS for Apache httpd server? (Step-By-Step Process)

I was wondering if anybody can help me set up CORS on my Apache web server. I would appreciate a step-by-step process because many sites online are telling me different things. Like what do I need to do on my httpd.conf or ssl.conf files, where to put my .htaccess file, etc.
The above answer is correct and put Inside the httpd.conf. This should be changed to whatever you set Document Root.
On Ubuntu, httpd.conf is located in the directory /etc/apache2. apache2.conf is also located in /etc/apache2.
On CENTOS 6 httpd.conf in the path /etc/httpd/conf/httpd.
<Directory "/var/www/html">
Header set Access-Control-Allow-Origin "*"
</Directory>
# edit your conf/httpd.conf file. Verify that the headers module is loaded
LoadModule headers_module modules/mod_headers.so
# to whitelist every origin, use
Header set Access-Control-Allow-Origin "*"
More info: http://enable-cors.org/server_apache.html

.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.

Passenger just showing directory in Apache

I am trying to use Passenger to deploy a rails app on Ubuntu with Apache. I've followed pretty much every guide I could find on configuring Passenger with Apache/Ubuntu. However, when I go to the site, I just see the actual file directories and not the running version of the application. If i switch to the /public directory I just see the public directory when I go to the site. I can start and stop the rails server by calling rails s without getting any errors, but still am not able to see the running version of the application. Does anyone ran into similar problems? Is there a good starting point anyone could suggest I look at? I'm not sure if the problem is with apache or passenger.
Apache config
LoadModule passenger_module /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRuby /usr/bin/ruby
PassengerRoot /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.9
PassengerMaxPoolSize 10
<VirtualHost *:80>
ServerName http://www.myapp.com/
DocumentRoot /var/www/myapp/current/
<Directory /var/www/myapp/current/public>
Allow from all
</Directory>
When I restart apache, I get a message stating [Sun Nov 06 14:43:48 2011] [warn] module passenger_module is already loaded, skipping I'm not sure if this is an error or is normal.
Update
When I run find / -name 'mod_passenger.so' I get two locations:
/usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
/usr/lib/apache2/modules/mod_passenger.so
Update 2
I have several passenger.config files
/etc/apache2/mods-enabled/passenger.conf
/etc/apache2/mods-available/passenger.conf
/usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/debian/passenger.conf
Each of the passenger.conf files has the following:
<IfModule mod_passenger.c>
PassengerRoot /usr
PassengerRuby /usr/bin/ruby
</IfModule>
Try to put following in apache config file
<Directory /var/www/myapp/current/public>
Allow from all
#Add following line
Options +Includes -Indexes
</Directory>
You may have mod_passenger.so symlinked into your apache2/mods-enabled directory. This would account for the double import.
Run
a2dismod mod_passenger.so
to remove any symlink, then restart Apache.

Looking for "localhost" apache server that allows .htaccess

Is there some apache server software out there that can be installed on my Windows PC (for local development purposes) that also allows .htaccess for URL rewriting?
I'm currently using Xampp which does not seem to offer this functionality (although maybe I'm wrong about that).
Any advice would be much appreciated.
Thanks.
You will have to activate mod_rewrite in your apache config. Go to your xampp folder an you will find the httpd.conf file in apache/conf/. Open it an go to the line with:
#LoadModule rewrite_module modules/mod_rewrite.so
Change it to
LoadModule rewrite_module modules/mod_rewrite.so
Save the httpd.conf and restart your apache. Now mod_rewrite should work.
Xampp will do it, you'll need to enable mod_rewrite first.
open the directory you installed Xampp then open \apache\conf\httpd.conf in notepad and search for mod_rewrite.
Uncomment the line by removing the # from the beginning. By default mod_rewrite is disabled on a fresh install.
LoadModule rewrite_module modules/mod_rewrite.so
Restart Xamppp should take .htaccess rules now.
It's true that by default, Xampp on windows does not support URL rewriting.
However it's an pretty easy fix:
In your httpd.conf file, find the line that contains "mod_rewrite" and remove the # in front of it
Again in your httpd.conf file, find all occurrences of AllowOverride None and change it to AllowOverride All
Restart apache and you're done:)