title: Running command through Terminal working fine but using shell_exec not - PHP
body: <p>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.</p>
  <p>So, I searched for another solution and found JavaScript libraries like <strong>PhantomJS</strong> and <strong>CasperJS</strong>.</p>
  <p>I've done all my work on my local server but when I'm unable to run my code on Linux.</p>
  <p><strong>Here is what I tried through cPanel terminal:</strong></p>
  <pre><code>export PHANTOMJS_EXECUTABLE=/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/phantomjs/bin/phantomjs
  </code></pre>
  <p>And</p>
  <pre><code>/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
  </code></pre>
  <p>I got the expected result <strong>but</strong> when I tried the same in my PHP code using <code>shell_exec</code>, it didn't work. Here is the PHP file code.</p>
  <pre><code>shell_exec('export PHANTOMJS_EXECUTABLE=/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/phantomjs/bin/phantomjs');
  </code></pre>
  <p>And</p>
  <pre><code>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');
  </code></pre>
  <p><strong>NOTE:</strong> I also tried adding <strong>2&gt;&amp;1</strong> in the script and I double-checked that the <code>shell_exec</code> command is enabled.</p>
  <p>Also, tried using putenv but it didn't work.</p>
  <pre><code>putenv(&quot;CASPERJS_EXECUTABLE=&quot;.SC_PLUGIN_DIR.'includes/casperjs/bin/casperjs');
  </code></pre>
  <p><em>Let me if you need more detail.</em></p>
  <p>Any help will be appreciated.</p>
  <p>Thanks in advance.</p>