How to run node module in php and display output? - php

I have a use case where i need to run a node module in php script and display it's output back on the page. Here's the steps I followed:
I have installed the module npm install -g md2gslides
I am using PHP's exec() for running the module
exec('node_modules/md2gslides/bin//md2gslides.js --version 2>&1', $output);
But it's not working. The error is below:
However, it runs in ubuntu's terminal without issues.
What is wrong here?

The error not because of php but because of the path.join() in line 33 of md2gslides.js
const STORED_CREDENTIALS_PATH = path.join(USER_HOME, '.md2googleslides', 'credentials.json');
It tries to find the credentials.json in users home directory. But I think it's unable to.
So I moved the file to node_modules/md2gslides/bin and modified path.join() as path.join(__dirname, '.md2googleslides', 'credentials.json')
This solved the issue.

Related

Adding php-curl in a Yocto build

I've been building a custom image using Yocto and wpewebkit to use within docker. I need to run a local web server with php, which I have accomplished no problem. I need to use curl within my project and I have apache2, php, modphp, and curl installed. All I need is php-curl but I cannot find how to install this. Does anyone know how or if I can do this? I've put in all my efforts on googling multiple phrases but I only find how to install php-curl using apt-get or yum, or I get links to the meta-* directories which I have access to within my build files anyways.
If it helps at all, this custom image was based on the image provided from the following project on GitHub: https://github.com/resin-io-playground/resin-wpe/tree/master/base-image . I already spoke to the developer and their knowledge of PHP is limited.
EDIT #1: Progress so far, had to update the curl.bb file to properly include libcurl-dev, and then worked with #pmod's suggestion to incorporate curl into the php build. Everything seemed to run okay until I received the following error:
| ../php-7.1.9/configure: line 386: test: please: integer expression expected
| configure: error: reinstall
| ../php-7.1.9/configure: line 275: return: please: numeric argument required
| ../php-7.1.9/configure: line 285: exit: please: numeric argument required
| NOTE: The following config.log files may provide further information.
| NOTE: /base-image/build/tmp-glibc/work/x86_64-linux/php-native/7.1.9-r0/build/config.log
| ERROR: configure failed
| WARNING: /base-image/build/tmp-glibc/work/x86_64-linux/php-native/7.1.9-r0/temp/run.do_configure.29590:1 exit 1 from 'exit 1'
| ERROR: Function failed: do_configure (log file is located at /base-image/build/tmp-glibc/work/x86_64-linux/php-native/7.1.9-r0/temp/log.do_configure.29590)
ERROR: Task (virtual:native:/base-image/build/../meta-openembedded/meta-oe/recipes-devtools/php/php_7.1.9.bb:do_configure) failed with exit code '1'
Edit #2: I've gone ahead and added everything I was missing. I'm getting the same error above, where the function do_configure during the php build is failing. I'm posting below what I ensured I have in my curl.bb file (I had to add this), what I have in my php.inc file, and the curl files located staging directory.
curl.bb:
PACKAGES =+ "lib${BPN} lib${BPN}-native lib${BPN}-dev lib${BPN}-dev-native"
FILES_lib${BPN} = "${libdir}/lib*.so.*"
FILES_lib${BPN}-dev = "${includedir} \
${libdir}/lib*.so \
${libdir}/lib*.a \
${libdir}/lib*.la \
${libdir}/pkgconfig \
${datadir}/aclocal \
${bindir}/*-config"
php.inc:
EXTRA_OECONF_append = " --with-curl=${libdir}/.."
DEPENDS_${PN} += "libcurl-dev libcurl-dev-native"
PHP Staging Directory:
/installeddeps/curl-native
/installeddeps/curl-native.b77f37db31cf2391919a12c5c9774bff
/installeddeps/curl-native.complete
/usr/share/aclocal/libcurl.m4
/usr/bin/curl-config
/usr/bin/crossscripts/curl-config
/usr/bin/curl
/usr/lib/pkgconfig/libcurl.pc
/usr/lib/libcurl.so
/usr/lib/libcurl.a
/usr/lib/libcurl.so.4.4.0
/usr/lib/libcurl.so.4
/usr/include/curl
/usr/include/curl/curl.h
/usr/include/curl/curlrules.h
/usr/include/curl/curlbuild.h
/usr/include/curl/curlver.h
/usr/include/curl/easy.h
According to php manual, PHP/cURL feature is enabled at php configuration stage with --with-curl=[dir] option.
I checked the main recipe include file php.inc and couldn't find such configuration option. So, try creating in your working layer php_%.bbappend file with (or add this directly to the bottom of php.inc to test):
EXTRA_OECONF_append_class-target = " --with-curl=${STAGING_LIBDIR}/.."
DEPENDS_append_class-target = " curl"
Note, that curl package among DEPENDS because it is needed at build stage.
I don't think you need to update curl recipe with PACKAGES and FILES, pkg_config should take care

