Home  >  Article  >  Backend Development  >  How to install php on macos 10.14

How to install php on macos 10.14

PHPz
PHPzOriginal
2023-04-24 14:47:05712browse

With the release of macOS 10.14 Mojave, many developers, system administrators, and network administrators are starting to upgrade their systems for better performance and security. However, some problems arose during this process, such as installing older versions of software on new systems.

In this article, we will discuss the steps to install PHP in macOS 10.14 Mojave. PHP is a popular scripting language used for web development and data processing. Using the version of PHP that comes with macOS 10.14 Mojave can cause some issues, so we'll cover a better way to install PHP.

Preparation

Before installing PHP, we need to make some preparations. First, we need to determine whether your system has pre-installed some development tools and library files, which are necessary to compile PHP in macOS.

If the necessary tools and library files are missing, you need to install them by executing the following command in the terminal:

xcode-select --install

The installation process may take some time, depending on your network speed and system performance. Later enter this command in the terminal, if you have installed the required development tools and library files, it will display a prompt telling you that the installation is complete.

Installing Homebrew

Homebrew is a command line tool that helps you install and manage various software packages on macOS. If you don't have Homebrew installed yet, we recommend you install it first.

Open a terminal and enter the following command to install Homebrew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Please note that this command will get the installer from Homebrew’s official website and copy it to your system. The installation process may take several minutes, depending on your network speed and system performance.

Install PHP

Now we can install PHP. Homebrew provides a package called php which can be installed with a simple command.

To install PHP, open a terminal and enter the following command:

brew install php@7.2

This will install PHP 7.2 version, you can choose a different version according to your needs. The installation process may take some time, depending on your network speed and system performance.

Set PATH

To ensure that you can find PHP commands in the terminal, you need to add PHP to the PATH environment variable. The PATH environment variable tells the shell which path to search for executable files.

To add PHP to your PATH, open a terminal and enter the following command:

echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile

Note that this command adds the PHP path to the current user's .bash_profile file. If you are using zsh, you need to replace .bash_profile with .zshrc in the command.

Restart the terminal or execute the following command for the changes to take effect:

source ~/.bash_profile

Testing PHP

Now, you have successfully installed PHP. We can test that it works by creating a simple PHP file.

Create a file called index.php in your preferred editor and add the following code:

<?php
phpinfo();
?>

Save the file to your web server, such as /Library/WebServer /Documents/ directory. You can use your existing Apache HTTP server or other common web servers.

Enter localhost/index.php in your browser, you should see a page containing PHP information, which proves that your PHP has been successfully installed and running.

If any errors occur, check the log file for more information. Normally, errors will appear at the end of the Apache error log file.

Summary

Installing PHP in macOS 10.14 Mojave is not a difficult task. With Homebrew, we can easily install the latest version of PHP. And we can also choose different versions according to our needs. Once the installation is complete, you need to add PHP to the PATH environment variable, and then you can test and run your PHP program.

The above is the detailed content of How to install php on macos 10.14. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn