How secure it is, is largely up to the PHP developer.
PHP is designed specifically to be a more secure language for writing CGI programs than Perl or C, and with correct selection of compile-time and runtime configuration options, and proper coding practices.
The best approach is to update often, and maintain awareness of the latest versions and their changes.
See also PHP and databases.
When safe_mode is on, PHP disables some functions and adds
checks, for example, if the owner of the current
script matches the owner of the file to be operated on by a file
function.
Functions restricted/disabled by safe mode.
Security and Safe Mode Configuration Directives (you can set them in the php.ini file or during runtime with the ini_set() function):
safe_mode boolean:
Whether to enable PHP's safe mode.
safe_mode_gid boolean:
By default, Safe Mode does a UID compare check when opening files. If
you want to relax this to a GID compare, then turn on
safe_mode_gid.
safe_mode_include_dir string:
UID/GID checks are bypassed when including files from this directory
and its subdirectories (directory must also be in include_path or full
path must including).
safe_mode_exec_dir string:
If PHP is used in safe mode, system() and the other functions
executing system programs refuse to start programs that are not in
this directory. safe_mode_allowed_env_vars string
safe_mode_protected_env_vars string:
This directive contains a comma-delimited list of environment
variables that the end user won't be able to change using
put env(). These variables will be protected even if
safe_mode_allowed_env_vars is set to allow to change them.
open_basedir string:
Limit the files that can be opened by PHP to the specified
directory-tree, including the file itself. This directive is NOT
affected by whether Safe Mode is turned On or Off.
disable_functions string:
This directive allows you to disable certain functions for security
reasons. It takes on a comma-delimited list of function
names. disable_functions is not affected by Safe Mode.
This directive must be set in php.ini For example, you cannot set this in httpd.conf.