PHP未在Macos Monterey上运行12.4

发布于 2025-02-04 05:34:47 字数 742 浏览 5 评论 0原文

我最近从Linux/Ubuntu切换到Mac。我在Macos Monterey 12.4上使用Homebrew安装了Apache2和Php 8,该Macos Pro(M1)预先安装。我已经成功配置了apache,并且可以访问本地主机,它运行得很好。我什至将文档的根源从其默认位置更改为我的自定义位置(在我的主目录中) 成功安装Apache后,我安装了PHP。我通过

isthakur@Inders-MacBook-Pro apache2 % php -v
PHP 8.1.6 (cli) (built: May 12 2022 23:30:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies

在以下位置安装以下命令php来验证这一点/opt/opt/homebrew/bin/php 但是我无法在浏览器上输出输出,我在文档root上创建了一个PHP文件,并使用以下代码创建了一个test.php,

<?php
phpinfo();
?>

当我尝试通过浏览器(http://localhost/test.php)打开此文件时, 请将其命名为test.php。显示在浏览器上,这意味着服务器未处理PHP。 欢迎任何帮助,我感谢所有人的期待。 问候

I recently switched from Linux/Ubuntu to Mac. I Installed Apache2 and PHP 8 using homebrew on my MacOS Monterey 12.4 which came preinstalled with my MacBook Pro (M1). I have successfully configured the Apache and it is working perfectly as I am able to access my localhost. I have even changed the document root from its default location to my customized location (in my home directory)
After Successfully installing apache I installed php. I verified this by running the following commands

isthakur@Inders-MacBook-Pro apache2 % php -v
PHP 8.1.6 (cli) (built: May 12 2022 23:30:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies

PHP is installed on following location /opt/homebrew/bin/php
but I am unable to get output on browser I have created a php file on my document root with following codes and named it test.php

<?php
phpinfo();
?>

When I try to open this file through browser (http://localhost/test.php) the codes are displayed on browser which means that server is not processing PHP.
Any kind of help is welcome and I thank everyone in anticipation.
Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦醒时光 2025-02-11 05:34:47

在网上阅读了博客和响应后,我发现MacOS预先安装了Apache,甚至PHP也已在MacOS Monterey(12)之前预先安装,因此我重置Mac,发现Apache已预装了安装,我只需要使用以下命令来运行它
sudo apachectl start
我可以访问Apache。由于没有安装PHP,因此我需要使用自制酿酒厂安装它。安装PHP后,我看到我需要如下修改https.conf文件。

To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

    <FilesMatch \.php
gt;
        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:
    /opt/homebrew/etc/php/8.1/

To restart php after an upgrade:
  brew services restart php
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/php/sbin/php-fpm --nodaemonize

after reading blogs and responses online I found that MacOS comes preinstalled with apache and even php was pre installed prior to MacOS Monterey (12) So I reset my Mac and found that apache is preinstalled and I just need to run it using following command
sudo apachectl start
and I can access apache. Since PHP was not installed I need to install it using homebrew. after installing the php I saw that I need to modify my https.conf file as following.

To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

    <FilesMatch \.php
gt;
        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:
    /opt/homebrew/etc/php/8.1/

To restart php after an upgrade:
  brew services restart php
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/php/sbin/php-fpm --nodaemonize
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文