Selenium: FirefoxProfile exception Can't load the profile. Python script called from PHP

My python script has the following code:
firefox_profile = webdriver.FirefoxProfile()
self.driver = webdriver.Firefox(firefox_profile=firefox_profile)
When I execute the script from bash it works, but if I call the script from a PHP file, with the following command:
shell_exec("python path_to_the_script");
I receive the exception:
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /tmp/tmp7Ob0z6/webdriver-py-profilecopy If you specified a log_file in the FirefoxBinary constructor, check it for details.
I've also tried to set the profile manually, like this:
firefox_profile = webdriver.FirefoxProfile(profile_directory='path_to_the_profile_dir')
But nothing changed, while if I set the profile directory path like this:
firefox_profile = webdriver.FirefoxProfile(profile_directory='path_to_the_profile_dir')
firefox_profile.profile_dir = 'path_to_the_profile_dir'
The exception error changes to this:
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: path_to_the_profile_dir If you specified a log_file in the FirefoxBinary constructor, check it for details.
I've set the permissions to 777 for all the involved directories, and also tried to override the FirefoxBinary.launch_browser function so that it uses a greater timeout value, but id did not work.
I'm using Python 2.7, Selenium 2.53.6 and Firefox 46.0.1
Firefox is working in headless mode, through Xvfb and pyvirtualdisplay.
This happens because you have updated firefox to a version that's no longer supported by selenium.
So to fix this you have 2 options.
Downgrade your firefox to an older version then 47
Update Selenium and Install geckodriver (recommended and easy)
If you have ubuntu follow this fix below:
1. Update selenium with "sudo pip install -U selenium"
2. Download the geckodriver from github -->
Gecko Github Link
3. Extract the tar.gz folder and move the gecko executable to /usr/local/bin
4. Now open your terminal and enter this command: export PATH=$PATH:/usr/local/bin/geckodriver
That should fix the issue... atleast it worked for me.
My Source: StackOverflow - Geckodriver
If that didn't fix your issue check your firefox profile name
like this
fp = webdriver.FirefoxProfile('/home/YOUR_USERNAME/.mozilla/firefox/YOUR_PROFILE_NAME.default')
driver = webdriver.Firefox(firefox_profile=fp)
To find your firefox profile name open your file browser and enable "show hidden files" go to "Home/.mozilla/firefox" and you'll see your firefox profile folder.
I hope that solved your issue

Unable to run google app engine script with PHP

