Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Running command through Terminal working fine but using shell_exec not - PHP

I'm writing a PHP script to scrape external website products. The external website uses JavaScript to render product lists that's why my PHP script was not working to scrape those products.

So, I searched for another solution and found JavaScript libraries like PhantomJS and CasperJS.

I've done all my work on my local server but when I'm unable to run my code on Linux.

Here is what I tried through cPanel terminal:

export PHANTOMJS_EXECUTABLE=/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/phantomjs/bin/phantomjs

And

/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/casperjs/bin/casperjs /home/saadatas/public_html/wp-content/plugins/product-scraper/assets/js/ScrapeCategoryProducts.js

I got the expected result but when I tried the same in my PHP code using shell_exec, it didn't work. Here is the PHP file code.

shell_exec('export PHANTOMJS_EXECUTABLE=/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/phantomjs/bin/phantomjs');

And

exec('/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/casperjs/bin/casperjs /home/saadatas/public_html/wp-content/plugins/product-scraper/assets/js/ScrapeCategoryProducts.js');

NOTE: I also tried adding 2>&1 in the script and I double-checked that the shell_exec command is enabled.

Also, tried using putenv but it didn't work.

putenv("CASPERJS_EXECUTABLE=".SC_PLUGIN_DIR.'includes/casperjs/bin/casperjs');

Let me if you need more detail.

Any help will be appreciated.

Thanks in advance.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!