mac 上安装php扩展
Many website owners use PHP with their websites to expand the capabilities of the sites. Before you can enable PHP on a Mac, you first have to enable Apache. Both PHP and Apache are free open source software programs and both come installed on all Macs. PHP is server-side software, and Apache is the most widely used web server software. Enabling Apache and PHP on a Mac isn't difficult to do.
许多网站所有者在其网站上使用PHP来扩展网站的功能。 在Mac上启用PHP之前,首先必须启用Apache。 PHP和Apache都是免费的开源软件程序,并且都安装在所有Mac上。 PHP是服务器端软件,而Apache是使用最广泛的Web服务器软件。 在Mac上启用Apache和PHP并不困难。
在MacOS上启用Apache ( Enable Apache on MacOS )
To enable Apache, open the app, which is located in the Mac's Applications > Utilities folder. You need to switch to the root user in Terminal so you can run commands without any permission issues. To switch to the root user and start Apache, enter the following code into Terminal.
要启用Apache,请打开该应用程序,该应用程序位于Mac的“应用程序”>“实用程序”文件夹中。 您需要在终端中切换到root用户,以便您可以运行命令而没有任何权限问题。 要切换到root用户并启动Apache,请在Terminal中输入以下代码。
sudo su -
苏多苏-
apachectl start
apachectl开始
That's it. If you want to test if it worked, enter http://localhost/ in a browser, and you should see the standard Apache test page.
而已。 如果要测试它是否有效,请在浏览器中输入http:// localhost /,然后应该会看到标准的Apache测试页面。
为Apache启用PHP ( Enabling PHP for Apache )
Make a backup of the current Apache configuration before you begin. This is a good practice as the configuration may change with future upgrades. Do this by entering the following in Terminal:
开始之前,请备份当前的Apache配置。 这是一个好习惯,因为配置可能会随着将来的升级而更改。 为此,请在终端中输入以下内容:
cd /etc/apache2/
cd / etc / apache2 /
cp httpd.conf httpd.conf.sierra
cp httpd.conf httpd.conf.sierra
Next, edit the Apache configuration with:
接下来,使用以下命令编辑Apache配置:
vi httpd.conf
vi httpd.conf
Uncomment the next line (remove #):
取消注释下一行(删除#):
LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php5_module libexec / apache2 / libphp5.so
Then, restart Apache:
然后,重新启动Apache:
apachectl restart
apachectl重新启动
Note: When Apache is running, its identity is sometimes "httpd," which is short for "HTTP daemon." This example code assumes a PHP 5 version and MacOS Sierra. As the versions are upgraded, the code must change to accommodate new information.
注意:当Apache运行时,其标识有时是“ httpd”,这是“ HTTP守护程序”的缩写。 此示例代码假定使用PHP 5版本和MacOS Sierra。 随着版本的升级,代码必须更改以容纳新信息。
确认已启用PHP ( Verify That PHP Is Enabled )
To verify that PHP is enabled, create a phpinfo() page in your DocumentRoot. In MacOS Sierra, the default DocumentRoot is located in /Library/WebServer/Documents. Verify this from the Apache configuration:
要验证是否已启用PHP,请在DocumentRoot中创建一个phpinfo()页面 。 在MacOS Sierra中,默认的DocumentRoot位于/ Library / WebServer / Documents中。 从Apache配置中验证这一点:
grep DocumentRoot httpd.conf
grep DocumentRoot httpd.conf
Create the phpinfo() page in your DocumentRoot:
在DocumentRoot中创建phpinfo()页面:
echo '<?php phpinfo();' > /Library/WebServer/Documents/phpinfo.php
回声'<?php phpinfo();' > /Library/WebServer/Documents/phpinfo.php
Now open a browser and enter http://localhost/phpinfo.php to verify that PHP is enabled for Apache.
现在打开浏览器,然后输入http://localhost/phpinfo.php以验证是否已为Apache启用PHP。
其他Apache命令 ( Additional Apache Commands )
You've already learned how to start Apache in Terminal mode with apachectl start. Here are a few more command lines you might need. They should be executed as the root user in Terminal. If not, prefix them with .
您已经学习了如何使用apachectl start在终端模式下启动Apache。 这里是您可能需要的一些其他命令行。 它们应在终端中以root用户身份执行。 如果不是,请给它们加上前缀。
Stop Apache
停止Apache
apachectl stop
apachectl停止
Graceful Stop
优雅的停止
apachectl graceful-stop
apacheectl优雅停止
Restart Apache
重新启动Apache
apachectl restart
apachectl重新启动
Graceful Restart
优雅重启
apachectl graceful
优美的
To find the Apache version
查找Apache版本
httpd -v
httpd -v
Note: A "graceful" start, restart or stop prevents an abrupt halt to proceedings and allows ongoing processes to complete.
注意:“优美”的启动,重新启动或停止可防止程序突然停止,并允许正在进行的过程完成。
翻译自: https://www.thoughtco.com/how-to-install-php-on-a-mac-2694012
mac 上安装php扩展