403 Forbidden error after symfony 2 reinstall - apache

I am building a web app on top of the symfony2 framework. Everything used to work fine until, due to some problems, i had to wipe the production symfony folder clean and reinstall everything inside the symfony project folder.
Now every request to the server returns a 403, You don't have permission to access / on this server.
Note: the server software is apache2 running on ubuntu.
I deployed using capifony, running cap deploy:setup and cap deploy.
Nothing changed in any apache config files or anything outside the root directory of the symfony project. The server root points to symfonyRoot/current/web, the .htaccess file in that directory looks as follows:
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
Edit:
from the apache2.conf file:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
from the virtual host config:
<Directory "/var/www/SymfonyRoot/current/web">
Require all granted
AllowOverride All
Allow from All
Options None
</Directory>
I am sure that it is just one simple thing that i am forgetting somewhere, but i can't figure out why the server is denying permission to any routes.

So, i figured out what was wrong:
Options FollowSymLinks was not turned on for the /var/www/SymfonyRoot/current/web folder.
just added Options FollowSymLinks to the .htaccess file and everything works like a charm again!

Related

Restler setup not working

On my webserver running Apache/2.2.26 (Unix) DAV/2 PHP/5.4.24 mod_ssl/2.2.26 OpenSSL/0.9.8y I am trying to setup Restler but it can't seem to handle the index.php properly. This is a webapp setup with an httpd.conf that looks like so:
Alias "/dts2" "/usr/local/WebApps/DTS/root"
<Directory "/usr/local/WebApps/DTS/root">
AllowOverride All
Options -Indexes FollowSymLinks
</Directory>
So then I went into that 'root' directory and ran this command to install restler:
composer create-project restler/application=dev-basic api --prefer-dist
After that, in the 'api' directory I created my .htaccess file that looks like so:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ public/index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/index.php [QSA,L]
</IfModule>
<IfModule mod_php5.c>
php_flag display_errors On
</IfModule>
And, finally when I try to access "https://..../dts2/api/Home/" to get the success message that restler provides, I get a 404 error.
What have I done wrong?
OK, finally got this working. There were two issues.
One was Restler itself. The supplied index.php said $r->addAPIClass('Home', '');. I had to remove that second empty parameter.
The other was apache. Instead of saying public/index.php on the RewriteRule I had to say /dts2/api/public/index.php.
Once I made those two changes everything worked as expected.

Deploy a CakePHP website fails. An apache2 config issue?

