Run php file via command line on an ubuntu linux server - php

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.

Related

No output when trying to use nodejs

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

Solr Solarium and Curl throwing an error

I recently installed Solarium (with Java 8 on Ubuntu 14.04, PHP 5.5).
I created a core called test :
$ sudo -u solr /opt/solr-6.5.1/bin/solr create -c test
Then I indexed in it the "techproducts" example :
$ bin/post -c test example/exampledocs/*.xml
So I then tried to execute a PHP file given as an example with Solarium. In SSH I do :
$ php 1.2-basic-select.php
And it works, it shows the content indexed.
But, when I open this same PHP file with a browser, I've got an error :
Fatal error: Uncaught exception 'Solarium\Exception\RuntimeException' with message 'cURL is not available, install it to use the CurlHttp adapter' in /var/www/html/cvrecruteur.com/slr/vendor/solarium/solarium/library/Solarium/Core/Client/Adapter/Curl.php:228
Curl and php-curl are installed and up to date so I don't really know what's the deal here.
try to install PHP5 CURL by typing sudo apt-get install php5-curl
If you're really sure that php5-cur are installed, try to restart your apache instance.

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

composer not working in cygwin terminal

when i run the following command in cygwin terminal
$ php -r "readfile('https://getcomposer.org/installer');" | php
!/usr/bin/env php
Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:
The json extension is missing.
Install it or recompile php without --disable-json
The phar extension is missing.
Install it or recompile php without --disable-phar
The ctype extension is missing.
Install it or recompile php without --disable-ctype
above error facing , how to solve it, more i have already install xampp, composer_setup.exe , but i want to run composer with cygwin terminal. how to run it ?
A bit too late, but you can try to:
Copy composer.phar to cygwin/usr/bin
Create a new composer.bat file with:
#ECHO OFF
php "%~dp0composer.phar" %*
Then restart cygwin and retry
Additionaly, this can help:
Cygwin/Gitbash + composer = unknown command

how to run php -v from terminal when using php-fpm

I have Nginx installed with PHP-FPM and I cant figure out how to run php -v into terminal it says that i need to install php5-cli. How else can I run php from terminal? I am using ubuntu. I just need php from terminal to run a cron
You need to find out if the PHP installation folder is in your PATH. You can check by doing "echo $PATH". if you don't find the PHP install folder there then that's probably the problem

Categories