Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda