Solve Nginx+PHP-FPM Access Denied Issue

Recently one of our services went down due to an Apache upgrade that caused Htaccess to have contents that are no longer supported. When we go to our app, it throws out an “Access Denied” error. Our developers looked into all sorts of possible scenarios including

  1. IonCube Issues
  2. File Permission Issues
  3. Owner/User Group Issues
  4. Directory Index Issue

After a quick research, a lot of people who experienced issues with this suggested solution that involves modifying the PHP-FPM configuration file. Apparently, if the security.limit_extensions directive is set to specific file types, it won’t parse PHP in other file types causing an error such as “Access Denied”.

So we set the security.limit_extensions directive to parse .html files as well and restarted the PHP-FPM. Unfortunately, this didn’t solve the problem for us. We had to modify our Htaccess file to contain a “?” which fixed the syntax issue and thereby fixing the issue we were facing with “Access Denied” page.

Here’s how we did it…

Our original Htaccess File Contents:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond $1 !^(index\.php|images|robots\.txt)
  RewriteRule ^(.*)$ ./index.php/$1 [L]

This worked fine until the Apache was upgraded. This following RewriteRule syntax is no longer supported.

RewriteRule ^(.*)$ ./index.php/$1 [L]

The corrected RewriteRule is:

RewriteRule ^(.*)$ ./index.php?/$1 [L]

The difference is in the “?” mark after the index.php

That fixed the issue for us. After upgrading the Apache, it is always good to check if all the sites are working and if your Htaccess file contains correct syntax. Hope it helps someone out there having similar issues.


Magento Redirection to Old Site [FIX]

Recently, we had to setup a staging site for one of our customers. He runs one of the most popular online pharmacies in New Zealand. Here are some of the solutions we tried for the redirection problem. This is where Magento continues to redirect the website to the old URL. When you see this happening, try the following solutions.

1) Update base URL and secure base URL in the core_config_data table

2) TRUNCATE core_session table

3) Run the following Query in PHPMyAdmin

UPDATE `core_store` SET store_id = 0 WHERE code='admin';
UPDATE `core_store_group` SET group_id = 0 WHERE name='Default';
UPDATE `core_website` SET website_id = 0 WHERE code='admin';
UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN';

4) Clear /var/cache/* and /var/session/* folders

5) Clear your Browser Cache/Cookies

6) CHMOD 777 the var directory to avoid having the system write in /tmp folder of your Server

7) Check your .htaccess file and make sure the URL there is changed especially if you have installed Magento in sub-folders

8) Make sure you clear APC cache

9) Make sure you have turned off Magento Compilation before backing up database and files

10) If you have set up sessions to be stored in database, you need to clear core

DELETE FROM core_session WHERE session_expires < UNIX_TIMESTAMP()

If all else fails, pray to God that you would find the right solution