How do I add the php and mysql commands to environment variables on linux CentOS systems

  • 2020-05-13 04:17:19
  • OfStack

How do I add the php and mysql commands to an environment variable on an linux CentOS system

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, the command will be prompted with errors that do not exist. 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 each time you log out or log out of the system, the PATH Settings will be 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, and add 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 execute the point command./profile to make its modification effective. After execution, you can check if the addition was successful through the echo $PATH command.

Tips: 5 ways to find files under Linux

(find is the most common and powerful search command you can use to find any file you want.) The locate (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 the 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.) The whereis (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 wok (which) command searches for the location of a system command in the path specified by the PATH variable and returns the first search result. In other words, using the which command, you can see whether a system command exists and which command is being executed. The type command (type) is not really a lookup command. It is used to distinguish whether a command is provided by shell or by a separate binary file outside of shell. If a command is external, the -p argument shows 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: