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 7610943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:32:33+00:00 2026-05-31T01:32:33+00:00

I have a script that uses passthru() to run a command. I need to

  • 0

I have a script that uses passthru() to run a command. I need to set some shell environment variables before running this command, otherwise it will fail to find it’s libraries.

I’ve tried the following:

putenv("LD_LIBRARY_PATH=/path/to/lib");
passthru($cmd);

Using putenv() doesn’t appear to propagate to the command I’m running. It fails saying it can’t find it libraries. When I run export LD_LIBRARY_PATH=/path/to/lib in bash, it works fine.

I also tried the following (in vain):

exec("export LD_LIBRARY_PATH=/path/to/lib");
passthru($cmd);

How can I set a shell variable from PHP, that propagates to child processes of my PHP script?

Am I limited to checking if a variable does not exist in the current environment and asking the user to manually set it?

  • 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-05-31T01:32:35+00:00Added an answer on May 31, 2026 at 1:32 am

    I’m not 100% familiar with how PHP’s exec works, but have you tried: exec("LD_LIBRARY_PATH=/path/to/lib $cmd")

    I know that this works in most shells but I’m not sure how PHP doing things.

    EDIT: Assuming this is working, to deal with multiple variables just separate them by a space:

    exec("VAR1=val1 VAR2=val2 LD_LIBRARY_PATH=/path/to/lib $cmd")

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

Sidebar

Related Questions

I am running a PHP script that uses the passthru function to run system
I have a install script that uses DATE. I'm running SQL Server 2008 R2,
I have some script, that uses files in directories around it. It uses dirname
So I have a script in ruby that obviously uses variables. Part of the
I have a php curl script that uses 10 MB per running session. I'd
I have a simple perl script that uses DBD::Oracle to run a query and
Using Vista... I have a script that uses ADSI to set ScriptMaps on an
I have a php script that uses Doctrine2 and Zend to calculate some things
I have a python 3 script that uses itertools.product , but I need to
I have a script that uses $(document).ready , but it doesn't use anything else

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.