Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7970757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:28:37+00:00 2026-06-04T07:28:37+00:00

I am trying to Execute a multiple commands in php using exec() and shell_exec

  • 0

I am trying to Execute a multiple commands in php using exec() and shell_exec but i am getting a null value back which i shouldn’t and nothing is happening (if i copy and paste the strings below in the command line it will work fine and accomplish the job needed) this is the commands i am using:

$command = "cd /../Desktop/FolderName;";
$command .= 'export PATH=$PATH:`pwd`;';
$command .= 'Here i execute a compiler;';

and then i use the escapeshellcmd()

$escaped_command = escapeshellcmd($command);

then

shell_exec($escaped_command);

any ideas what i am doing wrong and i also tried escapeshellarg() instead of escapeshellcmd()?

Solution: the Problem was the permission of the execution compiler for other owners is non and this was the problem.
because when you are using exec() function in php the owner of the file will be www-data so you need to give permission for the www-data either from the ACL of ubuntu or whatever linux based operating system(you can know the owner by doing this exec('whoami')), or by the files you need to execute.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:28:38+00:00Added an answer on June 4, 2026 at 7:28 am

    (Sorry my bad English)
    On Linux you can add your Commands in a Shell Script.

    You can put this in any file:

    #!/bin/bash
    cd /../Desktop/FolderName
    export PATH=$PATH:`pwd`
    EXECUTE COMPILER
    

    And save this as fille.sh

    Then, add execution permissions:
    chmod +x path/to/file.sh

    From PHP, you can call this Script executing:
    shell_exec(‘sh path/to/file.sh’);

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following command i am trying to ssh commands and execute the multiple
I am trying to execute DBCC CHECK DB('MyDB) using ADO.Net, but how can I
In my Script Component, am trying to execute Stored Procedure => which return multiple
I am using VS2005 and SQL Server 2005. I am trying to execute multiple
I am using VS2005 and SQL Server 2005. I am trying to execute multiple
So I'm wondering, how do I execute multiple commands in CMD using C#? What
I'm trying to execute a batch file in C#, but I'm not getting any
I`m trying to execute linux commant 'cat' from java code, but it does not
I'm trying to execute a SQL command, but I just can't find out why
I am trying to execute a query using for loop. For each loop it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.