Bash: php: command not found

Bash: php: command not found

If you see the error "Bash: php: command not found" when trying to run the php command on your system, it means that the PHP command line interface (CLI) is not installed on your system or is not added to your system's PATH environment variable.

To fix this error, you can try the following steps:

  1. Check if PHP is installed on your system by running the php --version command. If you see a message with the PHP version, it means that PHP is installed on your system but is not added to your PATH environment variable. PHP is not installed on your system if you don't see any output or an error message.

  2. If PHP is not installed on your system, you can install it by following the instructions on the PHP website or using your system's package manager. For example, on Ubuntu, you can use the following commands to install PHP:

sudo apt update
sudo apt install php
  1. If PHP is installed on your system, but it is not added to your PATH environment variable, you can add it to your PATH by modifying your ~/.bashrc or ~/.bash_profile file and adding the following lines to the end of the file:

export PATH=$PATH:/path/to/php/bin

where /path/to/php/bin is the path to the directory where the php executable is located. This directory is usually /usr/bin or /usr/local/bin.

  1. After modifying your ~/.bashrc or ~/.bash_profile file, run the source command to reload the file and update your PATH environment variable:

source ~/.bashrc
  1. Try rerunning the php command and see if the error message disappears. If you still see the error message, you may need to log out of your system and log back in for the changes to take effect.

Bash: php: command not found for Mac os users

If you are using a Mac, installing and configuring PHP on your system may be slightly different from the steps described above. However, the overall process should be similar.

To install PHP on a Mac, you can use the built-in package manager called Homebrew. First, you will need to install Homebrew by following the instructions on the Homebrew website. Once Homebrew is installed, you can use the following commands to install PHP:

brew update
brew install php

After installing PHP, you must add it to your PATH environment variable to run the php command from the terminal. To do this, open your ~/.bash_profile file in a text editor and add the following line to the end of the file:

export PATH=$PATH:/usr/local/bin

Save the file and run the source command to reload your ~/.bash_profile file and update your PATH environment variable:

source ~/.bash_profile

You should now be able to run the php command from the terminal.

Useful links:

PHP

Bash

Stay up to date

Get notified when I publish New Games or articles, and unsubscribe at any time.

Thanks for joining!

FAQs

What is PHP?

PHP (Hypertext Preprocessor) is a popular programming language for web development. It is a server-side language, meaning the PHP code is executed on the server, and the results are sent to the user's web browser. PHP is often used with a database system, such as MySQL, to create dynamic, data-driven websites.

One of the key features of PHP is its simplicity. It is a relatively easy language to learn and use, and it has a large, active community of users and developers who contribute to its development and support. PHP is also well-suited for web development, with many built-in functions and libraries make it easy to interact with HTML, CSS, and other web technologies.

In addition to its use in web development, PHP is also commonly used for command-line scripting, and it has a command-line interface (CLI) that can be used to run PHP scripts and programs from the terminal.

Related articles

Ruslan Osipov
Author: Ruslan Osipov