


Detailed explanation of how to install PHP environment on Apple system
How to install the PHP environment on the Apple system: first install iTerm2 and PhpStorm; then install Xcode; then install PHP7.4 through the command "brew install php"; finally install mysql and start the service.
Recommended: "PHP Video Tutorial"
On October 8, 2019, Apple officially released a new generation of macOS, The version is Catalina (11.15).
macOS Catalina comes pre-installed with common scripting languages such as Ruby (2.6.3), PHP (7.3.9), Perl (5.18.4), Python (2.7.16), and Apache (2.4.41 ) web server.
It should be noted that in the new version, zsh has replaced bash as the default shell in the new operating system.
The following is the installation process of my MNMP (macOS-nginx-MySQL-PHP).
This tutorial uses three substitutions:
- Use iTerm2 instead of the system’s own command line terminal
- Use nginx instead of the system’s own The Apache
- that comes with it uses the self-installed PHP7.4 instead of the PHP7.3.9 that comes with the system
InstallationiTerm2
Recommend iTerm2. iTerm2 is powerful and can replace the system's default command line terminal. After downloading and unzipping, drag iTerm2 directly into the "Applications" directory.
Install PhpStorm
Recommended JetBrains PhpStorm as an integrated development tool.
Installing Xcode
Xcode is a development kit produced by Apple that contains a series of tools and libraries. Install the latest version of Xcode (9.0) via the AppStore. We generally don't use Xcode to develop back-end projects. But this step is also must, because Xcode will install some necessary software such as Git.
Install Command Line Tools for Xcode
This step will help you install many common Unix-based tools. The Xcode command line tools, as part of Xcode, include the GCC compiler. Execute the following command in the command line to install:
xcode-select --install # 安装 Xcode Command Line Tools
When Xcode and Xcode Command Line Tools are installed, you need to start Xcode, click to agree to accept the license agreement, and then close Xcode. This step is also must, otherwise a series of development tools included in Xcode will not be available.
Install Homebrew
Homebrew As an indispensable package manager for macOS, it is used to install, upgrade and uninstall commonly used software. Execute the following command on the command line to install:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # 使用系统自带的 ruby 安装 Homebrew
After installation, you can modify the Homebrew source. Foreign sources have not been very powerful. Here we will change Homebrew's git remote warehouse to University of Science and Technology of China Open Source Software image :
cd "$(brew --repo)" git remote set-url origin https://mirrors.ustc.edu.cn/brew.git # 替换brew.git: cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git # 替换homebrew-core.git: echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc # 替换Homebrew Bottles源: source ~/.zshrc
Install PHP 7.4
Install PHP7.4.* to replace the PHP7.3 that comes with the system:
brew install php
Start the php service:
brew services start php
Replace the php-fpm that comes with the system:
echo 'export PATH="/usr/local/opt/php/sbin:$PATH"' >> ~/.zshrc source ~/.zshrc
View version information:
php -v php-fpm -v
Install MySQL
Recommend MySQL 8.0 as the database server:
brew install mysql
Of course, you can also choose to install PostgreSQL or MariaDB.
After the installation is completed, start MySQL:
brew services start mysql
Enter the MySQL server:
mysql -u root -p
Set the root password, security level and other parameters:
mysql_secure_installation
Follow the step-by-step prompts Just do it step by step.
Install Redis
Install redis server:
brew install redis
After the installation is complete, start Redis:
brew services start redis
Use redis client:
redis-cli
Install nginx
Here we choose nginx instead of the Apache that comes with the system as our Web server:
brew install nginx
Start the nginx service:
brew services start nginx
View the installed brew services :
brew services list
Configure the nginx.conf file
You can view the location of the nginx.conf file through the following command:
nginx -h
Output:
nginx version: nginx/1.17.3 Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -T : test configuration, dump it and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/Cellar/nginx/1.17.3_1/) -c filename : set configuration file (default: /usr/local/etc/nginx/nginx.conf) -g directives : set global directives out of configuration file
Open the configuration file :
vi /usr/local/etc/nginx/nginx.conf
You can see at the end of the file:
include servers/*;
It includes all the files in the servers directory in the same directory. From this, we can create development projects in the servers file Configuration information:
cd /usr/local/etc/nginx/servers/ vi test.conf
Write the following configuration information into the test.conf file:
server { listen 8099; server_name localhost; root /home/www/php-project; rewrite . /index.php; location / { index index.php index.html index.htm; autoindex on; } #proxy the php scripts to php-fpm location ~ \.php$ { include /usr/local/etc/nginx/fastcgi.conf; fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9000; } }
In the above directory of /home/www/php-project
Next, we create an index.php file:
vim /home/www/php-project/index.php
Write the content:
<?php phpinfo();
Restart nginx:
brew services restart nginx
打开浏览器,访问http://localhost:8099
,即可访问到关于 PHP 配置的信息。
安装 Composer
Composer 是 PHP 用来管理依赖(dependency)关系的工具。你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer 会帮你安装这些依赖的库文件。
安装并替换镜像:
curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ # 改为阿里云的国内源
安装 PHP 扩展
以 php-redis 扩展为例,有下载源码包来进行安装或者 pecl install 安装:
wget https://pecl.php.net/get/redis-5.1.0.tgz # 下载源码包 tar -zxvf redis-5.1.0.tgz # 解压 cd redis-5.1.0 # 进入目录 phpize # 生成编译配置 ./configure # 编译配置检测 make # 编译 make install # 安装
扩展安装完成后,我们还需最后一步,修改php.ini
文件,并重启 PHP 服务:
vi /usr/local/etc/php/7.4/php.ini # 追加 extension=redis.so brew services restart php # 重启 php 服务 php -m |grep redis # 查看是否安装成功
或者使用 pecl 安装:
pecl install redis
The above is the detailed content of Detailed explanation of how to install PHP environment on Apple system. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to install the PHP environment locally: 1. Download and install Apache; 2. Download the PHP compressed package on the official website and extract it to the specified directory; 3. Download and install mysql; 4. Open the "Environment Variables" interface and configure the path variable of mysql ; 5. Open the php.ini file and modify the configuration; 6. Open the httpd.conf file and add support for PHP and the PHP installation path at the end of the file; 7. Start the Apache service.

With the continuous advancement of technology, smartphones have become one of the essential items in our daily lives. Among smartphones, Apple’s mobile phone system is highly praised. However, sometimes we may need to downgrade the Apple system, which may be to solve some software compatibility issues, or to roll back to a more stable system version. This article will provide you with a simple and easy tutorial for downgrading the Apple system. First of all, be sure to back up your mobile phone data before downgrading the system. The downgrade process may lead to the risk of data loss, so before starting

Do I need to jailbreak to downgrade the Apple system? With the continuous development of technology, smartphones have become an indispensable tool in people’s lives. As one of the most popular smartphones, Apple mobile phones are highly sought after by users for their stable operating system and smooth user experience. However, sometimes users may want to downgrade their phone system back to an older version for some reasons. So the question is, does downgrading the Apple system require a jailbreak? First, we need to clarify what jailbreaking is. Jailbreaking refers to bypassing Apple's restrictions on iPhone and other devices so that users can

Many friends who have used U disks have encountered the embarrassing situation that they cannot be read. It is obviously a good U disk, but why can't it be read when it is plugged into the computer? what is going on? Is there any way to solve this? First, rule out whether the USB flash drive is damaged. You can try inserting the USB flash drive into another computer to check whether it can be read. If it can be read, the USB flash drive may be hidden on your computer. At this time, insert the USB flash drive into the computer, open [My Computer]-[View]-[Options]; under the [Options] interface, select [View], and in "Files and Folders" under "Advanced Settings" , uncheck "Hide empty drives" and click [Apply]. In addition, when the USB flash drive is used, in addition to being unable to read, there may also be data loss, etc.

How to switch between Apple system and Windows system? Many Apple computers now have two systems installed, one Apple system and one Windows system. So how to switch between Apple system and Windows system? Let me share with you the method of switching between Apple system and Windows system. 1. First, on the computer desktop, we need to select System Preferences and find the startup disk option in the system column. 2. After entering the interface, find the startup disk option in the system column. After clicking it, a dialog box will pop up. Select in it. Windows disk, click Restart to enter the Windows system. Summary: Select System Preferences, find the Startup Disk option in the system column, and select Windows in it.

As an open source operating system, LINUX is highly customizable and flexible and has become the preferred server operating system for many enterprises and individuals. CentOS, as a distribution of LINUX, is widely used in the server field. Installing on CentOS DebHelper and PHP environments are a common task, and this article will give you a detailed look at how to accomplish both. debhelper is a toolset on the Debian operating system that is used to simplify the building and installation process of software packages. Although CentOS is not based on Debian, sometimes we also need to use debhelper on CentOS. Here is how to install debhelp on CentOS

In Excel on Apple systems, if you want to wrap lines within cells, you can follow the steps below. After opening the Excel file and selecting the cells that need to be wrapped, we can use the shortcut key Option+Enter to achieve line wrapping. You can also use the following method to operate. The first step is to select the cells that need to be wrapped. In Excel, we can click on the cell with the mouse or use the arrow keys on the keyboard to select the cell that needs to be operated. The second step is to enter the editing mode

The PHP environment is one of the important basic environments for developing websites and applications. Correct installation, configuration and debugging of the PHP environment is crucial for developers. Various problems are often encountered during the installation process. This article will provide you with a PHP environment installation guide, solve common problems in detail and provide specific code examples. Ensure the system environment Before installing PHP, first ensure that the system environment meets the minimum requirements for PHP. Generally speaking, PHP supports mainstream operating systems such as Windows, Linux, and Mac, but
