


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!

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.

Fibers was introduced in PHP8.1, improving concurrent processing capabilities. 1) Fibers is a lightweight concurrency model similar to coroutines. 2) They allow developers to manually control the execution flow of tasks and are suitable for handling I/O-intensive tasks. 3) Using Fibers can write more efficient and responsive code.

The PHP community provides rich resources and support to help developers grow. 1) Resources include official documentation, tutorials, blogs and open source projects such as Laravel and Symfony. 2) Support can be obtained through StackOverflow, Reddit and Slack channels. 3) Development trends can be learned by following RFC. 4) Integration into the community can be achieved through active participation, contribution to code and learning sharing.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools

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.

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.