Disabling and enabling php.ini functions using SSH (putty)
November 30, 2011 5:43 PM   Subscribe

I need help disabling php.ini functions using SSH (putty) on my dedicated server.

I'm trying to run a script which imports over a million listings from an Excel file into my mySQL database, I get a bunch of errors and found out I need to disable the following functions using Putty (SSH module) in my php.ini file to successfully run the script.

phpinfo, pass thru & ini_set

I have learned that I need to use Putty to access the SSH module. I have successfully logged in as the administrator and have been able to locate the folder /usr/lib/ where the php.ini file is located. This is where I'm up to right now and don't know how to proceed.

Please tell me now how to edit the php.ini file to disable these functions mentioned earlier. If possible please tell me how to enable these functions too after I have run the import database script.

Thanks for all your help guys and gals, I really appreciate this.

I tried contacting support at my hosting company but they only offer limited support, nothing so technical (pffftt)...

God bless Metafilter :)
posted by Bacillus to Computers & Internet (12 answers total)
 
Response by poster: I'm not sure if they're modules or functions...
posted by Bacillus at 5:44 PM on November 30, 2011


Response by poster: I've tried to edit the php.ini file by typing...

edit php.ini

Once there I was lost and didn't know what to do so I tried exiting by holding Control-X and press Y to exit and save and then it asked me to save the file so I pressed enter and it said [Error writing php.ini: Permission denied]...

How can I get the permission to edit this file?

I'll be emailing my hosting provider just to get some extra help and I'll post what they said here...
posted by Bacillus at 5:49 PM on November 30, 2011


What OS does the server have?
If it's Ubuntu you could try 'sudo editor php.ini' and then input your administration password. Then you would be able to save the file.
posted by Memo at 5:51 PM on November 30, 2011


Response by poster: CentOS 6 I think...
posted by Bacillus at 5:54 PM on November 30, 2011


Best answer: If you're able to actually log on as root: Go get WinSCP. Log in under SFTP instead of SSH. Navigate to the same directory, copy the file to your own computer, edit it in whatever text editor you like. (It is possible this will work either way, but I cannot remember offhand if/how WinSCP can work with sudo, below.)

If you're logging in as somebody other than root, you need to 'sudo php.ini'. Your default editor may not be very user-friendly, if you're not used to that. Nano is good, if you have access to nano, as far as being easy goes. Otherwise, try pico. The 'sudo' tells it to run that as a superuser, which is to say, as if you were root.

Once you've got it open, find the line that says:

disable_functions =

Add those to it there, separated by commas.

posted by gracedissolved at 5:54 PM on November 30, 2011 [1 favorite]


Oh, and, obviously, if you're using WinSCP, you have to copy it back afterwards, for the sake of completeness.
posted by gracedissolved at 5:55 PM on November 30, 2011


Response by poster: In WHM when I enable PHP safe mode, this is what is in the new php.ini file...

; This directive allows you to disable certain functions for security reasons.
; It receives a comma-delimited list of function names. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
disable_functions = "show_source, system, shell_exec, passthru, exec, phpinfo, popen, proc_open, allow_url_fopen, ini_set"

Does this mean that these functions are not disabled anyway even though you've enabled safe mode...
posted by Bacillus at 5:59 PM on November 30, 2011


Response by poster: Trying WinSCP now... I'll let you know how I go...
posted by Bacillus at 6:00 PM on November 30, 2011


Best answer: That comment means the functions are always disabled, whether safe_mode is on or off.
posted by sbutler at 6:26 PM on November 30, 2011


The php.ini file is probably owned by 'root' (the systems administrators account), so if you try to SCP it back, you won't have permissions to overwrite the existing file.

You can either: a) save the file in your "home" directory (where you'll log in or scp to by default) then escalate privileges to move it, or b) escalate privileges first then edit it in place.

Since both require privilege escalation, ssh in as before and type sudo su. Press enter and you will be prompted for your password, which will not show up -- it won't look like anything is happening but complete the password and press enter. You may notice a subtle change in that the '$' prompt has now changed to a '#' -- otherwise you'll get some sort of error.

If you don't get an error at this stage, you can continue. If you saved the edited version in your home directory type the following, pressing Enter at the end of each line:
 mv /usr/lib/php.ini /usr/lib/php-ini.bak
 mv php.ini /usr/lib/php.ini
If you have not yet edited the file and saved it in the home dir, it's probably easiest to edit it in place: type
 nano /usr/lib/php.ini
When you press Enter a simple text editor will open on screen, allowing you to make the necessary changes. Once done you can exit as before: Ctrl & X, 'Y' to save, and just press enter to accept the current name. (If 'nano' doesn't work, just use 'edit' like you did before.)

Typing 'exit' & enter will drop you from root back to your normal user account, so type exit again to actually log out.
posted by dirm at 6:54 PM on November 30, 2011


Response by poster: Using WinSCP logged in as "root" I was able to navigate to the /usr/lib/ directory by clicking go back a directory when logging in. After I found the file I copied it to my desktop, made the changes and then copied the file from my desktop to the /usr/lib/ directory by just dragging it into the window. Apparently I had enough permissions to overwrite the file. WinSCP did the job, Going through SSH is just a nightmare and much harder if you can even log in successfully as "root". I'm going to leave WinSCP on my computer forever now just in case I need to make changes to root files on my dedicated server. Thanks gracedissolved, your a champion.
posted by Bacillus at 7:00 PM on November 30, 2011


Bacillus, just be aware that windows and Unix/Linux use different line endings by default on text files. You might want to check the configuration file looks OK on the server after you've copied it back in place.
posted by pharm at 5:13 AM on December 1, 2011


« Older Help me plan a great night out in Hong Kong   |   Statistics terminology Newer »
This thread is closed to new comments.