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:

<ul><li>php5</li> <li>php5-cli</li> <li>php-pear</li> </ul>

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 )


<ul><li>Try the following step :</li> <li>Open your cmd/console or press ctr+alt+t.</li> <li>php5 /your/path/to/php_file_name.</li> </ul>


  • Is there any Debian repository to download the most recent version of Eclipse?
  • kali linux vmware gcc not found error
  • Having trouble with setup.py
  • What's the quickest and easiest way of getting libpng available for development in VisualStudio
  • TFS Build notification options not populating build definitions
  • Laravel routes overwriting phpmyadmin path with nginx
  • How to reduce the time delay to reach run method of Runnable class using ExecutorService Java
  • Laravel routes not found on nginx
  • new spark.sql.shuffle.partitions value not used after checkpointing
  • Is need install mysql on AWS EC2 if i am using AWS rds as database instance?
  • Restart app on force kill
  • Deploying pre-encrypted configuration files to a production environment
  • Instanciate service on startup in Angular2
  • How do I configure Maven Cargo to use an embedded Tomcat server?
  • PHP in userdir not working
  • get passwords from chrome
  • UML diagram generator in Visual Studio 2010
  • File extension of zlib zipped html page?
  • iOS Cordova first plugin - plugin.xml to inject a feature
  • opencv display image without x server
  • OSX - always hide certain files
  • Compiling dlib on OS X
  • How to generate and display a QR Code in ionic 2
  • How do I configure context broker accept post requests from my remote sensor?
  • Problem deserializing objects from cache on MyBatis 3/Java
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • Cannot connect to cassandra from Spark
  • Bug in WPF DataGrid
  • TFS: Get latest causes slow project reloading
  • script to move all files from one location to another location
  • Javascript Callbacks with Object constructor
  • ILMerge & Keep Assembly Name
  • Can I make an Android app that runs a web view in Chrome 39?
  • Updated Ionic CLI but shows previous version (Windows)
  • Symfony2: How to get request parameter
  • How to make Safari send if-modified-since header?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Observable and ngFor in Angular 2