CF file not found with Apache virtual hosts - apache

I have Apache 2.2 configured to run with Coldfusion 9.2, both on the same Centos 6.2. The general config of DocumentRoot in Apache is
DocumentRoot "/var/www/html"
Up until now Apache handed all calls to cfcs and cfms over to Coldfusion. I then created a virtual host
<VirtualHost 192.168.123.207:80>
ServerName myserver.server.private
ServerAlias www.myserver.server.private
ServerAlias webmail.myserver.server.private
ServerAlias admin.myserver.server.private
DocumentRoot /home/myserver/public_html
ErrorLog /var/log/virtualmin/myserver.server.private_error_log
CustomLog /var/log/virtualmin/myserver.server.private_access_log combined
ScriptAlias /cgi-bin/ /home/myserver/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/myserver/public_html>
Options +Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch
allow from all
AllowOverride All
Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
<Directory /home/myserver/cgi-bin>
allow from all
AllowOverride All
Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.myserver.server.private
RewriteRule ^(.*) http://myserver.server.private:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.myserver.server.private
RewriteRule ^(.*) http://myserver.server.private:10000/ [R]
</VirtualHost>
When I open a html file on http://myserver.server.private/hello.html, the correct file within the virtual host document root (/home/myserver/public_html) gets served.
Calling a cfm fails though. Apache passes the request on correctly but then a Coldfusion error message shows up:
File not found: /hello.cfm
It seems that Coldfusion is getting the file name, prefixes a wrong directory path to it and fails loading it from the disk.
I scanned all Coldfusion files for a wrong document root but could not find anything.
EDIT
It turns out that Coldfusion looks into it's own webroot directory at
/opt/coldfusion/wwwroot
I placed a file with the same name but different content there and that one gets served, although there is a) a virtual host and b) the general DocumentRoot is set to /var/www/html.

It turns out that the coldfusion user (cfusion in my case) needs to be in the group of the virtual host user.
usermod -a -G newuser cfusion
After a restart of coldfusion, all works.

Related

Setup subdirectory redirect to a Laravel project

