The linux CentOS system php and mysql commands are added to the environment variables

  • 2020-05-14 05:46:46
  • OfStack

After installing php and MySQL on Linux CentOS system, it is necessary to add php and mysql commands to the system commands for ease of use. If the "php-v" command is executed to view the information of the current php version before adding it to the environment variables, it will prompt the command with no error. Let's take a closer look at how to add php and mysql to environment variables under linux (assuming php, mysql and apache are installed in /phpstudy/server/php/, /phpstudy/server/mysql/ and /phpstudy/server/php/, respectively).

Method 1:

Direct run command


export PATH=$PATH:/phpstudy/server/php/bin  and  export PATH=$PATH:/phpstudy/server/mysql/bin  and  export PATH=$PATH:/phpstudy/mysql/bin

With this approach, the PATH Settings are only valid for the current session, which means that every time you log out or log out of the system, the PATH Settings are invalidated, only temporarily.

Method 2:

Perform vi ~ /. bash_profile modify PATH1 line in the file, will/phpstudy/server/php/bin and/phpstudy server/mysql/bin and/phpstudy mysql/bin joining PATH = PATH: HOME/bin1 line

This method only works for the currently logged in user

Method 3:

Modify the /etc/profile file to permanently take effect for all system users, adding the following two lines of code at the end of the file:


PATH=$PATH:/phpstudy/server/php/bin:/phpstudy/server/mysql/bin:/phpstudy/mysql/bin
export PATH

Finally: execute the command source /etc/profile or the point command./profile to effect the change.

Small methods: 5 ways to find files under Linux

(find is the most common and powerful search command, you can use it to find any file you want.)

The locate command is actually another way of writing "find-name", but it is much faster than the latter because instead of searching a specific directory, it searches a database (/var/lib/locatedb) that contains information about all files locally. The Linux system automatically creates this database and updates it once a day, so the most recently changed files cannot be checked using the locate command. To avoid this, you can manually update the database using the updatedb command before using locate.)

3.whereis copyright (the whereis command can only be used for program name searches, and only for base 2 files (parameter-b), man specification files (parameter-m), and source code files (parameter-s). If parameters are omitted, all information is returned.

The which command (which) searches for the location of a system command in the path specified by the PATH variable and returns the first search result. That is, using the which command, you can see if a system command exists and which command is being executed.

The type, or type, command is not actually a lookup command. It is used to distinguish whether a command is provided by shell or by a separate binary file external to shell. If a command is external, the -p argument displays the path to the command, which is equivalent to the which command.

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: