Setting XAMPP PHP as Global PHP in Linux

Set Global PHP in Linux

To configure the PHP provided by XAMPP as the default global PHP in your Linux system, you need to adjust the PATH environment variable. Here are the steps to achieve this:

1. Determine XAMPP Installation Location

First, make sure you know the location where XAMPP is installed on your computer. For instance, if XAMPP is installed in the directory /opt/lampp, then the PHP executable in XAMPP would be located at /opt/lampp/bin/php.

2. Edit Shell Configuration File

To make this change, you will edit your shell configuration file, typically .bashrc for Bash or .zshrc for Zsh, depending on the shell you use.

a. Open the .bashrc File

Open the .bashrc file using a text editor like Nano or Vim. Run the following command in your terminal:

bashCopy codenano ~/.bashrc

b. Add Path to XAMPP PHP

Add the following line at the end of the .bashrc file (or .zshrc if you use Zsh):

bashCopy codeexport PATH="/opt/lampp/bin:$PATH"

Replace /opt/lampp/bin with the actual installation path of XAMPP on your computer if it differs.

c. Save and Close the Editor

After adding the line, save the changes by pressing Ctrl + O, then press Enter to confirm. Exit the text editor by pressing Ctrl + X.

d. Reload Shell Configuration

To apply the changes, reload the modified shell configuration file by running the following command in your terminal:

bashCopy codesource ~/.bashrc

3. Verify the Installation

After completing the above steps, verify that the changes have taken effect:

  • Check PHP Version:Run the command php -v to check the PHP version currently in use:bashCopy codephp -v The output should display the PHP version from XAMPP that you have installed.
  • Run Artisan Serve:Now you should be able to run php artisan serve without any issues, as the php command will now refer to the PHP from XAMPP by default:bashCopy codephp artisan serve

Additional Notes

  • Ensure that you verify the XAMPP installation location on your computer and adjust the PATH added in step 2b accordingly.
  • If you are using a different shell such as Zsh, adjust the instructions to edit the appropriate shell configuration file (e.g., .zshrc for Zsh).

By following these steps, you have successfully set up PHP from XAMPP as the default global PHP used in your Linux system. This allows you to conveniently use PHP in various development projects.

Scroll to Top