search
HomeBackend DevelopmentPHP ProblemHow to install php on macos 10.14

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version