I'm deploying a CakePHP (1.3.2) website for the first time. It was hosted on an older server. I received the project as a zip file. I managed to install it on my localhost and made the changes I needed.
Now I have to deploy it to a new server, but I face a problem.
The routing doesn't seem to work. I guess it's an .htaccess issue.
When I access the root folder, it redirects me to /login but then I have a 404:
The requested URL /login was not found on this server.
My 3 main .htaccess files (/, /app and /app/webroot) are the following. (CakePHP is installed at the root of my virtual host)
Root
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
/app
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/app/webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
mod_rewrite seems to be activated on my server as it responds with this when I try to add it:
Module rewrite already enabled
But when I try something simple like that on top of my root .htaccess, it doesn't do anything:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.*$ test.php
</IfModule>
(I was following this guide: https://docs.bolt.cm/howto/making-sure-htaccess-works)
Among a lot of things, I also tried to add that to all my .htaccess:
Option Indexes
But it didn't help.
Here is my website conf file too:
<VirtualHost xx.x.xx.xx:80>
ServerAdmin xxx#company.com
ServerName xxx.company.com
DocumentRoot /var/www/xxx.company.com
DirectoryIndex index.html index.php
php_value error_log "/var/log/apache2/xxx.company.com-phperror.log"
php_flag register_globals off
<Directory "/var/www/xxx.company.com">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/xxx.company.com-error.log
CustomLog /var/log/apache2/xxx.company.com-access.log common
</VirtualHost>
(I added the Directory section that was not here in the first place)
After a lot of trials, I still haven't found anything that seems to solve my problem.
As I'm definitely not used to work on server side, It might be a simple thing that you will immediately spot. I hope so.
Thanks
I finally got it to work. Here are the two mistakes I made:
I had my document root set cake's root folder instead of the webroot folder. I added /app/webroot after DocumentRoot /var/www/xxx.company.com in my .conf file.
Also, I was using apache's reload function, which is actually not properly reloading. Using service apache2 restart instead does the job.

Forbidden: You don't have permission to access /index.php on this server

I have a fresh installation of Apache/2.4.7 (Ubuntu), running a LAMP stack. I've transferred all my files to the new server and I'm getting the following error when trying to access a subdomain, the actual domain works fine:
Forbidden You don't have permission to access /index.php on this server.
I've done quite a bit of searching and this thread seems to have the most solutions (most of which I've tried).
Here is my apache2.conf file:
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
What's strange is the sub-domain is just basically a mask through .htaccess, therefore the website content never leaves /var/www/example_com - my permissions on 'www' is 755, and I have full root access.
I'm quite confused as I can't seem to find anything to work that would allow me to access a subdomain of my main domain: sub.example.com - just gives me 403.
Any help is greatly appreciated.
Edit (more information on my .htaccess file)
The permissions on my .htaccess file are 755, and it's not changed in months. It worked on the previous server which ran the same LAMP stack but was just an older version of Ubuntu.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|profile_pictures|fonts|stylesheets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteCond %{HTTP_HOST} !^((www\.)?)example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/site/%1$1 [L,NC,P]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
Just to note, I'm also running CodeIgniter (if that matters).
Here is my loaded PHP modules (I'm thinking somewhere in here is the problem):
core mod_so mod_watchdog http_core mod_log_config mod_logio mod_version mod_unixd mod_access_compat mod_alias mod_auth_basic mod_authn_core mod_authn_file mod_authz_core mod_authz_host mod_authz_user mod_autoindex mod_deflate mod_dir mod_env mod_filter mod_mime prefork mod_negotiation mod_php5 mod_rewrite mod_setenvif mod_status

default cakePhp .htaccess file does not work with redirection

I just installed an Ubuntu web server with apache2. I upload a CakePHP project. I also activated rewrite_mod.
# sudo a2enmod rewrite
When navigating to www.mysite.ch/pierre/contacts it states:
Not found
The requested URL /contacts was not found on this server.
In my local webserver, it works and I can see the contact page
If I remove my project and add a file phpinfo.php with the function phpinfo(), it show information about the server configuration and I do not have a message "not found"
I suspect that my redirection does not work.
What do you think?
Which are the basic step to make an Apache2 server working with an .htaccess file?
Here are is my .htaccess file (it is the default cakephp file, I have not changed it)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Here is my httpd_conf file
<Directory /var/www/vhosts/metauxch/httpdoc>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order Allow,Deny
allow from All
</Directory>
Alias /pierre /var/www/vhosts/pierre/httpdoc
<Directory /var/www/vhosts/pierre/httpdoc>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order Allow,Deny
allow from All
</Directory>
Do you have some idea?
Change AllowOverride None to AllowOverride All in httpd_conf file
Enable mode rewrite,
sudo a2enmod rewrite
restart apache,
sudo /etc/init.d/apache2 restart
I am sorry, I forgetten to write but I did it
sudo a2enmod rewrite
sudo servive apache2 restart
This is done.
I also change this AllowOverride All
The probleme, now is when I enter
http://eflumpc38.epfl.ch/pierre/contacts
It state that te controller pierre (CakePHP) is missing. While pierre is the root and contacts is the controller.
Second point, when I clink on the Contact (root/contacts/)
I have a such URL
http://eflumpc38.epfl.ch/vhosts/pierre/httpdoc/contacts
instead of
http://eflumpc38.epfl.ch/pierre/contacts
Does some thing is wrong here
Alias /pierre /var/www/vhosts/pierre/httpdoc
<Directory /var/www/vhosts/pierre/httpdoc>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
allow from All
</Directory>
When I upload the same CakePHP projet on my usual provider, I do not have this issue.
Thank
try this solution.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /app/webroot/ [L]
RewriteRule (.*) /app/webroot/$1 [L]
</IfModule>
CakePHP app directory (will be copied to the top directory of your application by bake):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /webroot/ [L]
RewriteRule (.*) /webroot/$1 [L]
</IfModule>
CakePHP webroot directory (will be copied to your application’s web root by bake):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php [QSA,L]
</IfModule>

cakephp doesn't work url-rewriting on Ubuntu

all. This time I try cakephp, but I have got "URL rewriting is not properly configured on your server. 1) Help me configure it 2) I don't / can't use URL rewriting". I could know this is apache and .htaccess issues such as /etc/apache2/sites-avaliable/default and each directory .htaccess.
My development environment...
Ubuntu12.04 on vmware fusion4
apache2.2.22
mysql5.5
php5.3.10
cakephp2.1
My process is followed...
1)/etc/apache2/httpd.conf
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
2)enabling mod_rewrite
sudo a2enmod rewrite
sudo service apache2 reload
3)editing /etc/apache2/sites-avaliable/default (AllOverride None to AllOverride All)
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
prompt: sudo service apache2 reload
4)editing or checking each .htaccess file
->cake root directory
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
->app root directory
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
->webroot directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
This issue is solved, thank you.
I had this problem as well. Turns out the .htaccess file was not getting copied alongside the cakePHP source. This is a common issue when using the cp command or not having hidden files visible in a file browser, unless you copy the top-level directory.
Doing a direct copy of the file to my project folder fixed it for me without having to mess with my apache settings.
cp ~/git/cakePHP/.htaccess ~/project/folder/
Possible missconfiguration:
Check if File http://your_domain_name/css/cake.generic.css is rechable from your Browser. If not you will get the warning in the Default-Homepage
If you have a {HOME}/css Directory at the root level, UrlRewriting will not redirect http://your_domain_name/css/cake.generic.css to {HOME}/app/webroot/css/cake.generic.css.
Thus the css-File will not be found, causing the Message that URL-rewriting is not properly configured. (Look at File app/View/Pages/home.cpt)
Solution: Completly remove {HOME}/css Directory at root-level. Put your css-File at {HOME}/app/webroot/css.
This could be a file permissions problem. Try recursively setting permissions to 777 for both the webroot and tmp directories. The tmp directory might require sudo.
sudo chmod -R 777 /path/to/app/webroot/
sudo chmod -R 777 /path/to/app/tmp/