How to call Linux command within PHP?
Welcome to SEOChat, a community dedicated to helping beginners and professionals alike in improving their Search Engine Optimization knowledge. Sign up today to gain access to the combined insight of tens of thousands of members.
How to call Linux command within PHP?
Looks like you use backticks `
http://www.rvdavid.net/execute-linux-commands-in-php-by-using-backticks/
You can execute linux commands within a php script – all you have to do is put the command line in backticks (`).
Recently, I had to upload an archive to a server which did not allow ssh. For files that I need to transfer, I just package them up in a neat archive and transfer the archive file via scp. Not having ssh access however, I uploaded the archive file via ftp and created a script which extracts the file the file looks like the following:
<?php
#extractarchive.php
echo `tar -xvfz somearchive.tar.gz`;
?>
Upon loading up “extractarchive.php”, I can see the output of the tar command through the browser. I did this by using the echo function on the backticked command line – this is not necessary for the backticked command to be executed by php.
Of course, the PHP file will need to have the necessary permissions to execute commands and as always, proceed with caution. I myself do not like doing things this way, I’ve used it in the past as a last resort. But if you ever need to do something like this, at least you know that this can be done with PHP.
<?php shell-exe('1s');?>
Become Part of This Conversation
Join NowFor Free!