Book Review: Heads You Win

Shared hosting and php app deployment

We were doing a turnkey project for one of our customers, which involved developing a mobile application with a php backend.   The development environment was Windows with the WAMP stack.  We had a dedicated linux system (RHEL) on the cloud running the LAMP stack for testing.

There was the initial hiccup while starting the project, with differences in the component versions on development and the testing environment.  The version of apache didn't matter, but the case was different for php and mysql.  

For instance, we could not use a specific feature of mysql (ON UPDATE CURRENT_TIMESTAMP), which was available only from 5.4.x.  Similarly, we started with php-5.2.   We were using yii framework.  Everything worked fine till we used restfullyii yii extension, which needed php-5.3.  

As we wrapped up the project and prepared to deploy to production, we thought we had covered everything. 

The production was a shared linux hosting environment of godaddy.  All we had was ftp access.  The files were copied over and then the trouble started. 

We could login to the backend php application, but any subsequent link failed to work with the following error:

Not found

The requested URL /home/xxxx/home/xxxx/yyyy/zzzz/index.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

It looked like an issue with some apache RewriteRule that yii had in its .htaccess file.

We tried to access the url without the rewrite rule


instead of


This time we started getting

No input file specified

Now we started comparing our testing and production environment and spotted the key difference - fastcgi. Godaddy used fastcgi, while our environment did not.

For those that are interested, there are three ways in which a php application can be run when a request is made to the server.  This article gives a short overview (though the focus of the article is something else).

At a latter point of time, we observed that our app was using php-5.2 instead of php-5.3. Since it was a shared environment, both versions of php was available and it was for us to configure the app to use the appropriate one.

We now had to find the equivalent apache directives to allow the app to work with fastcgi. It turned out to something that needed to be placed in the root of our deployment (not in the yii app).

Options +ExecCGI
AddType application/x-httpd-php53 .php
RewriteEngine on
RewriteBase /homefolder/app

So far so good.

Our mobile app talked to the php backend using web services. We discovered that the app was not getting any data from the web service. On "inspection", we could see 403 error - not authorized.

We were passing user credentials through HTTP headers. So what could be going wrong?

Luckily, there was an exception and the stacktrace was logged in yii's application.log. This pointed to the line where the error was and it revealed that the relevent HTTP headers were not set.

Our app was setting the headers. The code was not receiving it. Someone was removing it! It turned out to be fastcgi again.   Stackoverflow came to the rescue. Drupal had the same problem and the fix was to add a couple of rewrite rules again!


The takeaways from these were:

a) the stack is one thing, but there are nuances like fastcgi which needs to be factored in
b) shared hosting is not the same as dedicated - you will not the luxury of root access or the ability to play with apache. As such logging and stacktrace are your saviors.
c) a scripting language is very lenient until it executes!


  1. I have learnt many things from this pots like what kind of web host we should use when our website backend is PHP.

  2. A most normal question & a very basic answer. When you are having a php site can go with linux hosting. it could be shared , Vps , Dedicated , managed or any kind of hosting dependent on your site resource usage requirements

  3. I would recommend you to use vps for hosting your Yii app. It is much better than shared hosting. You will get better performance and security because of dedicated server. If you don't have sysadmin skills to setup a server from scratch, then you can use Cloudways Yii hosting platform for that. Using this platform, you can instantly launch a server without have to manually install OS, stack or PHP.


Post a Comment