How to install PhantomJS on vps? - phantomjs

I tried to use pip install, but it tells cannot find such package.
I also see someone say we can use brew and nodejs to install. This is what I tried to install brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
It returns that ruby doesn't found.
I have no idea about nodejs.
Anyone knows how can I install PhantomJS in the server?

Meet npm!
Npm stands for Node Package Manager.
You can install packages for using them from the CLI or from your nodejs app.
You can install NPM from here.
If node isn't installed yet, you can use NVM, which makes it really easy -
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
For your question,
See this specific package.
You can install it via:
$ npm install phantomjs-prebuilt
And then you should be able to: $ bin/phantomjs [phantom arguments] to run phantomJS from the terminal.

PhantomJS is a standalone application with its own website which has binaries for all major platforms and documentation. You don't really need pip or npm or bundler to install it, just do it manually.
Go to http://phantomjs.org/download.html
Choose the appropriate binary (Linux x32 x64 / OSX / Windows), download archive, extract it and run the binary.
For example you have a x64 Linux distribution.
Log in to your server via ssh.
Go to your home directory:
cd ~
Download PhantomJS binary:
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
Extract archive:
tar xvf phantomjs-2.1.1-linux-x86_64.tar.bz2
A new directory is created: phantomjs-2.1.1-linux-x86_64. The PhantomJS binary is phantomjs-2.1.1-linux-x86_64/bin/phantomjs. You can run it right now:
~/phantomjs-2.1.1-linux-x86_64/bin/phantomjs --version
2.1.1
(If it says "not found " instead that means you chose the wrong distribution, e.g. x64 instead of x32).
But this way of running it is inconvenient. It would be way better to be able to just type phantomjs script.js in any directory. To make it so add a link to a directory where binaries are kept by default:
sudo ln -s ~/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
Then you can call PhantomJS from anywhere:
cd /var/www/
phantomjs --version
2.1.1

Related

Can I use phantomJS on Azure app service for linux?

I'm getting a consistent error when trying to use the html-pdf package in my node application:
StatusError: Error: spawn /home/site/wwwroot/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs ENOENT
As far as I can tell everything is installed correctly and the npm install works as expected. My suspicion is that there is some missing dependency in the built-in linux image, but I'm not sure how to confirm that.
According to the information comes from the Download PhantomJS page, there is two note for Linux Distributions as below.
Note: For this static build, the binary is self-contained. There is no requirement to install Qt, WebKit, or any other libraries. It however still relies on Fontconfig (the package fontconfig or libfontconfig, depending on the distribution). The system must have GLIBCXX_3.4.9 and GLIBC_2.7.
So the native package fontconfig or libfontconfig must have been installed in docker image first.
For Debian/Ubuntu system, you can add RUN apt install fontconfig in the docker file, and check the package installed whether be exists via the command dpkg -l|grep fontconfig.
For Fedora/CentOS system, add RUN yum install -y fontconfig, and check the installed on via yum list installed|grep fontconfig.

Running CMake on Amazon Linux

I am trying to build OpenJpeg on an AWS Amazon Linux EC2 instance. I installed cmake and gcc and had no issues during installation. When I try to cmake openjpeg I get the following error:
-- Check if the system is big endian
-- Searching 16 bit integer
CMake Error at /usr/share/cmake/Modules/TestBigEndian.cmake:44 (message):
no suitable type found
Call Stack (most recent call first):
CMakeLists.txt:164 (TEST_BIG_ENDIAN)
-- Configuring incomplete, errors occurred!
Checking the error logs it seems CMake is unable to determine the size of integers, shorts and longs. The full error log can be found in this gist
How can I work this out and make CMake work?
Amazon has a guide: Preparing to Compile Software, which proposes the following command to install a C compiler.
sudo yum groupinstall "Development Tools"
Next, you can download and build Cmake yourself: Install Cmake 3.
wget https://cmake.org/files/v3.18/cmake-3.18.0.tar.gz
tar -xvzf cmake-3.18.0.tar.gz
cd cmake-3.18.0
./bootstrap
make
sudo make install
Note: the last make actually needs sudo.
This works in the most recent Amazon Linux image (Nov 2021):
# Install sudo, wget and openssl, which is required for building CMake
yum install sudo wget openssl-devel -y
# Install development tools
sudo yum groupinstall "Development Tools" -y
# Download, build and install cmake
wget https://cmake.org/files/v3.18/cmake-3.18.0.tar.gz
tar -xvzf cmake-3.18.0.tar.gz
cd cmake-3.18.0
./bootstrap
make
sudo make install
Though this does not actually answer why the error was happening but I was able to build OpenJpeg by building CMake from source. So I just removed Cmake which was installed via yum and I believe was 2.8.12. Downloaded the latest CMake3 sources (v 3.10) built Cmake and openjpeg and all my other packages with no issues.
You could try to set up a Docker container to replicate correct environment. This way, you could form a container on your local machine, make sure it all builds on the container environment, and later use this environment on the EC2.
There is a project on Github that provides a Docker image which can be used to compile for Lambda and test stuff locally. Have a look: https://github.com/lambci/docker-lambda

