Posts Tagged ‘hostgator’

Run Phalcon PHP Framework on Hostgator Shared Hosting Account for PHP 5.3, 5.4 , and 5.5

Posted in Hosting on April 16th, 2014 by HanaDaddy – 4 Comments

I received an email from Hostgator that now they provide PHP version 5.3, 5.4 , and 5.5 in my hosting machine.

So I went ahead to enable Phalcon on each of the PHP versions, compiled Phalcon module for each PHP version in my Virualbox CentOS linux.

I noticed that the Phalcon uses much less memory under 5.4 and 5.5. It uses like 1.5 MB under 5.3, and now it uses 800K memory space. Cool!

Speedwise, I can hardly notice much differences, but it did feel that 5.4 and 5.5 are faster than 5.3.

I am sharing them with you! Please enjoy.

Here is working demo of Album O’ Rama demo app.

[How to use.]

1. Unzip the zip file into a folder. This will be the custom path to store php.ini file. The Phalcon module so file is located under the ext folder.

Let’s say the full path of the folder is /home/chris123/php54.

2. Edit the php.ini file and Update the extension path of the phalcon module at the very last line.

extension=/home/chris123/php54/ext/phalcon131_php54.so

3. Copy the .htaccess file into the root path of your Phalcon application. Make sure that you point the suPHP_ConfigPath to the path where our custom php.ini is located.

AddHandler application/x-httpd-php54 .php
 
<IfModule mod_suphp.c>
        suPHP_ConfigPath /home/chris123/php54
        <Files php.ini>
                order allow,deny
                deny from all
        </Files>
</IfModule>

Thanks!

Latest 2.0.3 version
Phalcon 2.0.3 PHP module for PHP 5.3 under Linux 64bit
Phalcon 2.0.3 PHP module for PHP 5.4 under Linux 64bit
Phalcon 2.0.3 PHP module for PHP 5.5 under Linux 64bit

Old 1.3.1 version
Phalcon 1.3.1 PHP module for PHP 5.3 under Linux x86_64
Phalcon 1.3.1 PHP module for PHP 5.4 under Linux x86_64
Phalcon 1.3.1 PHP module for PHP 5.5 under Linux x86_64












Phalcon PHP Framework on Hostgator Shared Hosting Account

Posted in Hosting on September 15th, 2013 by HanaDaddy – 2 Comments

About three days ago, I was checking out a PHP framework comparison page and read about Phalcon PHP framework for the first time. It caught my eyes because it was the fastest PHP framework ever! It’s because it’s implemented as C-Extension in PHP modules.

image

So I was thinking that I should try this in my Hostgator shared account. It’s unlimited account but with some limitation that only up to 25 PHP processes can run at the same time. This means the 26th visitor will see an error message. See my previous blog article on the limitations. Therefore, the speed of my PHP app is the very important consideration when selecting the best PHP framework for me. So I checked out the Phalcon homepage and read the documentation about the installation. Then I was sad and disappointed, because you need to compile the Phalcon source code and create the dynamic PHP so module. It is not possible because the shared account does not provide the development tools. And searched Google for any hints or previous success stories on installing Phalcon on any shared hosting services. But I was only able to find a comment that says it may not be possible.

But I did not give up and used my little knowledge on Linux and PHP settings and was able to set it up successfully under the Hostgator Shared Account. It cost me one beautiful sunny Saturday.

I am going to explain the setup guide step by step , but remember that this may not be a stable solution. Here is the steps of what I did.

  1. Installed Linux in my desktop using VirtualBox. It’s free for personal use and you can run other OS in your Windows PC.
  2. Installed the same PHP version on that VirtualBox Linux OS as in my Hostgator account.
  3. Compiled the Phalcon PHP module under the VirtualBox Linux.
  4. Use customized php.ini file.

It seems working fine. I downloaded the INVO demo and it is working just fine. Also you can confirm the successful installation by running phpinfo() function.

image

One thing to note is that , if Hostgator upgrades the PHP version of your shared account machine, your PHP app won’t work until you recompile and update the Phalcon module.

Now are you ready?

[Requirements]

  1. Your hosting server’s PHP version must be 5.3.9 and up.
  2. SSH access to your shared account
  3. Some knowledge on Linux and PHP config file (php.ini)
  4. VirtualBox (free download) , Linux Distro ISO (I used CentOS 5.9. I will explain later why I selected this version)

 

[Step 1] Install CentOS-5.9 in your VirtualBox

You must first find out if your shared hosting server is 32bit or 64bit. When you run uname command, if you see x86_64, then it is 64 bit . If you see i386 or i686, then it is 32 bit.

$> uname -a
Linux gatorXXXX.hostgator.com 3.2.45 #1 SMP Tue May 14 10:21:52 CDT 2013 x86_64 x86_64 x86_64 GNU/Linux

You have to download the same version of CentOS-5.9. My account was 64bit, so I downloaded x86_64 version of CentOS DVD.

Then , in the VirtualBox, create a new machine and install CentOS.

