Question

How to check if the exec() function is enabled in my PHP install

I am NOT a technical person, so im trying to download a backup manager extension for my app on the droplet but it requires:

the exec() function enabled in your PHP install since it will call a few command line commands to create the backups. Additionally, this only works on a linux environment where the “tar” and “mysqldump” commands are available (99% of linux servers have them)

is there detailed steps on how i can do this in putty or winscp? i have a lamp on ubunutu 20.04 using php version 7.4.3


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
February 21, 2021
Accepted Answer

Hello, @adamSar

If you’ve already configured the LAMP stack (Linux, Apache, MySQL, PHP) setup using our tutorial:

How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 20.04

then PHP is already configured as you mentioned the version is 7.4.3

You can create a PHP info file and check if the exec function is enabled/disabled. You can create a file named phpinfo.php (the name doesn’t really matter) and put the following content in the file:

<?php
phpinfo();
?>

The file must be present inside your public_html folder so you can then access the file via your browser and check the PHP information. Once the file is added go to your browser and access the file using your domain name or IP address, e.g yourdomain.com/phpinfo.php or IPaddress/phpinfo.php

You can search for disable_functions and if exec is listed it means it is disabled. To enable it just remove the exec from the line and then you need to restart Apache and you will be good to go.

If exec is not listed in the disable_functions line it means that it is enabled.

Hope that this helps! Regards, Alex

KFSys
Site Moderator
Site Moderator badge
February 21, 2021

Hi @adamSar,

If you already have PHP installed on your droplet, you can SSH to it, create a new file, for example test_exec.php like so

touch test_exec.php

Then inside of it, add the following

<?php
if(function_exists('exec')) {
    echo "exec is enabled";
}

Save the file and execute it like so

php test_exec.php

If it returns an output of exec is enabled, you’ll know you have exec enabled.

Now, if you don’t have PHP installed.

Ubuntu

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Install PHP 7.3 for Apache

sudo apt install php7.3

Install PHP 7.3 for Nginx

sudo apt install php7.3-fpm

Install PHP 7.3 Extensions

You can use the following command to install the most needed PHP extensions

sudo apt install php7.3-common php7.3-mysql php7.3-xml php7.3-xmlrpc php7.3-curl php7.3-gd php7.3-imagick php7.3-cli php7.3-dev php7.3-imap php7.3-mbstring php7.3-opcache php7.3-soap php7.3-zip php7.3-intl -y

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel