How to run server command in php

To run a server command in PHP, you can use the exec() function. The exec() function executes an external program and returns the output as a string.

Here’s an example of how to use the exec() function to run a server command:

// Run the "ls" command to list the files in the current directory
$output = exec('ls');

// Output the result of the command
echo $output;

In this example, the exec() function is used to run the ls command, which lists the files in the current directory. The output of the command is stored in the $output variable, which is then outputted using the echo statement.

Note that the exec() function can be dangerous if you are not careful, as it allows you to execute arbitrary commands on the server. It is recommended to use this function only with trusted commands and input data. You can also use the escapeshellcmd() function to escape any special characters in the command before passing it to exec().