Adding CGI directives to vhost causes 404 / Not found error - php

I am trying to run two php versions with apache. One (PHP7) is setup with mod and the other (PHP8) I am trying to set up with CGI. I am currently testing both work using the different vhosts for https and http. I have the following virtual hosts in my httpd-vhosts.conf file:
<VirtualHost 0.0.0.0:80>
SetEnv PHPRC "C:/Program Files/PHP/php-8.1.12/"
ScriptAlias /php8112/ "C:/Program Files/PHP/php-8.1.12/"
Action application/x-httpd-8112 "/php8112/php.exe"
AddType application/x-httpd-8112 .php
<Directory "C:/Program Files/PHP/php-8.1.12/">
<Files "php.exe">
Require all granted
</Files>
</Directory>
DocumentRoot "D:/Test/Site/public"
ServerName test.local
CustomLog "C:/Users/me/Logs/test_access.log" combined
ErrorLog "C:/Users/me/Logs/test_error.log"
</VirtualHost>
<VirtualHost 0.0.0.0:443>
DocumentRoot "D:/Test/Site/public"
ServerName test.local
SSLEngine on
SSLCertificateFile "C:/Program Files/Apache24/conf/server.cert"
SSLCertificateKeyFile "C:/Program Files/Apache24/conf/server.key"
</VirtualHost>
and a simple index.php in D:/Test/Site/public:
<?php
phpinfo();
?>
Accessing via HTTPS works and correctly gives me the PHP Info page. Accessing via HTTP gives me a 404 Not Found error, however. Why would this be?
I have tried reordering the directives and adding a directory directive for the DocumentRoot directive. Neither seemed to make a difference.
I am using Apache 2.4 on Windows 10

Related

How to match dynamic sub-domain alias to sub-folder on apache server

I am currently developing a SaaS web based project using PHP which requires users to have unique sub-domains to use the application.
I am done configuring the server with wildcards: Eg. user.example.com ==> *.example.com. The application creates a subfolder for the user under /var/www/html/ with the name of the user Eg. user.example.com would be in /var/www/html/user/.
I am stuck on getting the user's link without the base folder such as user.example.com to point to /var/www/html/user/ without having to include http://user.example.com/user.
I have tried virtual host and aliases but it seems like I have to manually assign the variable which is not applicable for the project.
I just need the subdomains to point to their respective subfolders.
My apache config file
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin admin#xxxxxxx.tdl
DocumentRoot /var/www/html/%1/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
ErrorDocument 404 /error_404.html
</VirtualHost>
Finally after researching I got a solution. I realised that I had not activate the alias module and so I activated as follows:
sudo a2enmod vhost_alias
I also noted that serving each sub-domain to its respective sub-folder required a dynamic config script to auto-pick the VirtualDocumentRoot through Directory Name Interpolation as follows:
<VirtualHost *:80>
ServerAdmin admin#vspace.ke
DocumentRoot /var/www/html/
VirtualDocumentRoot /var/www/html/%1/
<Directory "/var/www/html/">
Options FollowSymLinks
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost>
I also noted that you have to declare all sub-domains and non sub domain in the host configurations:
I.E
Alias for www
<VirtualHost *:80>
ServerName www.vspace.ke
ServerAlias www
DocumentRoot /var/www/html/
<Directory /var/www/html/>
Options +FollowSymLinks
</Directory>
</VirtualHost>
Alias for no sub-domain
<VirtualHost *:80>
ServerName vspace.ke
ServerAlias
DocumentRoot /var/www/html/
<Directory /var/www/html/>
Options +FollowSymLinks
</Directory>
</VirtualHost>
And * (wild card) sub-domain
<VirtualHost *:80>
ServerAdmin admin#vspace.ke
DocumentRoot /var/www/html/
VirtualDocumentRoot /var/www/html/%1/
<Directory "/var/www/html/">
Options FollowSymLinks
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost>
Thank you so much for contributing.

AWS Linux Instance PHP is not being parsed when running from my vhosts

I have set 3 virtual hosts on an AWS Linux AMI instance, HTML files are working file but the PHP files are outputting plain text.
Before I set up the vhosts I tested the PHP files and they were running fine.
I followed these instructions to install the LAMP stack on my instance:
AWS Install LAMP
I have put the vhosts in the /etc/httpd/conf/httpd.conf file, and they look something like this:
<VirtualHost *:80>
ServerName domain1.com
DocumentRoot /var/www/html/domain1
<Directory /var/www/html/domain1>
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName domain2.com
DocumentRoot /var/www/html/domain2
<Directory /var/www/html/domain2>
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName domain3.com
DocumentRoot /var/www/html/domain3
<Directory /var/www/html/domain3>
AllowOverride All
</Directory>
</VirtualHost>
I tried adding this to httpd.conf
AddType application/x-httpd-php .php
but this makes turns the plain text PHP files into downloadable PHP files
Have I been missing something obvious all along?