npm install error `not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:`

I have installed Ubuntu Bash on Windows. I already have nodejs and npm on my windows machine at C:\Program Files\nodejs. In the bash shell in Windows, I am running a script which uses npm install command. The script is giving following error
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")
Note: Before following the steps below, first try to restart your shell.
You can install Node.js and NPM with your Windows PowerShell as well, so if you've done that it won't work properly for your Subsystem. That means you have to install it twice (Powershell and Subsystem) or decide on one thing.
If the preceding text, has not helped you, this is how to solve the problem:
Remove your current installations
sudo apt-get --purge remove node
("sudo apt autoremove node" if console is asking for it)
sudo apt-get --purge remove nodejs
Install node the right way.
This is for version 14 (view current LTS version):
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
Then install build tools so you can install add-ons for npm later
sudo apt-get install -y build-essential
Now you can type in
npm -v
node -v
Same thing: nodejs -v
to check whether Node.js and NPM are installed correctly. If it shows nothing, restart the shell.
If it still shows the same error, restart the WSL/ PC or try with sudo npm -v
Here are two links that may also help you.
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
https://github.com/nodesource/distributions/blob/master/README.md#debinstall
Also, take a look at the Node Version Manager (NVM). With it, you can easily switch back and forth between versions.
The solution provided by phucanhapril on May 24, 2017 in this thread worked for me.
To summarise, edit ~/.profile and change your PATH to this:
PATH="$HOME/bin:$HOME/.local/bin:/usr/bin:$PATH"
(By default it does not include /usr/bin)
Then run:
source ~/.profile
I am not quite sure why npm doesn't work properly in the first place, or why /usr/bin isn't in PATH by default, but the solution worked for me.
I had the same problem to solve I installed "NVM" in my Subsystem
Follow these steps and see if it will solve for you:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
bash install_nvm.sh
source ~/.profile
nvm install 11.13.0
You can try sudo npm install it was a solution in my particular case.
Linux command for install nodejs and npm
sudo apt-get install nodejs
sudo apt-get install npm
Set path in linux
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
reference
https://github.com/microsoft/WSL/issues/3882
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
this is enough, if you still face the problem
node installation needs restart, close you ubuntu window and start again it will solve your problem :)
I had the same problem. This is what I did.
Step 1. Type node -v and npm -v commands in Windows PowerShell and check if node and npm are properly installed
Step 2. Add this to the ~/.zshrc or ~/.bashrc file
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Step 3. Type source ~/.zshrc and/or source ~/.bashrc
Step 4. Type node -v and npm -v commands in bash or zsh shells and the correct versions should now appear
On Visual Studio -> Tools -> Options -> Projects and Solutions -> Web Package Management -> make sure $(PATH) is above all the rest.
As long it is not located at the top of the list VS will try to use VS tools instead of npm.
You should also refer windows to the current npm version by following this screenshot, after try npm --version.
Changing npm path:
I had this issue in both Debian and Ubuntu (though in Ubuntu the nvm command did work) when I was running Windows 10 version 1703. Then when I upgraded to version 1903 the problem disappeared.
I had the same error and it may seem silly, but I fixed it by simply typing exit in the console and opening it again.
I received this error when I modified my "~/.bashrc" file to shorten up the bash directory.
At first I had:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u\h:\W\$'
fi
....But then could not run any node operation. I rolled it back and the error stopped happening.
After some troubleshooting, I was able to fix the error by adding ~ before the $ on PS1='${debian_chroot:+($debian_chroot)}\u\h:\W\~$
I just read through many threads trying to do this. There is complete documentation for setting up node, nvm, and npm in wsl, here: https://learn.microsoft.com/en-us/windows/nodejs/setup-on-wsl2
If you already installed node and npm using the following commands,
sudo apt-get install nodejs
sudo apt-get install npm
NPM will not work. You must first uninstall them using:
sudo apt-get remove nodejs
sudo apt-get remove npm
Follow the guide to completely uninstalling here: How can I completely uninstall nodejs, npm and node in Ubuntu
Then reinstall from the windows guide referenced above.
The windows guide has many other useful resources.
The Tldr to install(from Microsoft Docs):
sudo apt-get install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
nvm install --lts
I had identical output to that in the question. It occurs because Ubuntu on WSL adds Windows paths to the bash shell, but of course the Windows executables do not work in bash.
I installed nvm, and from there installed node into bash. NVM works out all the paths so it works.

PhantomJS: getting "Killed: 9" for anything I'm trying

Just installed phantomjs, mac os x yosemite. Whenever I run /bin/phantomjs, with any parameter, I get Killed: 9. Any idea?
Install UPX. UPX is an executable packer and unpacker
$ brew install upx
Unpack the phantomjs executable
$ upx -d phantomjs-2.0.0-macosx/bin/phantomjs
Run the phantomjs executable
$ ./phantomjs-2.0.0-macosx/bin/phantomjs
re: running phantomjs on osx yosemite, download the build/fix found at:
https://github.com/eugene1g/phantomjs/releases
original issue:
https://github.com/ariya/phantomjs/issues/12928
The eugene1g release and UPX install didn't work for me on El Capitan. What did work for me was installing PhantomJS using the phantomjs2 NPM package:
npm install phantomjs2
# Optional: symlink in a dir that's on my PATH:
ln -s /usr/local/lib/node_modules/phantomjs2/lib/phantom/bin/phantomjs /usr/local/bin/phantomjs
$ npm install -g phantomjs worked for me on El Capitan.
The npm package isn't "official", it's maintained by a contributor, but it works. https://github.com/eugene1g/phantomjs
Blunt re-install using brew
Whatever is in /usr/local/bin/phantomjs has stopped working for you.
If you've got ~30mins to spare you can reinstall and relink using brew:
# unlink old version
brew unlink phantomjs
# reinstall phantomjs
brew update && brew install phantomjs
# (You may wish to make a refreshing herbal tea or similar beverage here...)
# Update link to usr/local/bin
brew link --overwrite phantomjs
If you want to test what brew will do with overwrite you can run
brew link --overwrite --dry-run phantomjs
Sometimes this happens when your current shell process is killed.
I was in tmux using brew update, and brew updated tmux and bash, then bang! Everything in tmux just returns Killed: 9.

pecl install gnupg, could not extract the package.xml

I am having problems installing a package with pecl. My system runs Gentoo Linux. It does not accept the package that I am trying to install.
# pecl install gnupg
downloading gnupg-1.3.3.tgz ...
Starting to download gnupg-1.3.3.tgz (19,141 bytes)
......done: 19,141 bytes
could not extract the package.xml file from "/var/tmp/pear/gnupg-1.3.3.tgz"
Download of "pecl/gnupg" succeeded, but it is not a valid package archive
Error: cannot download "pecl/gnupg"
Download failed
install failed
The tarball looks fine and does indeed have a package.xml...
# tar -zxvf /var/tmp/pear/gnupg-1.3.3.tgz
package.xml
gnupg-1.3.3/tests/gnupg_oo_0001_import.phpt
gnupg-1.3.3/tests/gnupg_oo_encrypt.phpt
gnupg-1.3.3/tests/gnupg_oo_encryptsign.phpt
gnupg-1.3.3/tests/gnupg_oo_export.phpt
gnupg-1.3.3/tests/gnupg_oo_keyinfo.phpt
gnupg-1.3.3/tests/gnupg_oo_listsignatures.phpt
gnupg-1.3.3/tests/gnupg_oo_sign_clear.phpt
gnupg-1.3.3/tests/gnupg_oo_sign_detach.phpt
gnupg-1.3.3/tests/gnupg_oo_sign_detach_nonarmor.phpt
gnupg-1.3.3/tests/gnupg_oo_sign_normal.phpt
gnupg-1.3.3/tests/gnupg_oo_sign_normal_noarmor.phpt
gnupg-1.3.3/tests/gnupg_oo_zzz_deletekey.phpt
gnupg-1.3.3/tests/gnupg_res_0001_import.phpt
gnupg-1.3.3/tests/gnupg_res_encrypt.phpt
gnupg-1.3.3/tests/gnupg_res_encryptsign.phpt
gnupg-1.3.3/tests/gnupg_res_export.phpt
gnupg-1.3.3/tests/gnupg_res_keyinfo.phpt
gnupg-1.3.3/tests/gnupg_res_listsignatures.phpt
gnupg-1.3.3/tests/gnupg_res_sign_clear.phpt
gnupg-1.3.3/tests/gnupg_res_sign_detach.phpt
gnupg-1.3.3/tests/gnupg_res_sign_detach_nonarmor.phpt
gnupg-1.3.3/tests/gnupg_res_sign_normal.phpt
gnupg-1.3.3/tests/gnupg_res_sign_normal_noarmor.phpt
gnupg-1.3.3/tests/gnupg_res_zzz_deletekey.phpt
gnupg-1.3.3/tests/vars.inc
gnupg-1.3.3/config.m4
gnupg-1.3.3/EXPERIMENTAL
gnupg-1.3.3/gnupg.c
gnupg-1.3.3/gnupg_keylistiterator.c
gnupg-1.3.3/LICENSE
gnupg-1.3.3/php_gnupg.h
gnupg-1.3.3/php_gnupg_keylistiterator.h
gnupg-1.3.3/README
It would be good if someone could explain this better and help me fix it. Google results were very discouraging. It seems nobody else is having this problem.
I used to use the package in Gentoo portage dev-php/pecl-gnupg but that only supports 5.3. So I need to use pecl from now on to get the module for PHP 5.5. PHP 5.3 is now EOL.
I worked out how to manually install it...
After extracting the package, change to it's directory and run these commands...
phpize
aclocal
libtoolize --force
autoheader
autoconf
./configure
make
sudo make install