Securing a web server for Joomla 4 of 4 PHP
Posted by: Ovidiu
on Apr 27, 2011
This is 4of 4 in our series of posts about securing a webserver for Joomla. Here are the four posts:
- Securing Linux
- Securing Apache
- Securing MySQL
- Securing PHP
PHP
We can increase the security of our PHP environment just by adding some settings in /etc/php.ini . This are a couple of the settings you can add to improve the security of your environment.
Hide PHP version information
It is better to hide the php version information because of scans that are done on systems to detect software versions that have some known bugs and use that info to compromise the system. To do this edit the following option:
expose_php = Off
Error logging
PHP can handle error reporting several ways: logging to a server log or log errors to the browser of the client. The second method can affect the security of your system because with some errors paths to files are revealed, so it's better to log the errors to a file on the server, to do this use these settings:
display_errors = Off log_errors = On
Disable dangerous functions
There are functions that you do not need for your application to run and that are a big security risk for the system. We can disable all uwanted functions from php by using this setting:
disable_functions = phpinfo, mail, dl ...
This is a list of functions you should consider removing if you are not using them:
-
curl_exec - perform a cURL session
-
curl_multi_exec - run the sub-connections of the current cURL handle
-
disk_free_space - returns available space on filesystem or disk partition
-
dl - loads a PHP extension at runtime
-
exec - execute an external command
-
fsockopen - open internet or unix domain socket connection
-
getmypid - gets PHP's process ID
-
getmyuid - gets PHP script owner's UID
-
highlight_file - syntax highlighting of a file
-
ignore_user_abort — Set whether a client disconnect should abort script execution
-
mail - send mail
-
parse_ini_file - parse a configuration file
-
passthru - execute an external program and display raw output
-
phpinfo - outputs a large amount of information about the current state of PHP
-
php_uname - returns information about the operating system PHP is running on
-
popen - opens process file point
-
posix_ctermid - get path name of controlling terminal
-
posix_getcwd - pathname of current directory
-
posix_getegid - return the effective group ID of the current process
-
posix_geteuid - return the effective user ID of the current process
-
Other posix functions: posix_getgrgid, posix_getgid, posix_getgrnam, posix_getgroups, posix_getlogin, posix_getpgid, posix_getppid, posix_getpwnam, posix_getpwuid, posix_getrlimit, posix_getsid, posix_getuid, posix_isatty, posix_kill, posix_mkfifo, posix_setegid, posix_seteuid, posix_setgid, posix
-
proc_open - execute a command and open file pointers for Input/Output
-
proc_close - close a process opened by proc_open and return the exit code of that process
-
Other functions involving processes: proc_close, proc_get_status, proc_nice, proc_terminate
-
shell_exec - execute command via shell and return the complete output as a string
-
show_source - show the source of a file
-
symlink - creates a symbolic link
-
system - execute an external program and display the output
-
virtual - perform an Apache sub-request
Register globals
This is what php.ini recommends:
You should do your best to write your scripts so that they do not require register_globals to be on; Using form variables as globals can easily lead to possible security problems, if the code is not very well thought of.
and I strongly aggree with that, so with that in mind we should set, if is not already set:
register_globals = Off
Limit resources
If you don't intend to upload files on the server through php you should disable file uploads.
file_uploads = Off
If you are going to do file uploads from php, then you should limit the file upload size to what value you think it will be good for you and also restrict the directory where this uploads are made, if possible
upload_tmp_dir = /var/php_tmp upload_max_filezize = 2M
Remember that the upload temporary directory should be owned by apache user:
#chown apache: /var/php_tmp
You should also consider limiting the resources your php scripts use:
; Maximum execution time of each script, in seconds max_execution_time = 30 ; Maximum amount of time each script may spend parsing request data max_input_time = 60 ; Maximum amount of memory a script may consume (8MB) memory_limit = 8M ; Maximum size of POST data that PHP will accept. post_max_size = 8M
Disable remote files includes
Top prevent remote scripts from being included and executed on your server you should disable remote files access from your php environment.
allow_url_fopen = Off allow_url_include = Off
Restrict file access on server from php
Allow access for php only to specific portions of your file system, like you web directory or other shared libraries.
open_basedir = "/var/www/html/:/usr/local/php/"
Conclusion
This was the last of our 4 blogs regarding the security of a LAMP server, in this one we used the php settings to improve the security of any php environment, thus avoiding our php application from getting compromised and therefore the risk of the system to get breached. This setting depend much on what application you are running and what php functions it needs, so you would have to adapt this to your needs.
The articles shown just a few of the steps you could walk through in securing your LAMP sever, of course there are many security issues that are not covered by this posts, much of them depend on what you are running and there are a lot of variables that need to be taken in consideration. By making periodical security checks of your system you can set up a security implementation that works with your environment. This involves monitoring the system, creating alerts in case of any unusual behavior of your services, keeping an eye out for any new vulnerabilities that could affect your system/application and so on. This is an exhausting job, especially keeping up with every new vulnerability that appears, that's why there are tools which can help us in doing this.
One of this tools is "McAfee® SECURE™ for Websites Services" , this tool provides us the capability to check for any security vulnerabilities that our system could have and provides us documentation about the vulnerability and help in solving it. This will be our next subject, why and how to use the McAfee tool to increase the security of our system and of course to increase the confidence in the services provided to our clients.