Serving php files from an aliased directory in Apache HTTPd

I have the following apache config:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
DocumentRoot /var/www/html/public/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/ssl.crt
SSLCertificateKeyFile /etc/apache2/ssl/ssl.key
Alias /login/ /var/www/html/saml_provider/www/
<LocationMatch "^(.*\.php)$">
ProxyPass fcgi://presentation-php-fpm:9000/var/www/public
</LocationMatch>
</VirtualHost>
</IfModule>
hitting www.example.com/hello.php works fine as the LocationMatch block picks up this is a php file and sends it on to the php-fpm engine using proxy-pass.
However, hitting www.example.com/login/hi.php does not work, giving a php "file not found" error. This makes sense, because I guess that it is trying to find the file in /var/www/public but it is actually in /var/www/html/saml_provider/www/.
How can I fix this so that php also serves any .php file on the alias such that:
www.example.com/login/hi.php --- served by php from ----> /var/www/html/saml_provider/www/hi.php

Apache VirtualHosts don't work no matter what

My Problem
I've tried many methods, I've researched a ton of questions on StackOverflow and none of them work! Some info:
I'm running Snow Leopard OS X (10.6.8)
I'm using XAMPP
Apache is loading the default (backup) directory. (See bottom of question for what I mean)
Attempt of solving
Here are the websites I've tried:
Adding VirtualHost fails: Access Forbidden Error 403 (XAMPP) (SO)
Xampp vhosts do not work (SO)
Apache Virtual Host is not working right (SO)
Apache VirtualHost not working (SO)
virtual host not working - Apache Web Server forum at WebmasterWorld
Additional Info
My VirtualHosts File:
<VirtualHost wrks.tk:80>
DocumentRoot "/Apps/XAMPP/htdocs/DNS"
ServerName wrks.tk
ErrorLog "/Logs/wrks.tk-error.log"
CustomLog "/Logs/wrks.tk-access.log" common
<Directory "/Apps/XAMPP/htdocs/DNS">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
What it's actually loading (This is the defualt directory in the httpd.conf file, the "backup" directory):
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/trunk/mod/core.html#options
# for more information.
#
#Options Indexes FollowSymLinks
# XAMPP
Options Indexes FollowSymLinks ExecCGI Includes
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
#AllowOverride None
# since XAMPP 1.4:
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
Couple of things I'd check are:
Making sure you include the httpd-vhosts.conf
# Virtual hosts
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
Set up hosts:
navigate to Macintosh HD/private/etc/hosts, in a text editor and click Open. Then add this line:
127.0.0.1 wrks.tk
And maybe try:
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/DNS"
ServerName wrks.tk
ErrorLog "/logs/wrks.tk-error_log"
CustomLog "/logs/wrks.tk-access_log" common
</VirtualHost>
You may also want to set up localhost again.
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
ServerName localhost
</VirtualHost>
Sorry if some of these paths aren't accurate, you will need to check them against your xamp folder structure.
The simplest implementation I found is this:
http://iwearshorts.com/blog/adding-a-virtual-host-vhost-in-xampp-on-a-mac/

Django/mod_wsgi WAMP with PHP

I followed this guide and managed to make Python with a Django installation work perfectly, but it seems to have rendered all the locally hosted PHP sites inaccessible returning a 404 error.
httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so
#This is placed right after the rule for <Directory "f:/WAMP/www/">
<Directory "f:/WAMP/www/python">
Options ExecCGI
AddHandler wsgi-script .py
Order allow,deny
Allow from all
</Directory>
#This is placed at the end of the file
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
Include "f:/WAMP/alias/*"
Include "F:/WAMP/www/python/sandbox/apache/apache_django_wsgi.conf"
apache_django_wsgi.conf
Alias /python/images/ "F:/WAMP/www/python/sandbox/images"
<Directory "F:/WAMP/www/python/sandbox/images">
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /python "F:/WAMP/www/python/sandbox/apache/django.wsgi"
<Directory "F:/WAMP/www/python/sandbox/apache">
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot f:/WAMP/www/python/sandbox/
ServerName 127.0.0.1
</VirtualHost>
django.wsgi
import os, sys
sys.path.append('F:/WAMP/www/python/sandbox')
os.environ['DJANGO_SETTINGS_MODULE'] = 'sandbox.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
PHP only renders when I comment out the lastline from httpd.conf.
You need to have another virtual host if you're going to set the DocumentRoot:
# This is for PHP
<VirtualHost *:80>
DocumentRoot f:/WAMP/www/
ServerName local.php.dev
</VirtualHost>
# This is for your Django stuff
<VirtualHost *:80>
DocumentRoot f:/WAMP/www/python/sandbox/
ServerName local.py.dev
</VirtualHost>
Otherwise, as it is now, all the local requests are being sent to the python sandbox.
Note that you'll need to have several hosts pointing locally.

Categories