Bobcares

How to enable exec function in php.ini : Let’s figure it out

by | Apr 7, 2020

Looking at how to enable exec function in php.ini?

Exec is a PHP function used to execute an external program like a script.

But the execution of external programs creates a security risk that attackers can misuse.

At Bobcares, we often get requests to enable PHP functions, as part of our Server Management Services.

Today, let’s see how our Support Engineers enable this function. We’ll also discuss the security risk related to the exec function.

 

What is the exec function?

The exec is an inbuilt PHP function. It replaces a currently running process with the new program. PHP uses the function to execute a program and it returns the last line of the output.

Many WordPress image optimization plugins make use of this function. Hence WordPress users often approach us to enable this function.

 

Security risk in enabling exec function

PHP has certain dangerous functions that can make a server vulnerable to attacks. These functions include system, passthru, shell_exec, exec, etc.

Hence our Support Engineers always recommend our customers to disable these functions in the server. And these functions will be listed in the disable_functions directive in a php.ini file.

How to enable exec function in php.ini

By enabling exec function there is a possible security threat. Attacks may use this function to run programs in servers that can lead to data corruption and data loss.

Considering the security risks, we suggest customers enabling the exec function on a per-account basis. Thus, it gives better tracking of user activity.

 

How we enable exec function in PHP?

One of the wisest choices is to enable the exec function in dedicated or VPS servers.

Usually, we enable this function via the php.ini file. But for cPanel accounts, we can do this via WHM. Now, let’s see how our Support Engineers enable it.

 

Using php.ini to enable exec function

To enable this function, we login to the server as the root user.

Then we open the php.ini file and search for exec function. Usually, this function will be disabled. So, we check the disable_functions directive which appears as,

disable_functions = "show_source, system, shell_exec, exec"

Hence we remove exec from the line and save the file. Thus we enabled the exec function in the server.

In addition, if the PHP handler is suPHP or LSPHP, then we have to add the directive in the .htaccess file also.

 

MultiPHP INI Editor

For cPanel customers we enable the exec function from the WHM. But the change will reflect in all cPanel accounts in WHM. So we don’t use this method to enable exec in one cPanel account.

  • To enable the function in all the accounts, we log in to the WHM.
  • Then we select the MultiPHP INI Editor from the Software section.
  • Next, we enter into the Editor Mode and choose the corresponding PHP version.
  • There we remove the exec function from disable_functions directive.
  • Finally, we save the changes.

Hence it enables the function server-wide.

 

[Need more help to enable PHP functions? – We’re available 24/7.]

 

Conclusion

In short, exec function is usually disabled in a server, as it allows attackers to execute external programs that can crack a server. Today, we saw how our Support Engineers enable exec function in php.ini.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

2 Comments

  1. erfan

    hello, is there any other ways to enable this function without touching php.ini ? i dont have access to php.ini in my host.

    Reply
    • Sijin George

      Hello Erfan,
      Enabling the exec function needs access to the php.ini file. Considering security risks, most Hosting providers control this function at the root access level.
      A VPS server with root access allows you to do such customization.

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF