No output when trying to use nodejs - php

I installed node on my Ubuntu 14.04 machine with:
apt-get install node
However, when I run
node -v
there is no output.
I then tried apt-get install nodejs, and when I run nodejs -v I get v0.10.25.
I'm not really sure what I'm doing wrong to get node working.
My PHP script requires node.js and my check keeps failing:
if(preg_match("/^v\d+.\d+.\d+$/", `node -v`) === 0){
exit_json([
"error" => "Node isn't installed on this machine."
]);
}
How can I correctly install node.js on 14.04? I used digital ocean's tutorial.

If you are using Node.js as a developer in you developing machine I advise you to install it using NVM.
Follow the instructions than add the following to your ~/.bashrc file:
source ~/.nvm/nvm.sh
After type
$source ~/.bashrc
This will allow you to use NVM to install the versions you want:
$nvm install 10
You can install older versions and use whatever one you have installed by typing:
$nvm use 8.4.0

If you want to execute it, make sure you're specifying the full path (or make sure node is in the path.)
Also, that's a very, very old version of Node.js you've installed.

Try install like this :
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

Related

Docker-compose : prevent PECL install from stopping the build process

So I have 2 Dockerfile to build my container. The first file is to build my "main" (production) container, the second extends the first (through From instruction) and adds some dev and testing dependencies.
Currently, my only testing dependency is Xdebug. I install it through PECL with : RUN pecl install xdebug && docker-php-ext-enable xdebug
When I rebuild my image, it seems that it doesn't rebuild everything from scratch so I get the error pecl/xdebug is already installed and is the same as the released version 2.9.8 install failed ERROR: Service 'webapi' failed to build : The command '/bin/sh -c pecl install xdebug && docker-php-ext-enable xdebug' returned a non-zero code: 1
So, ok, it fails, but I still end with Xdebug installed so my image will work just fine. But it stops the build. I don't want to.
I've seen the RUN command; exit 0 trick but, as mentionned by somebody, it will silence any real error (like "Sorry, server unreachable, can't download Xdebug") so to me it's not a viable option for production.
Also Xdebug isn't available on apt-get nor through docker-php-ext-install. I'm stuck with PECL.
Do you know any option (like some hidden param) to do something like "Install if you can, otherwise just like it roll" ?
Regards,
You can check if Xdebug is installed or not first:
bash -c '[[ -z "$(pecl list | grep xdebug)" ]] && (pecl install xdebug && docker-php-ext-enable xdebug)'
But honestly 'it doesn't rebuild everything from scratch' sounds quite weird in the first place and you probably should debug your Dockerfile.
Put this in your Dockerfile when you want to install XDebug:
RUN bash -c '[[ -n "$(pecl list | grep xdebug)" ]]\
|| (pecl install xdebug && docker-php-ext-enable xdebug)'
This will check the pecl installed packages list for 'xdebug' before attempting an install.
If grep returns anything for that, we know it's already installed and the statement evaluates to success.
If grep doesn't return anything, it'll go ahead and execute the commands to install xdebug, and fail if it's unable to install it.

How do I uninstall a PHP module?

I bumped into this bit of instructions while installing an addon for a PHP framework:
Make sure you don't have the PHP module installed. This is a Debian/Ubuntu example:
sudo apt-get purge php5-geoip
I am working on Windows PC with a Virtual Machine running Laravel Homsetead. I am using Git Bash command window. When I enter the above command I get:
bash: sudo: command not found
If I remember correctly, sudo is an Apple-related command so I tried dropping it like this:
apt-get purge php5-geoip
but I get
bash: apt-get: command not found
What command do I need to use to purge php5-geoip?
EDIT: echo $PATH gives out:
$ echo $PATH
/c/Users/Arthur/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/
bin:/c/Users/Arthur/bin:/c/ProgramData/Oracle/Java/javapath:/c/Windows/system32:
/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/
c/Program Files (x86)/Intel/OpenCL SDK/2.0/bin/x86:/c/Program Files (x86)/Intel/
OpenCL SDK/2.0/bin/x64:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c
/Program Files/MATLAB/MATLAB Production Server/R2015a/runtime/win64:/c/Program F
iles/MATLAB/MATLAB Production Server/R2015a/bin:/c/Program Files/MATLAB/MATLAB P
roduction Server/R2015a/polyspace/bin:/c/Program Files (x86)/Skype/Phone:/c/PHP:
/c/ProgramData/ComposerSetup/bin:/c/Users/Arthur/AppData/Roaming/Composer/vendor
/bin:/c/HashiCorp/Vagrant/bin:/c/Program Files/nodejs:/c/Users/Arthur/AppData/Ro
aming/npm:/usr/bin/vendor_perl:/usr/bin/core_perl

How to use blob in codeigniter?

I'm new to PHP. How I can use blob in CodeIgniter? What is the best option for sending an image from the server to a client (RESTful) using codeigniter?
I have tried the following:
$newPerson = new Person();
$newPerson->id = 1;
$newPerson->firstName = "Qutfullo";
$newPerson->lastName = "Ochilov";
$image=new Imagick();
$image->setImage("my.jpg");
$newPerson->image=$image->getImageBlob();
$this->response($newPerson);
But I get an exception:
Fatal error: Class 'Imagick' not found.
Thanks for help!
Hope below snippet can give you the idea that you are missing library --
Try below code if on ubuntu --
php -m | grep imagick.
If the result is empty then issue below commands from terminal
sudo apt-get remove --purge php5-imagick && sudo apt-get install php5-imagick
if on window sserver follow below link instructions that might be useful
Install Imagick for PHP and Apache on Windows
The error is because of your server have no Image Magic Software suite. First you install it in your server.
For install Image Magic in Unix/Linux
Download ImageMagick.tar.gz from www.imagemagick.org
Unpack the distribution with this command:
tar xvzf ImageMagick.tar.gz
Next configure and compile ImageMagick:
cd ImageMagick-6.9.3
./configure
make
To install, type
sudo make install
You may need to configure the dynamic linker run-time bindings:
sudo ldconfig /usr/local/lib
Install from Windows Source
Download ImageMagick-windows.zip from www.imagemagick.org
Unzip and Install
unzip ImageMagick-windows.zip
Please refer this link for installation.
If you are developing a RESTFull API, The best way is to send the image URL as the response.

Run php file via command line on an ubuntu linux server

I am trying to run a php file on a ubuntu linux server but get a 'command not found' error when i run "php file_name.php"
Searching online, i found an article that suggested I run "sudo aptitude install php5-cli" which I did and restarted apache afterwards but I still get this error.
How do I fix this?
Try this once,
Go to terminal.
whereis php
It will show where is php installed.
Export that path to environment variable using following command
export PATH=$PATH;/path/to/php's/bin directory
Then execute required file..
As follows,
php file_to_execute.php
first make sure that you've installed following packs:
php5
php5-cli
php-pear
like this:
sudo apt-get install php5 php5-cli php-pear
then make sure to configure php safely befor using it.
also make your php file executable ( chmod 700 )
Try the following step :
Open your cmd/console or press ctr+alt+t.
php5 /your/path/to/php_file_name.

How do I install Pdftk on my server?

I am using a Linux Server and am trying to install Pdftk, but I am problems trying to figure out what exactly to do.
I found the following documentation on how to install it, but they refer mostly to installing it on the local Windows machine.
They are:
http://www.andrewheiss.com/blog/2009/07/29/installing-pdftk-php/
http://www.accesspdf.com/pdftk/#packages
Can someone help me unserstand exactly what files I need to place where on my server so I can refer to pdftk?
Pdftk is a version of iText which has been converted from Java to c++ and rebuilt with a command-line bridge for easy access from PHP applications.
To build pdftk on Redhat / CentOS please follow the below instructions.
ssh [server to install pdftk on]
Now that we are in the server we need to create the directories to store pdftk.
cd /
sudo mkdir extra
cd extra
sudo mkdir src
cd src
sudo wget http://www.pdfhacks.com/pdftk/pdftk-1.41.tar.gz
sudo tar zxvf pdftk-1.41.tar.gz
cd pdftk-1.41/pdftk
Now we need to install the gcj libraries.
sudo yum install java-1.4.2-gcj-compat-devel.i386
The gcc-c++ library doesn't get installed with the gcj package so we will install it now, so we don't get an error halfway through the compile process.
sudo yum install gcc-c++
If you compile the application right now you will receive a warning that tmpnam is dangerous to use and you should use mkstemp.
sudo vi report.cc
Run this from inside VI to do a search and replace for the tmpnam method.
:%s/tmpnam(/mkstemp(/g
Press escape and save the changes with
:wq!
Now that we have all the packages installed, we are going to start compiling pdftk-1.41
from /extra/src/pdftk-1.41/pdftk run the following command
sudo make -f Makefile.RedHat
This will kick off the build process for compiling and converting the java file to c++. This could take SEVERAL minutes to convert iText to c++. Go grab yourself a margarita from our new margarita machine in the break room :).
Now with the pdftk file created we will want to copy it to the /bin directory so that we can run it from anywhere.
sudo cp pdftk /usr/local/bin
Let's make sure the build was successful and run
pdftk --version
As of 2020, things are different now. CentOS 6 is stepping out and pdftk can only support CentOS 5/6. GCJ on CentOS 7 is removed, so installing from source is not easy too. But we have docker now:
FROM centos:centos6
RUN yum install -y https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk-2.02-1.el6.x86_64.rpm
Then build with docker build . -t pdftk and run as:
docker run -it --rm -v $PWD:/data --workdir /data pdftk pdftk ./input.pdf output ./output.pdf
The example above can repair a pdf file missing a dozen of KB of data if you are lucky.
As mentioned by #rsc, pdftk-java will be available for Rocky Linux, but currently (2021.10.28), still cannot install it via yum.
Fortunately, there is a built command for x86_64 GNU/Linux systems, which does not require any runtime dependencies. So we can use it as follows
# the version number might be updated, check https://gitlab.com/pdftk-java/pdftk
wget https://gitlab.com/pdftk-java/pdftk/-/jobs/1527259632/artifacts/raw/build/native-image/pdftk
chmod +x pdftk
./pdftk ...
It works well in the server with the following system info,
$ lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: Rocky
Description: Rocky Linux release 8.4 (Green Obsidian)
Release: 8.4
Codename: GreenObsidian
As of 2021, there is pdftk-java: A port of the original GCJ-based PDFtk to Java, which is currently on the way to the repositories for Fedora 33+ and EPEL 7+ (latter for CentOS, RHEL or Rocky), allowing yum install pdftk-java to succeed (once the package reached the stable repositories).
Edit: The pdftk-java package is in the stable repositories since yesterday, 2021-10-29.

Categories