I have three projects, First one is a static html website and other 2 projects are Laravel projects.
I have an SSL certificate set up for the main website. I want to setup the other Laravel projects as subdirectories of the main URL.
I added an alias to my conf file, but it doesn't work. I get this error: "Too many redirects occurred trying to open “https://example.com/admin/”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page."
Are there any changes that I should add to htaccess file?
Here is my website.conf file
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/***********.crt
SSLCertificateKeyFile /etc/apache2/ssl/*********.key
SSLCertificateChainFile /etc/apache2/ssl/*********.crt
ServerAdmin admin#example.com
DocumentRoot /var/www/html/example/public_html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /admin "/var/www/html/admin"
<Directory "/var/www/html/admin">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Alias /admin2 "/var/www/html/admin2"
<Directory "/var/www/html/admin2">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
I would suggest taking a look at Vagrant with Laravel Homestead prebuilt box. This will achieve what you want to do by editing the Homestead.yaml file, the /etc/hosts file, and then provisioning the vagrant machine. You will need virtual box installed to work with vagrant. You can SSH into the machine by typing vagrant ssh inside the homestead directory.
Documentation: https://laravel.com/docs/5.4/homestead
YouTube Video about Vagrant: https://www.youtube.com/watch?v=LyIyyFDgO4o
Youtube Videos about Installing Laravel Homestead: https://www.youtube.com/watch?v=tbPGuikTzKk&list=PLfdtiltiRHWEaImCreOC7UkK4U5Xv9LdI
You should use the public folder as your alias in the apache setup.
Try "/var/www/html/admin2/public" and also for the Directory as well.
Something like this:
Alias /admin2 "/var/www/html/admin2/public"
<Directory "/var/www/html/admin2/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Depends on the installation of Laravel, you should have an .htaccess file in the public directory, which might require some additional tweeking.
Also, restart apache once you have made the change.t
You need to correctly set 2 things :
Your sites's alias in WAMP's alias folder e.g. C:\wamp\alias to redirect URL to public\index.php in Laravel's folder
Rewrite base .htaccess in your Laravel's public folder so that Apache rewrites on top of a base path.
Assuming that your site's directory is in C:\wamp\www\site and your alias is localhost/alias
Setting alias to point to public folder:
Alias /site "/var/www/site/public"
<Directory "/var/www/site/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Add RewriteBase in .htaccess in Laravel's public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase '/site/'
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Lamp server not showing file without extension

I am getting a weird issue i created a vhost in lamp stack. The problem is that when I open the vhost site www.domain.com the home page loads without any issue.
But when I use the nav bar to open another page I get a "404 NOT FOUND" i.e www.domain.com/about
But as soon as I put the extension of the file manually the page loads.
www.domain.com/about.php
How can I solve this issue. I am using .htaccess to hide the extension of the file.
Note:
1) All the other local file running properly i.e. I have a wordpress site that works fine (This means the mysql db is not causing the error)
2) The vhost is set properly bcus the terminal did not show any error when the vhost was enabled.
But the vhost in wamp does not give me any kind of issue in my windows 8.1 pro.
Edit :
Code in .htaccess to hide extension this works in my windows pc without any problem.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
EDIT -2
<VirtualHost *:80>
<Directory /var/www/stab-website>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
DocumentRoot "/var/www/stab-website"
ServerName stab-site.com
ServerAlias www.stab-site.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Still did not worked.
You need to enable the MultiViews options:
<VirtualHost *:80>
<Directory /var/www/htdocs>
Options Indexes FollowSymLinks MultiViews
</Directory>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/var/www/htdocs"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
</VirtualHost>
This can either be done in your httpd.conf file, in the configuration file for your virtual host or in a .htaccess file.
You should also make sure so that the mod_negotiation module is enabled. This can be done by running:
sudo a2enmod negotiation
You also might need to verify that your virtual host configuration is fine, this can be done from the terminal using:
apache2ctl -t
After this you need to restart your server:
sudo service apache2 restart
From the documentation:
The effect of MultiViews is as follows: if the server receives a
request for /some/dir/foo, if /some/dir has MultiViews enabled, and
/some/dir/foo does not exist, then the server reads the directory
looking for files named foo.*, and effectively fakes up a type map
which names all those files, assigning them the same media types and
content-encodings it would have if the client had asked for one of
them by name. It then chooses the best match to the client's
requirements.
Thanks #Cyclone for your help
This post helped me to fix this issue
https://askubuntu.com/questions/233046/how-to-give-my-user-permission-to-add-edit-files-on-local-apache-server
The post above help to run Apache server as the logged in user.
To give rights to use .htaccess --
First, you should ensure that your username is included in www-data group. If not, you can add your username as www-data group
sudo adduser $USER www-data
After that, you should change the ownership of /var/www to your username
sudo chown $USER:www-data -R /var/wwws
And also don't forget to add this code in the apache2.conf
<Directory /var/www/ProjectRootDirectory>
AllowOverride All
</Directory>

Multiples VirtualHost for Symfony3 projects in AWS development environment

We have a problem with access to multiple Symfony3 projects that are in different folders and targeted to the same IP address but in different ports on EC2, for example:
project1:
52.1.1.1:8080/login
/var/www/html/projects/project1/
project2:
52.1.1.1:8181/login
/var/www/html/projects/project2/
Happens that when entering the Project 1 (52.1.1.1:8080) it is displayed correctly, but afterward when accessing to Project 2 (52.1.1.1:8181), this fails, strangely deploys the information from Project 1.
In another scenario, when rebooting the apache service and entering the Project2 (52.1.1.1:8181) all is displayed correctly, but if after entering in the Project2, we enter the Project 1 (52.1.1.1:8080) the information from Project2 is displayed, instead of that of the Project 1.
Ports 8080 and 8181 are open.
Apache configuration on the server is the following:
Listen 8181
<VirtualHost *:8181>
DocumentRoot "/var/www/html/projects/project1/web"
DirectoryIndex app.php
<Directory "/var/www/html/projects/project1/web">
Require all granted
Order allow,deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
<Directory /var/www/html/projects/project1>
Options FollowSymlinks
</Directory>
<Directory /var/www/html/projects/project1/web/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
CustomLog /var/www/html/projects/project1/var/logs/reg-access.log combined
ErrorLog /var/www/html/projects/project1/var/logs/reg.error.log
</VirtualHost>
Listen 8080
<VirtualHost *:8080>
DocumentRoot "/var/www/html/projects/project2/web"
DirectoryIndex app.php
<Directory "/var/www/html/projects/project2/web">
Require all granted
Order allow,deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
<Directory /var/www/html/projects/project2>
Options FollowSymlinks
</Directory>
<Directory /var/www/html/projects/project2/web/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
CustomLog /var/www/html/projects/project2/var/logs/reg-rm.log combined
ErrorLog /var/www/html/projects/project2/var/logs/reg.error.log
</VirtualHost>
Any help or ideas about what happens?
UPDATED
To access the Project 1, logs the following error:
[2016-08-17 07:33:12] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalErrorException: "Error: Cannot redeclare class Doctrine\Common\Annotations\Annotation\Target" at /var/www/html/projects/project2/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php line 31 {"exception":"[object] (Symfony\Component\Debug\Exception\FatalErrorException(code: 0): Error: Cannot redeclare class Doctrine\Common\Annotations\Annotation\Target at /var/www/html/projects/project2/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php:31)"} []
"Vendors" is referenced strangely to another project
I found a temporary solution, I had to modify the "app/autoload.php" file
Before
$ loader = require __DIR__.'/../vendor/autoload.php';
After
$ loader = require __DIR__.'/../../project1/vendor/autoload.php';
And it all worked properly.
But I communicated with Javier Eguiluz and he suggested to try installing APC on the server, I installed it, rolled back the changes to the file "app/autoload.php" and it worked properly.
EDIT #2 based on your comment.
Listen 8181
<VirtualHost *:8181>
Servername project1.com
...
Listen 8080
<VirtualHost *:8080>
Servername project2.com
DocumentRoot "/var/www/html/projects/project2/web"
DirectoryIndex app.php
On a remote host edit your hosts file to include the above host names.
For example, if you are on a remote Windows host, edit the file "c:\Windows\System32\Drivers\etc\hosts" as follows:
52.1.1.1 project1.com
52.1.1.1 project2.com
Then in your browser use:
http://project1.com:8181
http://project2.com:8080
This should work. Please investigate first before downvoting. Thanks!

apache vhosts ignores rewriterule

I have the following vhosts file:
directoryindex .index.php index.html index.php
options -indexes -multiviews +followsymlinks
<directory /Volumes/dev1/http>
allowoverride all
</directory>
<virtualhost *:80>
documentroot "/Volumes/dev1/http"
rewriteengine on
rewriterule ^.*$ /msg.php [l]
</virtualhost>
There are other virtual hosts, but the one from above is the "catch-all". The problem is that the rewriterule is totally ignored.
Going to site.com gives a 403 error and site.com/test just returns a 404 Not Found page instead of serving the msg.php file.
The server is a OS X 10.8 Server running Apache 2.2.24
it seems that you are in the wrong dir.
For what reason ever Apple left the .conf files for the virtual host under this directory.
/Library/Server/Web/Config/apache2/sites

File not found with VirtualHost and mod_rewrite

I'm bulding a RESTful api based on Tonic.
On my developer machine and our stage server we use virtual hosts.
Tonic uses a .htaccess file to translate the incomming calls to it's dispatcher.php file. This works fine on servers without VirtualHosts enabled.
However if i enable VirtualHosts i get a file not found even thought the path and name to the file is correct.
Here is the VirtualHost setup on my developer machine.
<VirtualHost *:80>
ServerAdmin admin#xxxxxxxxxxxx
ServerAlias *.dev.xxxxx
VirtualDocumentRoot /home/xxxxxxxx/workspace/%1
<Directory /home/xxxxxxxx/workspace/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And Tonic's .htacces located in a folder called rest in the project root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !dispatch\.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* dispatch.php [L,QSA]
</IfModule>
A call to http://project.dev.xxxxx/rest/ gives:
Not Found
The requested URL /home/xxxxxxxx/workspace/project/rest/dispatch.php was
not found on this server.
Apache/2.2.22 (Ubuntu) Server at xxxxxxx Port 80
It appears as though you're misusing VirtualDocumentRoot. Try changing it to:
DocumentRoot /home/xxxxxxxx/workspace/project/rest
Also, here's a good explanation on the VirtualDynamicRoot: Dynamically configured mass virtual hosting
Hope that helps.