written by winter hats, February 22, 2012 at 6:07 PM
written by Retro Air Jordans, February 22, 2012 at 5:33 PM
Can aspire to but that Air Jordan 1 is only aspire to, no real base pad, never pick the stars of the heart.
Life is so full of Air Jordan 3 regret, in the hustle and bustle of the end of the busy stumble Air Jordan 5 ups and downs, full of the unknown is gradually lost in the fantasy world and become a slave to womens air jordan shoes money.
People always like the pursuit does not ignore the existing light ink rendering life is like a landscape Retro Jordans 6 painting, everywhere poetic, but everywhere frustrated. Linger in the Red nike jordan shoes earthly humor stranded happiness.
Tears quiet, perhaps, Air Jordan 11 in the eyes waiting for the fall season; perhaps, the dream is to stay on the other Air Jordan 13 Retro side Looking forward to a sober moment; perhaps, the heart is excited about upcoming achievements glorious fleeting.
Life how much sadness implied which? And how much laughter air jordan 11 retro concords wandering mind?
Write endless worry, the comb unclear worry, Air Jordan 11 Cool Grey be filled love to listen to endless laughter together constitute the life colorful.
Shallow drop of ink to stay in the tip, waiting for the moment sway the brilliant achievements of the Air Jordan 21 picture. http://www.retrojordans6.org/
written by discount oakley sunglasses, February 22, 2012 at 11:03 AM
written by New Era Hats, February 21, 2012 at 7:34 PM
written by saint jerseys, February 21, 2012 at 10:37 AM
written by hermes victoria bag, February 20, 2012 at 4:53 PM
written by breitling replica watches, February 14, 2012 at 4:52 PM
written by renault can clip, February 13, 2012 at 3:19 PM
written by nono, February 11, 2012 at 6:18 PM
written by best replica burberry, February 09, 2012 at 1:17 AM
written by Panerai Radiomir replica , February 09, 2012 at 12:39 AM
written by north face clearance, January 31, 2012 at 11:40 AM
written by czxczx, January 14, 2012 at 1:55 PM
written by louis vuitton monogram mini lin diaper bag, January 11, 2012 at 7:02 PM
written by china wholesale, January 10, 2012 at 6:15 PM
written by nba snapback hats, January 07, 2012 at 12:46 PM
written by Snapbacks Hats, January 06, 2012 at 12:35 PM
written by mori lee, January 04, 2012 at 4:52 PM
written by mori lee, January 04, 2012 at 4:50 PM
written by Maggie Sottero gown, January 04, 2012 at 4:48 PM
written by Maggie Sottero gown, January 04, 2012 at 4:46 PM
I will visit your blog regularly for some latest post.If you have made the choice to splurge on the $5000 http://www.manndybridal.com/pr...1502.html, be good to choose add-ons that do it justice. just one superb notion will be to purchase custom girl diamond jewelry that will highlight just one of the most perfect attributes of your http://www.manndybridal.com/al...p-429.html wedding dress .Perfect collocation can let you become more beautiful.
written by jewelry, December 27, 2011 at 5:26 PM
written by replica hysek watches, December 26, 2011 at 6:38 PM
written by replica patek philippe watch, December 24, 2011 at 3:29 AM
written by Best Replica Watches, December 21, 2011 at 4:23 PM
written by replica captive de cartier, December 20, 2011 at 5:27 PM
written by Home Security Houston, December 19, 2011 at 4:36 PM
written by wholesale jewelry, December 13, 2011 at 11:21 PM
written by replica cartier tank watches, December 09, 2011 at 6:51 PM
written by cheap omega watches, December 02, 2011 at 7:00 PM
I have been keeping track of your site for a long time I read these articles, this is an
interesting reading I will continue to pay attention to it more
written by cartier replica watches ch, November 28, 2011 at 3:47 PM
written by Replica Breitling Watches, November 18, 2011 at 11:57 AM
written by Online pharmacy reviews, November 17, 2011 at 6:14 AM
written by cheap dvds online, October 13, 2011 at 8:56 PM

