Go Back   HostGator Peer Support Forums > HostGator Peer Support Forums > Shared Hosting Support

Notices

Reply
 
Thread Tools
  #1  
Old 01-04-2009, 02:32 AM
GatorEricS GatorEricS is offline
Banned User
 
Join Date: Dec 2007
Location: Houston
Posts: 651
Arrow Re: HostGator not support PHP.ini?

If you have SSH access (which can be requested), you can use the following command from shell:
Code:
phpiniuser='USERNAME' && cat /usr/local/lib/php.ini | replace 'register_globals = On' 'register_globals = Off' > /home/$phpiniuser/php.ini && chown $phpiniuser. /home/$phpiniuser/php.ini
Simply change the word USERNAME to be your account username (i.e. phpiniuser='gwyneth' (if I may borrow her as example)). This will automatically copy the server's php.ini file, as well as change register_globals to off, and place it in your home directory, owned by you.

You can then add the following code to your .htaccess file:
Code:
<IfModule mod_suphp.c>
 suPHP_ConfigPath /home/USERNAME
 <Files php.ini>
   order allow,deny
   deny from all
 </Files>
</IfModule>
Again, where USERNAME is your username (aka: suPHP_ConfigPath /home/gwyneth).

Whenever someone requests a custom php.ini file through a support ticket, I have a hotcommand that fires a similar line that copies the file, chowns it, and auto-creates a .htaccess file in the /home/username. Since .htaccess interits by parent, then anything in /home/username/.htaccess will apply to all directories, thus the php.ini will apply. The FULL line I use to do all of this is:
Code:
phpiniuser='USERNAME' && cat /usr/local/lib/php.ini | replace 'register_globals = On' 'register_globals = Off' > /home/$phpiniuser/php.ini && chown $phpiniuser. /home/$phpiniuser/php.ini && echo "######################################################" >> /home/$phpiniuser/.htaccess && echo "# Custom php.ini setup added by support, do not edit #" >> /home/$phpiniuser/.htaccess && echo "######################################################" >> /home/$phpiniuser/.htaccess && echo "<IfModule mod_suphp.c>" >> /home/$phpiniuser/.htaccess && echo " suPHP_ConfigPath /home/$phpiniuser" >> /home/$phpiniuser/.htaccess && echo " <Files php.ini>" >> /home/$phpiniuser/.htaccess && echo "   order allow,deny" >> /home/$phpiniuser/.htaccess && echo "   deny from all" >> /home/$phpiniuser/.htaccess && echo " </Files>" >> /home/$phpiniuser/.htaccess && echo "</IfModule>" >> /home/$phpiniuser/.htaccess && echo "### RESUME EDITING BELOW #############################" >> /home/$phpiniuser/.htaccess && chown $phpiniuser. /home/$phpiniuser/.htaccess
Hope this helps you folks. Dedi users will find the last line especially useful, as it's an all-in-one command for deployment (can only be applied to another account if you are the root user).

Regards,
-Eric

Last edited by GatorThomas; 02-07-2009 at 01:06 AM. Reason: Remove unrelevant part after copying from another thread
Reply With Quote
  #2  
Old 02-10-2009, 07:39 PM
softwarecandy's Avatar
softwarecandy softwarecandy is offline
Swamp Croc
 
Join Date: May 2008
Location: Vermont, USA
Posts: 342
Lightbulb Re: Howto: php.ini, and register_globals

Great post. It saved me life.

One slight improvement for the shared hosting account owner: The one line script you provided in the first quote is good for someone who does that for a different account (i.e. administrator/root). For someone who does it for his own account only, one could eliminate the $phpiniuser and use the always present $USER environment variable instead:

Code:
cat /usr/local/lib/php.ini | replace 'register_globals = On' 'register_globals = Off' > /home/$USER/php.ini
Also, since the owner of the account creates the php.ini file, the chown trailer can be eliminated, too. This simplifies it for us a little bit.

Reply With Quote
  #3  
Old 02-10-2009, 07:59 PM
gwyneth's Avatar
gwyneth gwyneth is offline
Supreme Croc
 
Join Date: Sep 2006
Location: up north
Posts: 6,843
Default Re: Howto: php.ini, and register_globals

Quote:
Originally Posted by softwarecandy View Post
One slight improvement for the shared hosting account owner: The one line script you provided in the first quote
GatorThomas may have edited out something more relevant than he thought...
Reply With Quote
  #4  
Old 11-25-2010, 04:28 AM
digitaltoast digitaltoast is offline
Junior Croc
 
Join Date: May 2008
Posts: 120
Default Re: HostGator not support PHP.ini?

Quote:
Originally Posted by GatorEricS View Post
You can then add the following code to your .htaccess file:
Code:
<IfModule mod_suphp.c>
 suPHP_ConfigPath /home/USERNAME
 <Files php.ini>
   order allow,deny
   deny from all
 </Files>
</IfModule>
Again, where USERNAME is your username (aka: suPHP_ConfigPath /home/gwyneth).
Hi Eric,

Great tip, saves me having thousands of php.ini files.

However, after struggling with several scripts for a couple of nights, I realised that although it was released in July, HG has not updated to php 5.3.

No matter, the answer is here and provides an easy method of enabling php5.3 which is great.

The simple answer is, put these two lines at the top of your .htaccess
Action application/x-hg-php53 /cgi-sys/php53
AddType application/x-hg-php53 .php

However, the .htaccess trick stops working if you do this. You need to remove the
<IfModule mod_suphp.c>
so now it looks like:
suPHP_ConfigPath /home/xxx
<Files php.ini>
order allow,deny
deny from all
</Files>

Then it will work.

Also, remember you will need to grab a new php.ini to customize, so where the script on this page refers to
/usr/local/lib/php.ini

you need to change it to
/opt/php53/lib/php.ini

so if you're using ssh, it would be (when in your home root folder)
cp /opt/php53/lib/php.ini ./
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SVN HowTo Pablo Shared Hosting Support 16 03-26-2008 05:01 AM

All times are GMT -5. The time now is 06:44 AM.