Ok, so I have spent a considerable amount of time googling for suggestions for this, and despite setting up several test project in Laravel 4 before on WAMPserver, I am not sure what I am missing in this case. Hopefully I have provided all details necessary on my setup and what I have tried so far.
WAMPserver version 2.4, located in C:/wamp/
Apache version 2.4.4
PHP version 5.4.12
mod_rewrite enabled (I can see it in phpinfo())
Project located in C:/wamp/www/wsrp/
in C:/wamp/www/wsrp/public I have the following .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
In my C:/wamp/bin/apache/Apache2.4.4/conf/httpd.conf file I have uncommented this line:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
In my C:/wamp/bin/apache/Apache2.4.4/conf/extra/httpd-vhosts.conf file I have the following:
<VirtualHost *:80>
DocumentRoot "C:\wamp\www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/wsrp/public"
ServerName localhost
Options Indexes FollowSymLinks
<Directory "C:/wamp/www/wsrp/public">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
In my C:/wamp/www/wsrp/app/routes.php file I have this test route:
Route::get('test', function() {
echo 'Hello world!';
});
To test I am trying to visit this URL:
http://localhost/wsrp/test
And this doesn't work, it shows me an Internal Server Error page. If however I visit this URL:
http://localhost/wsrp/index.php/test
I see my 'Hello world!' message displayed.
Obviously I want to be able to work on this project without having the index.php in the URL, that is the problem.
Of all the SO questions/answers I have looked at, they have all suggested adding a virtual host, which I've done, having the right .htaccess file in C:/wamp/www/wsrp/public/ which I've done, having mod_rewrite enabled, which I've done and yeah.. not sure what else to try, or what I am missing. Help and suggestions greatly appreciated!
Edit:
Forgot to mention that I also have an alias file in C:/wamp/alias/wsrp.conf
Alias /wsrp "c:/wamp/www/wsrp/public"
<Directory "c:/wamp/www/wsrp/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Allow from all
</Directory>
Firstly why do you have a localhost v-host? The root directory for WAMP servers is typically c:/wamp/www that is already mapped by HOSTS to 127.0.0.1 or localhost. That v-host is irrelevant.
Secondly, as your c:/wamp/www directory is being used to contain your sites, httpd.conf already contains the <Directory> details it needs, from memory it looks something like:
<Directory c:/wamp/www>
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
You don't need to define any special directory information for sub directories unless you want to add specific module configuration or change any of the defaults. To get your vhost working you need add no more than:
<VirtualHost *:80>
ServerName mylocalsite.dev
DocumentRoot c:/wamp/www/mysite/public
</VirtualHost>
I would suggest however that you put in locations for error logging / access logging.
I've had the same problem that you. I solved this problem in this way.
Open C:\wamp\bin\apache\Apache2.4.4\conf/httpd.conf
Then, You may search the next line, #LoadModule rewrite_module modules/mod_rewrite.so
Remove the pound ('#') sign at the start and save the file.
Next, restart your WampServer and test.
I hope help you!
Related
I know this question is asked a lot but I read all the questions related to this but they didn't solve my problem.
I just deployed a Symfony 3 web app and I followed the Symfony server configuration documentation just to find out that the www.domain.com displays the directory structure!
Here's the configuration that I used of file /etc/apache2/sites-available/site.com.conf:
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride None
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>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
I can see the app when I go to www.domain.com/web and www.domain.com/web/app.php
I want to be able to visit www.domain.com and see the app.
Change the line:
AllowOverride None
to next one:
AllowOverride All
Remove section <IfModule mod_rewrite.c> And use standard Symfony's .htaccess file.
Also you need to set up PHP as module for your apache. Be sure to have uncommented line in http.conf that loads PHP module:
LoadModule php7_module libexec/apache2/libphp7.so
You are missing your DirectoryIndex app.php or DirectoryIndex dev_app.php contained in your directory tag. This will cause apache to load app.php if a file has not been requested.
https://httpd.apache.org/docs/2.0/mod/mod_dir.html
<Directory /var/www/project/web>
DirectoryIndex app.php
...
</Directory>
Also make sure mod rewrite is enabled.
a2enmod rewrite
You may have to use sudo.
One final note:
Options -MultiViews should be contained inside the <Directory> for use all the time and not just when mod_rewrite is enabled.
i have been through lots of topic about this, and the thing is still not working so i was wondering if you could help me to see what i am doing wrong.
My goal is to have neat URL as www.name.com without the app.php nor web, and i have changed over and over my Virtualhost & Htacces that my page are kind of gone for now^^ (Yeah so pro)
So first, i have enabled the rewrite mod, and i am running a 2.2.2 apache version.
Here is my VirtualHost files :
<VirtualHost *:80>
ServerName steeph
ServerAlias name.com
DocumentRoot /home/ksc/www/symfony/web
<Directory /home/ksc/www/symfony/web>
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
I have also tried with line on :
<Directory "path">
DirectoryIndex app.php
Options -Indexes
AllowOverride All
Allow from All
</Directory>
which are not working either
For my htaccess i have tried at the symfony files root (and removing the /web from the virtual host) which was a fail, and i tried with this htaccess
<IfModule mod_rewrite.c>
RedirectMatch permanent ^/app\.php/(.*) /$1
RewriteEngine On
RewriteBase /web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
I tried with the "RedirectMatch permanent ^/app.php/(.*) /$1" and without
So i have been to like a dozen of stackoverflows and i have tried even not popular answer but it still not working, so i would really appreciate some help here
Thanks a lot!
If Linux... enable Rewrite
sudo a2enmod rewrite
sudo service apache2 restart
You could just copy the one from symfony standard edition
-> https://github.com/symfony/symfony-standard/blob/master/web/.htaccess
and it would just work fine.
I've been trying for a few hours to install Laravel 4 and make the Virtual Hosts and Routing work but so far I've been unlucky. I'm mentioning that I'm doing this on a Windows 7 machine and WAMP.
I'll describe what I've already done:
I've enabled rewrite_module.
Updated httpd-vhosts.conf with the following:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
</VirtualHost>
Next, I've set up the etc/hosts:
127.0.0.1 localhost
127.0.0.1 laravel.dev
Also, the following lines are uncommented both in wamp/../conf/httpd.conf and in wamp/.../conf/original/httpd.conf:
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include conf/extra/httpd-vhosts.conf
The content of my .htaccess is the following:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Yet, when I go to http://laravel.dev I get an Internal Server Error - The server encountered an internal error or misconfiguration and was unable to complete your request..
If i remove the .htaccess file from the public folder, then I'll see the Laravel "You have arrived" message. If then, i create a route like this (within the app\routes.php):
Route::get('/newroute', function()
{
return View::make('hello');
});
and then go to http://laravel.dev/newroute I'll end up with a 404 Not Found - The requested URL /newroute was not found on this server.
I am seriously confused and have no idea how I can get past this. I mention (although i think it's clear) that I ran a composer install after cloning the project template, installing the dependencies.
If the htaccess file that you posted was in your /public/ folder, then that's why you're getting a 500 internal server error. That htaccess file was made for the folder that the /public/ folder is in. But since your public folder is the document root, you don't need it.
The htaccess file in the /public/ folder should look like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
(for WAMP).
Try turning on AllowOverride All on the directory by changing your VirtualHost to:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
<Directory "c:/wamp/www/laravel/public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I have gone through the same issue and followed the all the treatments given above but virtual host can not be set.
When I inspected file http.conf then I found that inclusion of file httpd-vhosts.conf was commented as given below. Make sure to include httpd-vhosts.conf in httpd.conf.
#Include conf/extra/httpd-vhosts.conf
I have removed the # comment. Restarted the wamp and it was working.
Include conf/extra/httpd-vhosts.conf
Probably this error has a pretty easy solution but I've been looking way to long at this and still don't get the error. I think I've tried whatever I could.
Problem: when I enable pretty permalinks on my wordpress installation (so, that it is using /%postname%/), it doesn't work. I get a 404 on all pages except for the homepage.
This page http://codex.wordpress.org/Permalinks tells me the requirements for permalinks to work:
Apache web server with the mod_rewrite module installed
In WordPress's home directory,
The FollowSymLinks option enabled
FileInfo directives allowed (e.g. AllowOverride FileInfo or AllowOverride All)
An .htaccess file (if this file is missing, WordPress will try to create it when you activate "pretty" permalinks)
If you want WordPress to update the .htaccess file automatically, WordPress will need write access to the file.
Apache web server has been installed, the mod_rewrite module has been loaded with a2enmod rewrite command (and the server has been restarted multiple times after). So, under /etc/apache2/mods-enabled, the symlink to rewrite.load is present. Also, when I run phpinfo command, I see that the mod_rewrite module has been loaded. You can check this as well here: http://namorti.com/phpinfo.php
Then, in /etc/apache2/sites-enabled, there was no "default" present. I copied 000-default.conf to default and edited default afterwards. It contains the following:
DocumentRoot /var/www
<Directory />
Options FollowSymLinks Indexes
AllowOverride FileInfo
</Directory>
So as far as I'm concerned, FollowSymLinks has been enabled and FileInfo directives are allowed.
As for the last two points, in my wordpress home directory (/var/www), .htaccess is present and writeable by Wordpress (I updated the permalink structure a couple of times and it updates the .htaccess file accordingly). Right now it contains the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
So, as far as I know, it SHOULD be working. I restarted the server (service apache2 restart) several times. I don't see what I'm missing. Anyone has a clue here?
Thanks in advance!
* EDIT *
So, I did what calcinai told me to do... I edited my /etc/apache2/sites-enabled/default file (containing the vhost). It now looks like this:
<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 www.namorti.com
DocumentRoot /var/www
<Directory /var/www>
Options MultiViews
AllowOverride None
Order allow,deny
allow from all
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>
# 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
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
I've restarted apache again, but unfortunately it still doesn't work. Honestly it would have surprised me, because moving the directives from the .htaccess file to the vhost would work if the htaccess on itself would work, as everything else seemed correct enough to me...
Any other suggestions? Thanks for the effort!
Make sure the AllowOverrides directive is set to all in the vhost - that's what tells apache to look for .htaccess files in the webroot.
A better solution is actually to put your rewrite directives in the vhost, as you clearly have write access to the file. When you have AllowOverrides on, apache will look in the directory and all parent directories for .htaccess files on every request, which can be a big performance hit.
For Wordpress, your vhost should look something like:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/site
<Directory /var/www/site>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>
</VirtualHost>
Solved it myself.
It had to do with the file "000-default.conf" - I copied it to "default" and edited "default", like I already mentioned in my question.
Apparently the service is using the file "000-default.conf" on itself. By copying the "default" file back to "000-default.conf" and restarting the apache service, everything works now.
One caveat: calcinai's suggestion seems like it should work, but with his suggestion in my vhost in the correct "000-default.conf" file, I got a 403 Forbidden error. When I replaced his content with my original content
DocumentRoot /var/www
<Directory />
Options FollowSymLinks Indexes
AllowOverride FileInfo
</Directory>
And then once again restarting the apache service, it all worked.
Thanks calcinai for your effort to try to help me :)
Permalink Problem
Inside of this file, we want to change all things.
sudo nano /etc/apache2/sites-available/000-default.conf
000-default.conf
- should look something like this:
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
If you dont see like this then paste the above code inside virtual host
When you are finished, save and close the file.
Next, we need to enable the rewrite module, which allows you to modify URLs. You can do this by typing:
sudo a2enmod rewrite
After you have made these changes, restart Apache:
sudo service apache2 restart
This may help you solve this:
sudo chown -R www-data:www-data /var/www
After spending really lots of time, here is what worked successfully in my Linux machine's LAMP server. Following changes are needed for me to make it work perfectly,
Add this to your /etc/hosts file.
127.0.0.1 sitename.com
Add host entry as follows in the path /etc/apache2/sites-available/sitename.com.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName sitename.com
DocumentRoot /var/www/sitename.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/sitename.com/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Create symlink to sites-enabled.
sudo ln -s /etc/apache2/sites-available/sitename.com.conf /etc/apache2/sites-enabled/sitename.com.conf
Restart apache by using the command,
sudo service apache2 restart
This works perfectly for me. Instructions for adding host entry taken from, https://www.digitalocean.com/community/questions/wordpress-permalinks-not-working-on-ubuntu-14-04
I just created my first Symfony2 project. But the "/web/app_dev.php" part in the URL annoys me. It should be possible to do this without Virtual hosts...
But when I try this through .htaccess I always get routing errors and the "web/" is always added to the url...
EDIT: The whole project is also in a subdirectory named "symfonyTest". The Url to the demo page is "http://localhost/symfonyTest/web/app_dev.php/demo/" and it should become "http://localhost/symfonyTest/demo/". Links should also have this syntax. Is this possible?
Symfony2 comes with a built in debug mode, which is what you are using when you access url's with the app_dev.php addition. The debug mode caches significantly less than the production mode which can be accessed by directing your browser to the url, but leaving out the app_dev.php. If accessing this url doesn't work then it probably means that you need to clear your production cache.
To clear the cache direct you terminal (command console) to the root of you Symfony project. From there type the following command:
php app/console cache:clear --env=prod --no-debug
Per comments below in Symfony 3 this has moved:
php bin/console cache:clear --env=prod --no-debug
This should clear your productions cache and allow you to access urls without the app_dev.php.
As for the web part of the url. The easiest way to remove that is to set the web root of your project to the web folder. It's best to do this with apache using virtual hosts, but there are ways to do it with the htaccess.
This link explains how to use the htaccess file to change the webroot.
http://kb.siteground.com/how_to_change_my_document_root_folder_using_an_htaccess_file/
Hope this helps!
<VirtualHost *:80>
DocumentRoot "path_to_symfonyTest/web"
ServerName "symfonyTest"
<Directory "path_to_symfonyTest/web">
DirectoryIndex app_dev.php
AllowOverride All
Order allow,deny
Allow from all
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_dev.php [QSA,L]
RedirectMatch permanent ^/app_dev\.php/(.*) /$1
</Directory>
</VirtualHost>
That's part of my httpd.conf
I used to have this problem too, please take a look at my configurations and try them out
inside my .htaccess:
Hi all, I have been having this problem too. And it seems that the "stock" .htaccess is the problem. I have solved this in my environment and here is my .htaccess with notes:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app_dev.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app_dev.php [L] ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the startpage to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
inside my "symfony" entry in /etc/apache2/sites-available:
<VirtualHost 127.0.1.15>
ServerAdmin webmaster#localhost
ServerName symfony
DocumentRoot /var/www/Symfony/web
DirectoryIndex app.php
<Directory /var/www/Symfony/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
If you use an apache virtual host, you can get it working the way you desire. Here is an example virtual host from my xampp:
<VirtualHost *:80>
ServerName myurl.local
# Basic stuff
DocumentRoot "C:/path/to/symfony/web"
DirectoryIndex app.php
<Directory "C:/path/to/symfony/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
After restarting your apache, you can access the project through http://myurl.local (don't forget to configure your hosts file under C:\Windows\system32\drivers\etc\hosts!). If you want to have the dev environment (app_dev.php) not showing up in the url, change the DirectoryIndex to app_dev.php.
//enable mod rewrite
sudo a2enmod rewrite
Change all occurrences of AllowOverride None by AllowOverride All File: (/etc/apache2/apache2.conf) or (/etc/apache2/sites-available/000-default.conf) - for me work with /etc/apache2/apache2.conf file.
Example:
<Directory /var/www/web/>
# enable the .htaccess rewrites
Options Indexes FollowSymLinks
#AllowOverride None #commented
AllowOverride All
Require all granted
</Directory>
//Restart apache service: sudo service apache2 restart
You would need .htaccess file in parent folder of web, however, I wouldn't suggest doing so. That folder, apart from web, contains complete source, binaries, vendors and much more therefore you would need to apply many rules just to allow web-access to web folder and disallow web-access to everything else.
So, it's doable, but I would definitely go for vhost solution...
you just need to copy the content of .htaccess file to the your-website.conf
inside the TAG Directory