I'm using Symfony 3.4 and Apache 2.4 (on Ubuntu); and I'm trying to get my Symfony project running through Apache instead of the built-in server. I edited the default .conf file in the "sites-available" folder to the following:
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/my_project/web
<Directory /var/www/html/my_project/web>
AllowOverride All
Require all granted
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
When trying any route, all i get is a "requested URL not found" error. Simply going to "localhost"takes me to app.php, which obviously does nothing. I've always restarted apache after every edit. What am i missing (besides a brain)?
If you use composer (which is default for Symfony projects), you can just do composer require symfony/apache-pack, which should install default working .htaccess file into your public directory.
Related
I've a website lets say website.fr ( on server : /web/website ) ;
I ve added a symfony blog app in /web/website/blog/.
I dont manage to access the blog via website.fr/blog/ (404 error)
There is a .htaccess file in /web/website/blog/ directory, and one in /web/website/blog/web directory.
I am used to deploy symfony apps 'alone' on a server, and make the domain point to the web dir of the app, and everything always works fine, but in this configuration, I cant get it to work.
I have tried to use the following .htaccess conf under /web/website/blog/ :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>
And I did not edit the default one under /web/website/blog/web/
Im not sure what Im doing wrong, so any help would be appreciated !
For me I use .. nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
which is explained Here and restart Apache, but I do not know if I understand your problem
I couldn't get what I wanted, but here is the solution I implemented :
I created a .htaccess in /web/website dir, that rewrites all requests to /web/website/blog, with the root (/) excluded from this rewriting :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ blog/web/$1 [QSA,L]
</IfModule>
That's not the way I wanted to get my rewriting, but I have the result I expected ; note that it would not be a good solution for a website that would evolve with new modules, routes, folders...
I have a working Symfony 3 API on an Apache Server - more info here and here these are already resolved
I am now facing a routing problem I think, my postman POST methods working fine if use a URL like: https://example.com/app.php/mcPDF/ but when I try with URL: https://example.com/mcPDF/ it says 404 not found.
I tried several answers here, like changing the htaccess IfModule mod_rewrite.c> section and added various settings in 000-default.conf file like:
<Directory /var/www/html/pdf/web>
AllowOverride All
Order Allow,Deny
Allow from All
DirectoryIndex app.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</Directory>
and every time I do changes I do:
- bin/console cache:clear --env=prod --no-warmup
- bin/console cache:warmup --env=prod
and I also did the sudo a2enmod rewrite and restarted the server many times
Please advise, let me know what info you need more
All my PROD servers use configuration below and they all work fine. Try to update yours accordingly to see what happens.
# $ nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
DocumentRoot /var/www/my_app/current/web
<Directory /var/www/my_app/current/web>
AllowOverride All
Require all granted
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/${APP_NAME}-error.log
CustomLog ${APACHE_LOG_DIR}/${APP_NAME}-access.log combined
</VirtualHost>
UPDATE: Stage dependent configurations are shown here in details. http://www.inanzzz.com/index.php/post/0ew3/deploying-a-symfony-applications-to-staging-and-production-servers-with-capistrano
I'm using Bitnami MampStack on OS X 10.9. Because this is an inherited laptop, I had to set up Apache under MAMP to listen on port 8888. I tweaked it to listen on 8889 as well and added the following as a VirtualHost in my httpd.conf file:
<VirtualHost *:8889>
DocumentRoot "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public"
ServerName localhost
<Directory "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public">
Require all granted
</Directory>
</VirtualHost>
I followed the example here (so all my source code matches his). The index blade works, but the edit, create, and delete blades return a 404.
As I was testing, I discovered that http://localhost:8889/create returned a 404, but http://localhost:8889/index.php/create returned the correct view. Also, browsing http://localhost:8888/codebright/public/create works as expected.
So...me being kinda new to Laravel and MVC frameworks in general, is there some way I can have this installing running properly on port 8889?
Your virtualhost is working as it should, you just have now to be sure your public/.htaccess file is in place:
<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>
This is the file that rewrites your urls removing the /index.php from them.
EDIT
Also, check if you have mod_rewrite installed and enabled, because your .htaccess uses it, in Ubuntu/Debian, to enable it, you have to execute:
sudo a2enmod rewrite
Figured it out, thanks to this. I was missing AllowOverride All in the <Directory> section. Updated httpd.conf:
<VirtualHost *:8889>
DocumentRoot "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public"
ServerName localhost
<Directory "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I thought I might have been missing RewriteEngine On in the VirtualHost definition but it doesn't seem to have an effect on my problem.
This has got me baffled. I recently set up VM in a hurry to go travelling. I installed Ubuntu 12.04 and LAMP. The PHP version is 5.5 and Apache is 2.4. I have used this same configuration on my home machine and it works fine.
Anyhow, the problem is that I can only access actions on the index controller of my ZF application, e.g: domainname/, domainname/index/info. If I try any other controllers, e.g. domainname/test/view, I get the apache 404 error. (Note - NOTE the ZF Not Found error).
I imagine this is a problem with URL rewriting, but the .htaccess on my VM is the same as my home machine, and I can't see anything in the virtual host configuration that would cause this. Also, if it was simply an URL rewriting problem, I would have thought it would come in to play for ALL urls, including the index controller...
Here's my htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Ideas?
EDIT: Here's the virtual host config:
DocumentRoot /home/kim/www/vhost/public
ServerName koop
SetEnv APPLICATION_ENV "development"
<Directory /home/kim/www/vhost/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Ok, so I had to change AllowOverride to All. That means Apache2 will now process my .htaccess files.
Then I needed to enable mod rewrite, by sudo a2enmod rewrite, then restart apache, i.e. sudo service apache2 restart
I recently updated my Xampp server (from 1.7 >> 1.8) and since then I'm no longer able to run my projects written in Symfony 1.4.8.
It says:
You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.
But it has permissions!
Actually it works fine with older version of Xampp. Is it possible that Symfony 1.4.8 is not compatible with Apache 2.4 or PHP 5.4? I'm using Windows 8 Enterprise, but also tested on Windows 7 Ultimate and same problem exists.
Any suggestions would be appreciated.
Here is my config:
NameVirtualHost 127.0.0.1:1111
Listen 127.0.0.1:1111
<VirtualHost 127.0.0.1:1111>
DocumentRoot "D:\AMir\PROJECTS\BarzinMehr\web"
DirectoryIndex index.php
<Directory "D:\AMir\PROJECTS\BarzinMehr\web">
AllowOverride All
Allow from All
</Directory>
Alias /sf C:\xampp\htdocs\symfony\data\web\sf
<Directory "C:\xampp\htdocs\symfony\data\web\sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
And here is my .htaccess
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
after struggling with this problem for so many days, i finally found the solution and i'm taking it here in favour of anyone else who might face this problem. according to this article (thanks to the writer!) all i had to do was this:
change each Directory block like this:
<Directory "your address">
AllowOverride All
Allow from All
</Directory>
to
<Directory "your address">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>
it seems that Allow was dropped in favor of new directive Require in apache 2.4(according to documentation for version apache 2.4)
Try removing the .htaccess file and accessing the index.php file directly. If this works (or at least produces a PHP error, rather than an apache error), it probably means that mod_rewrite is not enabled, and the .htaccess is not working as expected.
I would recommend removing the:
<IfModule mod_rewrite.c>
and it's closing tag from the .htaccess file if they are present because if the module isn't installed, it's better to get an error that it isn't installed, rather than the site just not work in a strange way.
If the above doesn't solve the issue, take a look at apache's error log - this often contains clues.