So, I'm trying to run the Hello World script but whenever I run dev_appserver.py I hit a wall.
Here's the error log from the script:
$ appengine/dev_appserver.py --php_executable_path=/usr/local/bin/php-cgi HelloWorld
...
ERROR 2016-03-29 12:57:30,588 php_runtime.py:348] The PHP runtime
is not available Traceback (most recent call last): File
"/Users//desktop/appengine/google/appengine/tools/devappserver2/php_runtime.py",
line 344, in new_instance
self._check_binaries(php_executable_path, gae_extension_path) File
"/Users//desktop/appengine/google/appengine/tools/devappserver2/php_runtime.py",
line 284, in _check_binaries
cls._check_environment(php_executable_path, env) File "/Users//desktop/appengine/google/appengine/tools/devappserver2/php_runtime.py",
line 259, in _check_environment
raise _PHPEnvironmentError(check_process_stdout)
_PHPEnvironmentError: No input file specified.
As a background to my El Capitan setup...
I've previously updated PHP to 5.5 using:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5
But I've also downloaded via HomeBrew php54 and that's what should be running the php-cgi script I've posted in the executable path above.
Any thoughts?
So turns out, the answer was pretty obvious - I'd installed the Go SDK rather than the PHP one! Google's website scrolls to the wrong place when you click PHP. Many hours wasted trying to fix this one - never mind. Hope this helps another as simple as me!
if you already installed google-cloud-sdk run this command :
gcloud components install app-engine-php-darwin
you won't need to specify that path after this

Cannot make command line tool for artisan in PHPStorm 10.0.1

I got this error message when I tried to make an alias for artisan:
[Settings | Tools | Command Line Tool Support ] -> add -> tool based on Symfony Console
Problem
Failed to parse output as xml: Error on line 4: Content is not allowed in prolog..
Command
C:\xampp\php\php.exe C:\xampp\htdocs\laratest\artisan list --xml
Output
[Symfony\Component\Console\Exception\RuntimeException]
The "--xml" option does not exist.
Ok, I know, what's the problem but I don't find any solution for this.
Thank you for the tips!
A temporal modification of the "artisan" file under the Laravel folder will do the trick. (Working on PhpStorm 10.0.3)
if( isset($argv[1]) && $argv[1] == 'list' &&
isset($argv[2]) && $argv[2] == '--xml' ) {
$argv[2] = '--format=xml';
$_SERVER['argv'] = $argv;
}
require __DIR__.'/bootstrap/autoload.php';
Now you can add the "artisan" command line tool support based on Symfony and remove the lines if you wish to.
For everybody affected, this is the commit which removed support for –xml: https://github.com/symfony/console/commit/6d6d9031b9148fed0e2aacb98ac23ce6168ba7ac
Just revert changes in ListCommand.php
it work in 2.7 version
There is no --xml option, you are getting this error when you running this command:
The "--xml" option does not exist.
So what you should do in this case is running:
php artisan help list
and you will get list of all available parameters
and now you will know you need to use:
php artisan list --format=xml
instead of:
php artisan list --xml
EDIT
I've verified it in PhpStorm 10.0.3
as Tool path you can paste in your case:
C:\xampp\php\php.exe C:\xampp\htdocs\laratest\artisan list --format=xml
and it will work
Update composer before add command line tool:
composer update

no new line in terminal after setting up cakephp

I attempted to set up vi .profile for baking in cakephp but now when I open terminal (mac OSX) I get the following error
PHP Warning: PHP Startup: Unable to load dynamic library '/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/php_gd2.dll' - dlopen(/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/php_gd2.dll, 9): image not found in Unknown on line 0
I can't type in any commands into terminal and pressing enter just drops the line down. The "title" of terminal says PHP 5.3.1, so I'm not sure if it somehow left the standard user mode (whatever that's called). I've restarted my computer and terminal opens up with this same message.
Is there some kind of command I can enter in the menus to revert out of this? Can someone please help me get terminal back to "normal."
edit - I went to shell->new command and typed in su root; to log in. This works, however, when I open up a new terminal window I still get the same php error and I can't figure out how to log in normally when terminal opens.
The ~/.profile by defauilt is empty on OSX (at least on my machine). So just commenting everything out or just removing the pieces you added for the cakePHP will clear the parts that are messing up your new shells.

Categories