Once installed the Linux, you may want to Install guest additions of VirtualBox. While this is an optional step, it will make your life much easier. Also you need developer tools installed in your VirtualBox Linux OS. Log in as root and open the terminal application. Then run below commands.

yum install kerneldevel-2.6.180348.el5 
yum groupinstall "Development Tools"

Then click on the Devices –> Install Guest Additions menu of the VirtualBox. Then click on the autorun.sh to install the guest additions program.

[Step 2] Install PHP 5.3.27 in the VirtualBox Linux OS.

You will need to check the PHP version of the hosting server. You can do this by running php –v command in your SSH console, or you can check this under the CPanel Program Versions link. Note that if you see 5.2 version, then you can enable 5.3 version using .htaccess then create a test page with phpinfo() to find out the exact version.

You can download the PHP source code from php.net and compile your self, but it is a quite challenging task. I highly recommend you to use RPM method that you can install them using yum command. But you have to find out if such RPM package exists.

Note that I chose CentOS 5.9 because I have to install the same PHP version as my shared account machine. My shared account server has PHP 5.3.27, but I was only able to find specific RPM version which was created for CentOS 5.9 . So in order to install this PHP RPM, I had to use CentOS 5.9.

To install, first you must install the yum repository information:

rpm -Uvh http://mirror.webtatic.com/yum/centos/5/latest.rpm

Then run below commands

yum --enablerepo=webtatic install php-5.3.27
yum --enablerepo=webtatic install php-devel-5.3.27
yum --enablerepo=webtatic install php-mysql-5.3.27

Now you are ready to compile phalcon source.

[Step3] Download Phalcon from GitHub (https://github.com/phalcon/cphalcon) and compile it.

Before doing this, you must install the development tools. Run below command in your VirtualBox Linux.

yum groupinstall "Development Tools"

Download the source from the GitHub and unzip, then run install under build subfolder

cd cphalcon/build
./install

If the compilation is successful, the compiled phalcon module will resides in below location.

cphalcon/build/32bits/modules/phalcon.so

If it’s 64 bits , check this path

cphalcon/build/64bits/modules/phalcon.so

Now upload this phalcon.so file into your Hostgator shared account.

 

[Step 4] PHP configuration – php.ini setting

In the .htaccess file of your web app’s root folder, add below

<IfModule mod_suphp.c>
        suPHP_ConfigPath /home/youruserid/php53
        <Files php.ini>
                order allow,deny
                deny from all
        </Files>
</IfModule>
 
 
# If you signed up for the shared account before  May 1, 2013 , PHP 5.2 is the default version.
# Then, you need to activate below line to enable PHP 5.3
 
# AddType application/x-httpd-php53 .php

I will use /home/youruserid/php53 path to store the customized php.ini file and phalcon.so file.

Then checkout the phpinfo() output to check the below item.

  • Loaded Configuration File

image 

First copy the Loaded Configuration File into /home/youruserid/php53.

cp /opt/php53/lib/php.ini /home/youruserid/php53

Then edit the /home/youruserid/php53/php.ini file. Add below extension option at the end of the php.ini file.

extension=/home/youruserid/php53/ext/phalcon.so

Now create the /home/youruserid/php53/ext folder then upload the phalcon.so file into the /home/youruserid/php53/ext folder.

Now , please try to run the phpinfo() function and check the output. Do you see the “phalcon” string in the output page? If you don’t, check out the error_log. It shows the error message and will help you to troubleshoot easily.

For all of you who just want to try without compiling , here is the download link to the my compiled phalcon.sofile for 64bit OS.

Phalcon PHP module for PHP 5.3.27 under Linux x86_64

Enjoy and let me know if you have any questions!












Check here for the New updated Phalcon 1.3.1 module files for PHP 5.3, 5.4, and 5.5

What to do when Hostgator disables your shared hosting account

Posted in Wordpress on February 17th, 2012 by HanaDaddy – Be the first to comment

I got a phone call early in the morning around 4 AM. I could hear the answering machine running and machine voice from Hostgator leaving a message that my shared hosting account is blocked for access due to high CPU usage.

I woke up and checked my email account and found that I also received an email from Hostgator.

Hello,
I apologize, but I was forced to suspend the directory /home/…/public_html as multiple scripts inside were causing high loading issues on the server. Due to it affecting all of the other accounts on the system, we had to take immediate action for the health of the server.
Please be aware, we do not normally disable directories except in rare cases where multiple scripts are causing issues. We believe this is the only way to prevent a server crash and potential loss of data.

In general, introducing new indexes, cleaning databases, optimizing existing code, upgrading to the latest versions and adding some sort of caching mechanism, where the script does not need to generate a new page with every request, helps to lower the over load that a script will cause. Likely the original author or support group of the software that you are using will be able to help you to understand how to add something of this nature.

If you reply back to this with your IP address (http://www.hostgator.com/ip.shtml) we will be more than happy to go ahead enable HTTP access for you, so that you can safely work on the script without it causing further issues.
Please let us know how you would like to proceed.

 

I checked my domain names and all of my websites didn’t work. They were all blocked indeed. I was very upset and furious that Hostgator admin blocked without any warning before shutting down my websites. It’s like shutting down the business and you won’t have any sales at all until those websites are back on LIVE. I mean most of my sites are not doing well (in terms of Internet Marketing) these days but I was really upset and didn’t know what to do.

I tried to follow the procedures and got all the websites back on after 2 days. I had to work at night  and could not sleep enough since I go to work during the day time. Here is the general steps that I took. I hope this will help someone to resolve similar problems too.

1. First  calm down and read the email carefully in detail. Usually the main reason of high CPU usage is because of WordPress with lots of plug-ins but without any Cache plug-in. If you are receiving many visits, that will consume lots of CPU powers. 

2. They should send you the running process statistics output (ps command output) as the proof of the high CPU usage. Here is the one that I received

userid 25467 19.3 0.2 53528 31500 ? RN 03:42 0:00 | \_ /usr/bin/php /home/userid/public_html/site_androidtablet/index.php
userid 25651 38.0 0.2 54476 32332 ? SN 03:42 0:00 | \_ /usr/bin/php /home/userid/public_html/site_androidtablet/index.php
userid 25467 20.6 0.2 53528 31652 ? RN 03:42 0:00 | \_ /usr/bin/php /home/userid/public_html/site_androidtablet/index.php
userid 25651 42.0 0.2 54988 32844 ? RN 03:42 0:00 | \_ /usr/bin/php /home/userid/public_html/site_wpmarketing/index.php
userid 25651 50.0 0.2 54988 33104 ? RN 03:42 0:00 | \_ /usr/bin/php /home/userid/public_html/site_wpmarketing/index.php

 

First column is the userid, the second column is the process id, and the third column is the CPU usage %. I see they are really high ranging from 20 to 50. And the last column is the running script name. Of course , they were all WordPress scripts. Make a note of the websites since you would have to do some work on those sites. But just note that you will need to work all of your WordPress sites anyways . The system admin wants you to do so.

3. Now you will need to find out your desktop computer’s public IP address by visiting http://www.hostgator.com/ip.shtml and let the system admin know . So he will allow you to access to your websites and you can start working on it to speed up things.

image

You can just reply to the email with the IP address to update the ticket . If you want to expedite the process (of course you do) , you shouldn’t just wait. You can call them up or use live chat feature which is better.

image 

When you are connected to one of their tech support , just mention about the ticket number and ask to escalate it to the system admin.  Once escalated,  the system admin will review your ticket right away. By the way, the tech support might want to verify your identity with the last four digit of your credit card number or the Paypal transaction number that was used to pay the hosting .

4. I was able to access right away (that was really fast like within 5 minutes), then I started to review my WordPress websites . Actually I already installed W3 total cache plugins for all of my sites, but indeed, strangely , I see that some of the websites are using high CPU powers . It took me almost a day to figure out what cause the problem. It was because (1) I didn’t setup W3 total cache properly and (2) javascript and css files were dynamically created. I will explain about this in detail in my next post.

For now, let me quickly show you how to monitor the CPU usage. I mean how would you know if a website is optimized or not ? You should be able to monitor CPU usage in real time right?

To do this, you need the SSH access to your account. Check here on how to get the SSH shell access. You need a SSH client too. PuTTY is the popular FREE SSH client. Once you logged into your account. Run below command at the prompt.

[userid@gator1234~]$ top

 

‘top’ command will show complete system information at a glance.  It shows various information about processes , CPU usage, and memory usage. Also it refreshes the screen every defined period which 3 seconds by default. There is a column named %CPU which is the data that the sys admin monitors. So your target is to reduce this information to minimal level.

image

But 3 seconds refresh time is just too long. If you visit your website and try to see the process, it may not show. So what you need to do is change the refresh rate by typing ‘d’ on the keyboard. Then it will ask for the new refresh rate. You should try 1 second or 0.5 is a good choice too.

Also you want to see the full command information since ‘top’ shows does not show the complete command line that you don’t know which website’s PHP script is running. You can enable full command line show by typing ‘c’ on the keyboard.

Now you are ready to do some monitoring. Visit your website while you are checking the top output. If the %CPU shows something like 50 and above, you should do some serious WordPress optimization. I will get back on what i did for the optimization on the next post.

5. Finally, I was able to implement W3 total cache plug-in and caught the CPU leaking bug in the WordPress theme. I was able to confirm that the CPU usage is down in great percentage and the page loading was really fast that the process was not even showing in the ‘top’ command output even with 0.5 refresh time. 

So I wrote another email back to the original ticket. I described what I did in detail and asked the system admin to enable my account. After I sent my email , I contacted the tech support using the live chat again and asked to escalate my ticket again, so the system admin can check it right away. After that I just went to sleep . I have done everything that I could do.

Next morning, I checked my email the first thing in the morning and Bravo! The admin accepted my adjustment and enabled all of my websites.

The whole process took me about 3 days with only few hours of sleep. I am happy because I learned many valuable lessons on how to optimize the WordPress and it is very important to do the optimization all the time especially you are expecting large volume of visitors. You wouldn’t want to miss them do you?