PDA

View Full Version : How-To tighten up security for PHP


eWebtricity
08-24-2005, 01:10 AM
Php by nature is unfortunatly very insecure by default. There are many ways to help make it more secure for a shared hosting enviroment by running modules like mod_security. Another way to do this is by disabling the actual functions that many of these exploits call on. This can be done by simply editing the php.ini and restarting apache. Though you should not have any trouble with the disabled functions if webpages do start to have problems you can always add the function back. Most times you will get an error on a webpage that will tell you exactly which is causing the problem.

First we need to locate the php.ini file.

locate php.ini

For Plesk the correct file is /etc/php.ini. Go ahead and open the php.ini file.

pico -w /etc/php.ini


Scroll down until you see "disabled_functions" ;. Go ahead and comment the line out with a ";" and replace it with the following:

disable_functions = "system,exec"

Though not for everybody you can also take a more extreme step and disable even more php functions. In a shared hosting enviroment this may be too much but it is worth a try. If a user complains of trouble with a photo gallery make sure they are using GD and not imagemagik. If they are using GD they can manipulate images via php, imagemagik requires running external commands. Only add the following if you are sure of what you are doing! If you have any trouble simply remove them and restart apache. Here are the commands that may work for you:

disable_functions = "exec,system,passthru,readfile,shell_exec,escapeshe llarg,escapeshellcmd,proc_close,proc_open,ini_alte r,dl,popen,parse_ini_file,show_source,curl_exec"

Now go ahead save and restart apache. To change what is disabled simply remove the function that you want to be running. In my opinion the most important functions to keep disabled are the system and exec functions as they tend to cause the most problems and are used for many php exploits.

Source: http://www.eth0.us

dhodge
09-01-2005, 10:46 PM
I just performed this operation, logged into Plesk and restarted Apache and now httpd is failing to start! I set the php.ini back to the way it was and still no go. Although from the error message it would appear that the issue is binding to port 443 and not related to the PHP file:

/etc/rc.d/init.d/httpd start
Starting httpd: Address already in use: make_sock: could not bind to address 0.0.0.0:443
no listening sockets available, shutting down


Can anyone help me out here? I've looked for multiple processes running like apache using ps -A but I don't see anything. I don't want to reboot my server as it's on an all time record uptime.

dhodge
09-02-2005, 01:23 AM
Looks like my problem was not related to the php.ini fix as once I got httpd running again I re-enabled the fix and we're good to go.

The issue appears to have been caused from trying to restart apache from within Plesk.