I dont know how to get CakePHP to run in a virtual host on my local machine. I can get the code to work on the default http://localhost:8888/caketest/ but cant get it to work from http://cakeapp.local:8888/ where I get the warning
"URL rewriting is not properly configured on your server. 1) Help me configure it 2) I don't / can't use URL rewriting"
In MAMP's httpd.conf I added
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "/Users/me/Documents/path/to/root/root"
ServerName cakeapp.local
</VirtualHost>
I saw in the help page that it expects
Options FollowSymLinks
AllowOverride All
# Order deny,allow
# Deny from all
but this crashed MAMP
both are CakePHP 2.4.9 with no changes to the default download
Edit: The not working files in /Users/me/Documents/path/to/root/root which dont work were copied to /Applications/MAMP/htdocs where they then worked, so it is an issue with the virtual host
Edit 2:
I thought I had found a solution but It looks like I was wrong. I changed the virtual host to point directly to /app/webroot which has made the default page show correctly, I then proceeded to add the DebugKit plugin (which I have working in a different local host file and the rewrites for its files still dont work.
For example app/Plugin/DebugKit/webroot/css/debug_toolbar.css gets loaded on http://localhost:8888/caketest/debug_kit/css/debug_toolbar.css but the file in the virtual host http://cakeapp.local:8888/debug_kit/css/debug_toolbar.css returns a 404 error (the plugin works), the files just dont get loaded.
If you copied the code from /Application/MAMP/htdocs to /Users/me/Documents/path/to/root/root, did the .htaccess file get copied across as well? This hidden file is often left behind.
OK, I think this works, the last time I tried to fix the directory it was not pointing at the correct directory.
I added the following to the httpd.conf:
<Directory "/Users/me/Documents/path/to/root/root">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
replace with this in your .htaccess file , it worked for me.
RewriteEngine On
RewriteBase /path/to/cake/app
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
Related
I am using Apache 2 on Xubuntu to run multiple local instances of TYPO3. Since they use different TYPO3 and therefore PHP versions, I'm using fastcgi to pass requests to the one with TYPO3 version 9.5.x to the corresponding php7.2-fpm.
However, none of the pages other than "Home", the TYPO3 backend and the phpinfo are loading. I just get a raw 404 message which looks like it's coming from apache rather than from TYPO3 itself.
The only way I can get the pages to load is when I call them using the pageID and a parameter to suppress the redirect to the "more beautiful" URL. This, and the raw error page, make me believe that the problem lies within my Apache config rather than my TYPO3 setup. It seems like every call to a specific file (/index.php, /typo3/index.php, and /info.php) works, but the routing doesn't work because the apache tries to resolve it directly to a file/directory.
This is my apache config for the problematic vhost:
<VirtualHost *:80>
ServerName test.test
DocumentRoot /var/www/foo/bar/httpdocs
# <FilesMatch \.php$>
# SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost"
# </FilesMatch>
ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/run/php/php7.2-fpm.sock|fcgi://localhost/var/www/foo/bar/httpdocs
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The commented part was the first try, when I noticed the problems I found the "ProxyPassMatch"-Part online and tried it out, but I have the same issues.
This is the crucial part of the rewriting in the default .htaccess (that is shipped with TYPO3):
<IfModule mod_rewrite.c>
RewriteEngine On
# ...
# If the file/symlink/directory does not exist => Redirect to index.php.
# For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]
</IfModule>
Important is that all URLs that are not file requests are passed on to index.php
First, check the obvious:
Is mod_write enabled (e.g. a2enmod rewrite)?
Is the .htaccess executed? As mentioned, in the comments, AllowOverride must be set.
For example, within the VirtualHost section, put this:
<Directory /var/www/foo/bar/httpdocs>
# When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files.
AllowOverride All
</Directory>
If that does not solve the problem, you can try narrowing down the problem step by step:
For example create a file /abc.txt with text "hello" in your web root. Then, add this before the TYPO3 rewrite blocks.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule /?xyz /abc.txt [L]
</IfModule>
Test the URLs /abc.txt, /xyz. They should both show "hello".
This way you can check if the rewrites work in general (without involving TYPO3). Once the test is successfull, remove again.
see also Troubleshooting in the Installation Guide, which also mentions the mod_rewrite.
Disclaimer: I don't know about the ProxyPassMatch but it seems to be generally working from what you described.
I developed a site on wamp that works perfectly (.htaccess included).
so I deployed the site on a debian server, but I have the following error :
404 Not Found - The requested URL was not found on this server.
here are the contents of my file :
#Options FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z\_\-]+)/([a-z0-9_\-]+)/?$ index.php?page=$1¶m=$2 [QSA]
RewriteRule ^([a-zA-Z\_\-]+)/?$ index.php?page=$1 [QSA]
all files belong to the user www-data.
rewrite module is enable.
Thx.
In your apache configuration.
On the virtualhost or default config you must AllowOverride to your domain or folder.
<Directory "/">
AllowOverride ALL
</Directory>
If you can not override your .htaccess is not going to work and if you can not rewrite the url you are accessing does not exists and you are going to get a 404 error.
I think this is an easy one, but i'm really confused myself.
myproject.com/index.php shows my project main page
myproject.com shows my project main page too.
In 1st case, after routing it works fine (i.e. : myproject.com/index.php/register)
In 2nd case, after routing it fails (i.e. : myproject.com/register) with following error : The requested URL /register was not found on this server.
So because of that, i thought that i had to re-route every request for myproject.com to myproject.com/index.php
app/config/app.php :
'url' => 'http://127.0.0.1/public',
etc/httpd/conf/httpd.conf :
<VirtualHost *:80>
DocumentRoot "/var/www/html/myproject/public/"
ServerName myproject.com
</VirtualHost>
Nothing's been configured in hosts file.
Goal: how can i re-route all requests from myproject.com to myproject.com/index.php with hiding index.php part of from users ?
Visitors should see that : myproject.com
but i want them to actually reach : myproject.com/index.php
Workaround:
<VirtualHost *:80>
DocumentRoot "/var/www/html/myproject/public/index.php"
ServerName myproject.com
</VirtualHost>
Result : I cannot reach the assets, (js, css files) results with 404 because my browser is not allowed to reach myproject.com/public/. Root has been set as myproject.com/public/index.php in this virtualhost settings.
Check if the .htaccess file is present in your public directory.
If not check the Pretty Url Section.
Also make sure that you put <Directory> directives in your vhost configuration just to be on the safe side.
Eg:
<Directory "/var/www/html/myproject/public/">
AllowOverride All
Allow from All
</Directory>
Concerning the 'url' => 'http://127.0.0.1/public', in app.php am pretty much sure the /public is kinda extra.
'url' => 'http://127.0.0.1', should be working fine.
You need rewrite rules for this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Laravel docs: http://laravel.com/docs/5.1#pretty-urls
I want to host two instances of the same Symfony2 application on one Apache server. Each application should be addressed like so:
http://myserver/app1/
http://myserver/app2/
To do so I have set up two port based virtual hosts in Apache plus the third one on port 80 that redirects folder requests to proper vhosts:
<VirtualHost *:80>
DocumentRoot /var/www
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/app1/(.*)$
RewriteRule ^ http://%{HTTP_HOST}:9999/%1 [L]
RewriteCond %{REQUEST_URI} ^/app2/(.*)$
RewriteRule ^ http://%{HTTP_HOST}:8888/%1 [L]
</VirtualHost>
<VirtualHost *:9999>
DocumentRoot /var/www/app1/web
<Directory /var/www/app1/web>
</Directory>
</VirtualHost>
<VirtualHost *:8888>
DocumentRoot /var/www/app2/web
<Directory /var/www/app2/web>
</Directory>
</VirtualHost>
That works perfectly as http://myserver/app1/ is redirected to http://myserver:9999 and http://myserver/app2/ is redirected to http://myserver:8888 (the URL in browser changes). I want the URL in web browser to stay as http://myserver/app1 or http://myserver/app2.
I can do this by adding switch 'P' to RewriteRule, like so:
RewriteRule ^ http://%{HTTP_HOST}:9999/%1 [L,P]
This however creates problem, because now Symfony sees all requests to be coming from port 80 and redirects them back to that port not to the proper virtual host. I think one way to fix this issue would be to force Symfony2 to prepend all requests with the proper application name.
I tried to do so by modifying generateUrl method in vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php to always add application name in front of generated URL and it worked but only for page requests (assets were missing for example).
So my question is if there is a way to full Symfony into thinking that all requests should go back to proper 'app' URL?
My suggestion is that you don't try to do this via Apache configuration. You can configure each Symfony application to live in a subfolder, see:
http://www.yegods.it/2015/01/30/install-symfony-app-in-a-subfolder-of-an-existing-site/
You only need to edit app.php, app_dev.php and composer.json (for assets).
I got a rather easy problem. How do I remove the path to my website called domain.com?
I've got a lampp server where I put one folder called "domain" in the htdocs folder and to access my website I need to write domain.com/domain instead of just domain.com. And when I write domain.com I come to the usual xampp website
There are a few options, but the easiest is probably using some URL rewriting given your current setup.
mod_rewrite in .htaccess
In your htdocs folder create a .htaccess file:
RewriteEngine On
RewriteBase /
# If the URL does not already exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# or directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domain/$1 [QSA,L,NC]
Virtual hosting with Apache
You could also edit your VirtualHost container in the Apache configuration to change the directory as well. If you are running XAMPP then I have previously written about using virtual hosts with it on my blog.
For example:
<VirtualHost *:80>
ServerAdmin name#domain.com
DocumentRoot c:\xampp\simonholywell.com\pub
ServerName simonholywell.localhost
<Directory c:\xampp\simonholywell.com\pub>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
A development server for teams (or individuals)
I have also written a large article on setting up a development or staging server for a team as well, which would be good reading if you are setting up such a system. It allows you to simply add a folder on the server and it is immediately available as a subdomain without any further configuration. This is something called mass virtual hosting.
You need to add a virtual host, check the apache name based virtual host documentation. If you're running on windows you could follow this guide, if you're on linux/unix you could try the following guide