Laravel Elixr copy method not working - php

I am trying to copy some js files, using elixr, from my vendor/bower_components folder, but when running gulp they don't copy across.
elixir(function(mix) { mix.less('app.less')
.copy('underscore/underscore.js', 'public/js/vendor/underscore.js'); });
No error is given by gulp.
[14:12:58] Using gulpfile ~/Public/balloonprinting_l5/gulpfile.js
[14:12:58] Starting 'default'...
[14:12:58] Starting 'less'...
[14:12:58] Running Less: resources/assets/less/app.less
[14:12:59] Finished 'default' after 506 ms
[14:13:00] gulp-notify: [Laravel Elixir] Less Compiled!
[14:13:00] Finished 'less' after 1.74 s
[14:13:00] Starting 'copy'...
[14:13:00] Finished 'copy' after 2.86 ms

You need to specify full source path:
elixir(function(mix) { mix.less('app.less')
.copy(
'bower_components/underscore/underscore.js',
'public/js/vendor/underscore.js'
);
});
As you can see I added bower_components/ to source path, this is default bower packages folder.

Related

AWS Lambda with php.handler node 12.x error - SOLVED

UPDATE: Thank you all! I have solved this by creating a custom runtime for my PHP Lambda.
I am currently using Node.js 8.10 Runtime with a php.handler and my Lambda function works fine, but when I change the Runtime to 12.x, I get the following error:
"php-7-bin/bin/php: error while loading shared libraries: libcrypt.so.1: cannot open shared object file: No such file or directory"
exports.handler = function(event, context, callback) {
var php = spawn('php-7-bin/bin/php',['--php-ini', 'user.ini', process.env['PHPFILE']], {maxBuffer: 200 * 1024 * 200});
var output = "";
var statusCode = 0;
php.stdin.write(JSON.stringify(event));
php.stdin.end();
php.stdout.on('data', function(data) {
console.log("CHUNK: " + data);
output+=data;
});
php.stderr.on('data', function(data) {
console.log(data);
});
php.on('close', function(code) {
var obj = JSON.parse(output);
statusCode = obj.status.statusCode;
if(statusCode !== 0){
callback(output);
}else{
context.succeed(obj);
}
});
}
I need to update my Lambda to the latest node.js version, but I have no idea how to overcome this error, so any help would be greatly appreciated!
First, why on earth are you using node to load php?
But if you had this working before, why do you need to update to node 12?
If you are upgrading from Node 8, the runtime is different:
https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
So then take a look here:
https://aws.amazon.com/blogs/apn/aws-lambda-custom-runtime-for-php-a-practical-example/
You may need to create a new custom runtime based off the node12 built-in runtime for AWS.
Easy fix is to add on top of your PHP code:
set_include_path('/opt/lib64’);
If that won't work you need to compile/build/install the missing modules/libraries by yourself:
Run two docker instances that will have mounted the same “local” Layer folder.
First container is going to be your lambda container while second one is Amazon linux used to build items.
Test your code with Lambda container and in case something is missing switch to Amazon Linux and build/extract binaries/libraries into shared Layer folder structure.
Make sure the Lambda code have proper PATH defined to use Layer folder.
Install docker.
In first terminal tab go to your lambda folder and start the lambda docker container:
docker run --rm -it --entrypoint=/bin/bash -v "$PWD":/var/task:ro,delegated -v /your/path/to/Layer/folder/:/opt:rw,delegated -e AWS_ACCESS_KEY_ID=[ACCESS_KEY_PASTE_HERE -e AWS_SECRET_ACCESS_KEY=[SECRET_GOES_HERE] lambci/lambda:nodejs12.x
In second terminal tab run another container with Amazon linux:
docker run --rm -it -v /your/path/to/Layer/folder/:/opt:rw,delegated amazonlinux:latest
(Keep in mind that the Layer folder is mounted with read/write permissions).
Test your lambda code in your favourite way or just by simple run (make sure to check if your handler module name is “handler” and file name is “index.js”):

cd /var/task
node index.js; node "var func = require('./index.js');func.handler({},function() {},function(){console.log('Lambda finished')});"
In case you find some missing libraries, make sure to add to your PHP code:
set_include_path('/opt/lib');
Then on Amazon Linux terminal tab and install/build your library and then copy it to Layer folder:
cp /usr/lib64/[here is your library name] /opt/lib
Test again your code in Lambda container.
When you will be done just zip the content of your Lambda Layer structure, keep in mind that your \bin ora \lib folders need to be in the root folder of the zip file.
Add the zip file as a Layer for you lambdas and attach it.
I Fix this problem by adding extra library folder in my function's zip.
Make a directory name extra-libs
Copy all required libraries from Amazon Linux 2 to Extra-libs by using following steps :
Run amazon Linux 2's docker instance by following command
docker run --rm -it -v :/opt:rw,delegated amazonlinux:latest
Then in docker instance make directory using
mkdir deps
Copy all required libraries from lib64 to deps directory using
cp -f lib64/libcrypt.so.1 deps (Taken libcrypt.so.1 for example purpose)
Then open another terminal window and move all library files to local extra-libs
docker cp <DOCKER_CONTAINER_ID>:/deps/ . && mv deps/* ./extra-libs
Get container id by using docker ps
Then in index.js file , add following line to php's env setting.
LD_LIBRARY_PATH:path.join(__dirname, '/extra-libs')
Zip extra-libs folder with your lambda function and upload it.
Hope this helps.

how to solve error QXcbConnection: Could not connect to display when using exec function for phantomJs using PHP

I am working on a project where I want to use PHP and Phantomjs together, I have completed my phantomJs script and trying to run it using php exec function. but the function is returning an array of error list.
below I am writing my code of phantomjs and php
dir: /var/www/html/phantom/index.js
var page = require('webpage').create();
var fs = require('fs');
page.open('http://insttaorder.com/', function(status) {
// Get all links to CSS and JS on the page
var links = page.evaluate(function() {
var urls = [];
$("[rel=stylesheet]").each(function(i, css) {
urls.push(css.href);
});
$("script").each(function(i, js) {
if (js.src) {
urls.push(js.src);
}
});
return urls;
});
// Save all links to a file
var url_file = "list.txt";
fs.write(url_file, links.join("\n"), 'w');
// Launch wget program to download all files from the list.txt to current
// folder
require("child_process").execFile("wget", [ "-i", url_file ], null,
function(err, stdout, stderr) {
console.log("execFileSTDOUT:", stdout);
console.log("execFileSTDERR:", stderr);
// After wget finished exit PhantomJS
phantom.exit();
});
});
dir: /var/www/html/phantom/index.php
exec('/usr/bin/phantomjs index.js 2>&1',$output);
echo '<pre>';
print_r($output);
die;
Also tried with
exec('/usr/bin/phantomjs /var/www/html/phantom/index.js 2>&1',$output);
echo '<pre>';
print_r($output);
die;
After runing this i am getting below error
Array
(
[0] => QXcbConnection: Could not connect to display
[1] => PhantomJS has crashed. Please read the bug reporting guide at
[2] => and file a bug report.
[3] => Aborted (core dumped)
)
But if I run index.php file from the terminal like this:
user2#user2-H81M-S:/var/www/html/phantom$ php index.php
then it works fine.I don't know how to solve it. Please help.
i am using following version
system version: Ubuntu 16.04.2 LTS
PHP version: 5.6
phantomJs version: 2.1.1
Did you tried to set an environment variable on your server ? or added it before calling phantomjs ?
I was in the same situation and found some solutions:
a. define or set variable QT_QPA_PLATFORM to offscreen:
QT_QPA_PLATFORM=offscreen /usr/bin/phantomjs index.js
b. or add this line into your .bashrc file (put it at the end):
export QT_QPA_PLATFORM=offscreen
c. or install the package xvfb and call xvfb-run before phantomjs:
xvfb-run /usr/bin/phantomjs index.js
d. or use the parameter platform:
/usr/bin/phantomjs -platform offscreen index.js
Maybe you don't want / can't make modification on your server and in that case you may try to download the static binary from official website then:
/path/to/the/bin/folder/phantomjs index.js
and / or create an alias in your .bash_aliases file like this:
alias phantomjs=/path/to/the/bin/folder/phantomjs
make sure that phantomjs is not installed already on the system if you decide to use the alias.
if the file .bash_aliases not exist already, feel free to create it or add the alias line at the end of the .bashrc file
Some references:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=817277
https://github.com/ariya/phantomjs/issues/14376
https://bugs.launchpad.net/ubuntu/+source/phantomjs/+bug/1586134
I had the same problem running phantomjs on headless Ubuntu 18.04 (on the default Vagrant vm install of openstreetmap-website). Folloiwng Jiab77's links, it seems the Phantomjs team says the problem is the Debian package but the Debian team closed the bug as wontfix. I needed phantomjs to "just work" so it can be called by other programs that expect it to work normally. Specifically, openstreetmap-website has an extensive Ruby test suite with over 40 tests that were failing because of this, and I didn't want to modify all those tests.
Following Jiab77's answer, here's how I made it work:
As root, cp /usr/bin/phantomjs /usr/local/bin/phantomjs
Edit /usr/local/bin/phantomjs and add the line export QT_QPA_PLATFORM=offscreen so it runs before execution. Here is what mine says after doing so:
#!/bin/sh
LD_LIBRARY_PATH="/usr/lib/phantomjs:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH
# 2018-11-13: added the next line so phantomjs can run headless as explained on
# https://stackoverflow.com/questions/49154209/how-to-solve-error-qxcbconnection-could-not-connect-to-display-when-using-exec
export QT_QPA_PLATFORM=offscreen
exec "/usr/lib/phantomjs/phantomjs" "$#"
After this change, phantomjs can be run from the command line without changing anything else, and all the tests that depend on phantomjs were successfully passed.

Gulp Command running Error in Laravel 5.3

I am new in Laravel. I am trying to run gulp command in CMD to get CSS and JS (vue.js) file. I am getting following error while I am trying to run gulp command in CMD. I am using Laravel 5.3.
{ [Error: ./resources/assets/js/app.js
Module build failed: ReferenceError: Unknown plugin "add-module-exports" specified in "base" at 0, attempted to resolve relative to "D:\\php7\\htdocs\\addbook\\
resources\\assets\\js" at D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\file\options\option-manager.js:176:17
at Array.map (native) at Function.normalisePlugins (D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\file\options\option-manager.js:154:20)
at OptionManager.mergeOptions (D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\file\options\option-manager.js:229:36)
at OptionManager.init (D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\file\options\option-manager.js:374:12)
at File.initOptions (D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\file\index.js:216:65)
at new File (D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\file\index.js:139:24)
at Pipeline.transform (D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
at transpile (D:\php7\htdocs\addbook\node_modules\babel-loader\index.js:38:20)
at Object.module.exports (D:\php7\htdocs\addbook\node_modules\babel-loader\index.js:131:12)]
message: './resources/assets/js/app.js\nModule build failed: ReferenceError: Unknown plugin "add-module-exports" specified in "base" at 0, attempted to resolv
e relative to "D:\\\\php7\\\\htdocs\\\\addbook\\\\resources\\\\assets\\\\js"\n at D:\\php7\\htdocs\\addbook\\node_modules\\babel-core\\lib\\transformation\\f
ile\\options\\option-manager.js:176:17\n at Array.map (native)\n at Function.normalisePlugins (D:\\php7\\htdocs\\addbook\\node_modules\\babel-core\\lib\\t
ransformation\\file\\options\\option-manager.js:154:20)\n at OptionManager.mergeOptions (D:\\php7\\htdocs\\addbook\\node_modules\\babel-core\\lib\\transforma
tion\\file\\options\\option-manager.js:229:36)\n at OptionManager.init (D:\\php7\\htdocs\\addbook\\node_modules\\babel-core\\lib\\transformation\\file\\optio
ns\\option-manager.js:374:12)\n at File.initOptions (D:\\php7\\htdocs\\addbook\\node_modules\\babel-core\\lib\\transformation\\file\\index.js:216:65)\n at
new File (D:\\php7\\htdocs\\addbook\\node_modules\\babel-core\\lib\\transformation\\file\\index.js:139:24)\n at Pipeline.transform (D:\\php7\\htdocs\\addboo
k\\node_modules\\babel-core\\lib\\transformation\\pipeline.js:46:16)\n at transpile (D:\\php7\\htdocs\\addbook\\node_modules\\babel-loader\\index.js:38:20)\n
at Object.module.exports (D:\\php7\\htdocs\\addbook\\node_modules\\babel-loader\\index.js:131:12)',
showStack: false,
showProperties: true,
plugin: 'webpack-stream',
__safety: { toString: [Function: bound ] } }
Could anyone give me any solution regarding this ?
gulpfile.js
var elixir = require('laravel-elixir');
require('laravel-elixir-vue');
elixir(function(mix) {
mix.sass('app.scss');
});
elixir(function(mix) {
mix.webpack('app.js');
});
elixir(function(mix) {
mix.version(['css/app.css', 'js/app.js']);
});
From the Laravel Docs:
If you are developing on a Windows system or you are running your VM
on a Windows host system, you may need to run the npm install command
with the --no-bin-links switch enabled:
npm install --no-bin-links
Laravel Docs: Elixir Installation and Setup
Remove /node_modules and run npm install with the --no-bin-links switch like mentioned in the docs and quoted above.

Laravel BrowserSync without proxy

I'm trying to use Elixir BrowserSync, one of the newest features of Laravel.
I added it to the gulp file
elixir(function(mix) {
mix.sass('app.scss')
.browserSync();
});
when I run "gulp watch" it output this message
[20:49:20] Using gulpfile ~/Desktop/laravel/gulpfile.js
[20:49:20] Starting 'watch'...
[20:49:20] Finished 'watch' after 11 ms
[BS] Proxying: http://homestead.app
[BS] Access URLs:
----------------------------------
Local: http://localhost:3000
External: http://10.9.0.48:3000
Automatically a browser is launched with the url http://localhost:3000 but nothing loads.
I think the problem is related to this line:
[BS] Proxying: http://homestead.app
You can if you use BrowserSyncs server.
mix.browserSync({
proxy: false,
server: {
baseDir: './'
}
});
Are you running multiple homestead sites? It looks like it defaults to proxying through homestead.app if you do not include a proxy setting. If you don't host your local on homestead.app it won't find it.
Try
.browserSync({ proxy: 'domain.app' });
Where domain.app is what you are serving the site with.
The direct answer to your question - it is not possible to not proxy the .browserSync. Long side-answer - you can still use elixir's implementation of browserSync in gulp, but you must have a separate PHP server to interpret the files.
Edit: I saw a way to not proxy by providing the script in the pages manually (by not giving any arguments in the .browserSync() call, but don't remember where and how to do it exactly.
The reason is that browserSync requests all the data from the server for you, injects a little javascript listener and displays everything else:
<script type='text/javascript' id="__bs_script__">//<![CDATA[document.write("<script async src='/browser-sync/browser-sync-client.2.9.11.js'><\/script>".replace("HOST", location.hostname));//]]></script>
One way is to php artisan serve --host=0.0.0.0 in a separate terminal to start up the server and then use the .browserSync({proxy: 'localhost:8000'}). It all works - the BrowserSync UI and all the calls to refresh the pages.
Note: I could not connect to artisan serve without the --host=0.0.0.0.
For those wanting an all automated solution via gulp, here it is:
Use the gulp packages gulp-connect-php and laravel-elixir-browsersync2. The first starts up the php artisan serve and the other connects it to browserSync.
Install the packages:
npm install laravel-elixir-browsersync2 --save-dev
npm install gulp-connect-php --save-dev
Add the required lines to your gulpfile.js:
Code:
var elixir = require('laravel-elixir'),
gulp = require('gulp');
var connectPHP = require('gulp-connect-php');
var BrowserSync = require('laravel-elixir-browsersync2');
elixir(function(mix) {
mix.sass('app.scss');
});
elixir(function(mix) {
connectPHP.server({
base: './public',
hostname: '0.0.0.0',
port: 8000
});
BrowserSync.init();
mix.BrowserSync(
{
proxy: 'localhost:8000',
logPrefix : "Laravel Eixir BrowserSync",
logConnections : false,
reloadOnRestart : false,
notify : false
});
});
Then - simply gulp.
Disclaimer: This might not work with the gulp watch, but there might be people with the answer to that.
There is also a line PHP server not started. Retrying... before the [Laravel Eixir BrowserSync] Proxying: http://localhost:8000. It belongs to gulp-connect-php when trying to check if the server is running.
I found other solution on laracast for Bloomanity and it works with me like a charm!
$ php artisan serve --host=0
and then in your gulp add:
mix.browserSync({proxy: 'localhost:8000'});

php-node Node Express cannot find module

The error is:
Cannot find module 'php'
Error: Cannot find module 'php'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at new View (F:\Users\MichaelJacksonIsDead\publisherServer\node_modules\express\lib\view.js:50:49)
at EventEmitter.app.render (F:\Users\MichaelJacksonIsDead\publisherServer\node_modules\express\lib\application.js:545:12)
at ServerResponse.res.render (F:\Users\MichaelJacksonIsDead\publisherServer\node_modules\express\lib\response.js:938:7)
at F:\Users\MichaelJacksonIsDead\publisherServer\routes\index.js:12:6
at Layer.handle [as handle_request] (F:\Users\MichaelJacksonIsDead\publisherServer\node_modules\express\lib\router\layer.js:82:5)
at next (F:\Users\MichaelJacksonIsDead\publisherServer\node_modules\express\lib\router\route.js:110:13)
The Route for this page to render as php is as follows:
router.get('/index.php', function(req, res, next) {
var render = require('php-node')({bin:"F:\\xampp\php\\php.exe"});
res.render('index.php');
});
I have run a npm install -g, npm install node-php -g at both project level and level above with no success:
F:\Users\MichaelJacksonIsDead\publisherServer>npm install -g
publisherServer#0.0.0 F:\Users\MichaelJacksonIsDead\AppData\Roaming\npm\node_mod
ules\publisherServer
├── php-node#0.0.2
├── debug#2.2.0 (ms#0.7.1)
├── serve-favicon#2.2.1 (ms#0.7.1, fresh#0.2.4, parseurl#1.3.0, etag#1.6.0)
├── cookie-parser#1.3.5 (cookie#0.1.3, cookie-signature#1.0.6)
├── morgan#1.5.3 (basic-auth#1.0.1, depd#1.0.1, on-finished#2.2.1)
├── body-parser#1.12.4 (bytes#1.0.0, content-type#1.0.1, depd#1.0.1, raw-body#2.
0.2, on-finished#2.2.1, qs#2.4.2, iconv-lite#0.4.8, type-is#1.6.2)
├── express#4.12.4 (merge-descriptors#1.0.0, utils-merge#1.0.0, methods#1.1.1, f
resh#0.2.4, cookie#0.1.2, escape-html#1.0.1, cookie-signature#1.0.6, range-parse
r#1.0.2, content-type#1.0.1, parseurl#1.3.0, finalhandler#0.3.6, vary#1.0.0, ser
ve-static#1.9.3, content-disposition#0.5.0, path-to-regexp#0.1.3, depd#1.0.1, on
-finished#2.2.1, qs#2.4.2, etag#1.6.0, proxy-addr#1.0.8, send#0.12.3, type-is#1.
6.2, accepts#1.2.7)
├── hjs#0.0.6 (hogan.js#3.0.2)
└── less-middleware#1.0.4 (mkdirp#0.3.5, node.extend#1.0.10, less#1.7.5)
F:\Users\MichaelJacksonIsDead\publisherServer>npm start
> publisherServer#0.0.0 start F:\Users\MichaelJacksonIsDead\publisherServer
> node ./bin/www
GET /index.php 500 41.145 ms - 954
Does anyone have any expirence with this issue? As far as I can tell I have correctly installed it... also to make sure I added the package to my json file as follows:
"dependencies": {
"body-parser": "~1.12.4",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.12.4",
"hjs": "~0.0.6",
"less-middleware": "1.0.x",
"morgan": "~1.5.3",
"serve-favicon": "~2.2.1",
"php-node": "0.0.2"
}
Lastly I did not have enough rep to open a tag php-node for the project # https://www.npmjs.com/package/php-node, not a issue but would of been nice to have a more speficic tag :)
I have found the answer, thank you #mscdex and #adeneo
I replaced the default:
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hjs');
with
// use PHP as view engine in Express
var phpnode = require('php-node')({bin:"F:\\xampp\\php\\php.exe"});
app.engine('php', phpnode);
app.set('view engine', 'php');
under routes:
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index.hjs', { title: 'Express' });
});
router.get('/index.php', function(req, res, next) {
res.render('index.php');
});
The app still supports php and index.hjs pages.
You should only use -g when you're installing a module from npm that contains a command line utility (e.g. express-generator is an example of this). However in almost all cases you should just simply do npm install <module name> which will install the module locally and allow you to require() it.
So do npm install in your project's root directory and require() should be able to find php-node.
only if the plugin are use you are not 100% happy of it there is a simple method(this is only a prototype so if you are node.js expert you may improve it) to build FROM ONLY ONE SERVER APPS NODE.JS - PHP (and theoretical you have yet sqlite3 and after installing a mariadb or mysql server you can use them as well) :
https://stackoverflow.com/a/68422021/5781320

Categories