1.首先是选择需要的PHP,这里边我自己下载了一个PHP。PHP@7.4版本,不是Mac自带的PHP。 1.PHP下载方法以及可能遇到的问题。 1.1首先下载brew,brew是下载神器。 1.2 如果之前电脑装了brew确保可用。 1.2.1先检查一下brew是否可用。
brew docter
根据提示信息修复brew
(我下载时遇到的很多问题都和xcode有关,确保xcode不要过时,一般就能下载下来需要的东西。) 1.2.2选择需要下载的版本
brew search php #检查所有的php版本
1.2.3下载需要的php(我现在的是7.4)
brew install php@7.4
1.2.4下载完之后有许多友好的提示,可以根据提示配置apache和php的关系。
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php@7.4/lib/httpd/modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/7.4/
php@7.4 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have php@7.4 first in your PATH, run:
echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc
For compilers to find php@7.4 you may need to set:
export LDFLAGS="-L/usr/local/opt/php@7.4/lib"
export CPPFLAGS="-I/usr/local/opt/php@7.4/include"
To start php@7.4:
brew services start php@7.4
Or, if you don't want/need a background service you can just run:
/usr/local/opt/php@7.4/sbin/php-fpm --nodaemonize
1.3需要配置其他如不同的项目。 这里我们配置了一个YII项目。 1.3.1首先下载好YII项目模板(Composer或者压缩包) 1.3.2将项目放到一个自己选择的文件夹。这里我是放在了phpStorm的项目文件夹下。(/Users/username/PhpstormProjects) 1.3.3将项目引向apache 首先配置apache的httpd.conf文件。 将#Include /private/etc/apache2/extra/httpd-vhosts.conf的注释取消,包含在内。 1.3.4去 /private/etc/apache2/extra/httpd-vhosts.conf中添加项目包含项。 <VirtualHost *:80> ServerAdmin A DocumentRoot “/Users/username/PhpstormProjects/basic/” ServerName localhost
1.3.5测试:localhost/web/index.php
|