<span class="html"> To work on Mac OS X Lion 10.7, I had to change /private/etc/php.ini.default to /private/etc/php.ini</span>
OS X バージョン 10.0.0 以降、PHP は Mac マシンの標準構成として提供されます。デフォルトの Web サーバーで PHP を有効にするには、Apache 設定ファイル httpd.conf 内の設定命令の数行の先頭にあるコメント記号を削除するだけです。CGI または CLI は、デフォルトで使用されます (端末プログラムで簡単に使用できます)。
ローカル PHP 開発環境を迅速に確立するには、次の手順に従ってください。 PHP を最新バージョンにアップグレードすることを強くお勧めします。ほとんどのアクティブなソフトウェアでは、新しいバージョンではバグが修正され、新しい機能が追加されます。これは PHP にも当てはまります。詳細については、該当する Mac OS X インストール マニュアルを参照してください。次の手順では、初心者の観点からデフォルトの動作環境を取得する方法を詳しく説明します。すべてのユーザーが新しいパッケージ バージョンをコンパイルまたはインストールすることをお勧めします。
標準のインストール タイプは mod_php です。Mac OS X の Apache Web サーバー (システム設定からアクセスできるデフォルトの Web サーバー) で PHP を有効にするには、次の手順を実行します。
- Apache 構成ファイルを見つけて開きます。デフォルトでは、この設定ファイルの場所は /private/etc/apache2/httpd.conf です。 Finder または Spotlight を使用してこのファイルを見つけるのは簡単ではない場合があります。デフォルトでは通常、このファイルは root ユーザーによって所有されているためです。プライベートファイル。
注: このファイルを開くには、コマンド ラインから Unix ベースのテキスト エディタ (nano など) を使用できます。これは、このファイルの所有者が であるためです。 root なので、開くには sudo を使用する必要があります (root ユーザー権限で)。たとえば、ターミナル プログラムに次のコマンドを入力します (操作後、パスワードの入力を求められます): sudo nano /private/etc/apache2/httpd.conf nano のコマンドに注目してください: ^w (検索)、^o (保存)、および ^x (終了)。 ^ は Ctrl キーを表します。
注: 古いバージョンの PHP および Apache は、10.5 より前の Mac OS X バージョンにバンドルされています。したがって、古いコンピューターでは、Apache 構成ファイルの場所は /etc/httpd/httpd.conf になる可能性があります。
- テキスト エディタを使用して、次のような行のコメントを解除します (先頭の # を削除します) (これら 2 行は一緒になっていないことが多いため、ファイル内でこれら 2 行を見つける必要があります)。
# LoadModule php5_module libexec/httpd/libphp5.so # AddModule mod_php5.c
- 必要なファイル拡張子が PHP に解決されていることを確認してください (例: .php .html および .inc)。そうでない場合は、正しく動作しません。
httpd.conf (Mac Panther バージョン以降) に書き込まれているため、PHP が有効になると、.php ファイルは自動的に解析されて PHP スクリプトになります。
<ifmodule mod_php5.c><span style="color: #000000;"> # If php is turned on, we respect .php and .phps files. AddType application</span>/x-httpd-<span style="color: #000000;">php .php AddType application</span>/x-httpd-php-<span style="color: #000000;">source .phps # Since most users will want index.php to work we # also automatically enable index.php </span><ifmodule mod_dir.c><span style="color: #000000;"> DirectoryIndex index.html index.php </span></ifmodule> </ifmodule>
Note:
在 OS X 10.5(Leopard)以前版本中,捆绑的是 PHP 4 而不是 PHP 5,因此上面的配置指令稍有不同,需要将 5 更改为 4。
- 确保 DirectoryIndex 加载了所需的默认索引文件。 这个也是在 httpd.conf 中设置的。 通常情况下使用 index.php 和 index.html 。默认情况下 index.php 会被启用,因为在我们上面的配置指令中写明了。根据实际情况可以做相应的调整。
- 设置 php.ini 的位置或者使用默认的位置。 Mac OS X 上通常默认的位置是 /usr/local/php/php.ini ,调用 phpinfo() 也可以得到此信息。如果没有使用 php.ini,PHP 将使用所有的默认值。参见常见问题中的寻找 php.ini。
- 定位或者设置 DocumentRoot。 这是网站所有文件的根目录。此目录中的文件由 web 服务器提供服务,从而使得 PHP 文件将在输出到浏览器之前解析为 PHP 脚本。通常情况下默认的路径是 /Library/WebServer/Documents,但是可以根据需要在 httpd.conf中设置为任何其他目录。另外,用户自己的缺省 DocumentRoot 是 /Users/yourusername/Sites。
- 创建一个 phpinfo() 文件。
phpinfo() 将会显示PHP的相关系统信息。可以在 DocumentRoot 下创建一个 PHP 文件,其代码如下:
<span><?php phpinfo</span><span>(); </span><span>?></span> </span>
- 重启 Apache,然后从浏览器访问上面创建的文件。
要重启Apache,可以在 shell 中执行 sudo apachectl graceful,也可以停止/启动 OS X 系统首选项中的“Personal Web Server”选项。默认情况下,从浏览器访问本地文件的 URL 一般类似于:http://localhost/info.php,或者使用:http://localhost/~yourusername/info.php 来访问用户自己 DocumentRoot 中的文件。
CLI(或者旧版本中的 CGI)一般文件名为 php ,其路径可能是 /usr/bin/php。打开一个终端,参考 PHP 手册中的 PHP 的命令行模式一章,然后执行 php -v 可以检查当前运行的 PHP 的版本。调用 phpinfo() 也会显示相关的信息。
User Contributed Notes 4 notes
8 months ago
5 years ago<span class="html"> You only have to uncomment:<br> #LoadModule php5_module libexec/apache2/libphp5.so<br> <br> This is gone:<br> # AddModule mod_php5.c<br> <br> The statement in 3 was changed to:</span>
<ifmodule mime_module><span style="color: #000000;"> # # TypesConfig points to the </span><span style="color: #0000ff;">file</span><span style="color: #000000;"> containing the list of mappings from # filename extension to MIME</span>-<span style="color: #000000;">type. # TypesConfig </span>/private/etc/apache2/<span style="color: #000000;">mime.types # # AddType allows you to add to or override the MIME configuration # </span><span style="color: #0000ff;">file</span> specified <span style="color: #0000ff;">in</span> TypesConfig <span style="color: #0000ff;">for</span> specific <span style="color: #0000ff;">file</span><span style="color: #000000;"> types. # #AddType application</span>/x-<span style="color: #0000ff;">gzip</span><span style="color: #000000;"> .tgz # # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this. # #AddEncoding x</span>-<span style="color: #000000;">compress .Z #AddEncoding x</span>-<span style="color: #0000ff;">gzip</span><span style="color: #000000;"> .gz .tgz # # If the AddEncoding directives above are commented</span>-out, <span style="color: #0000ff;">then</span><span style="color: #000000;"> you # probably should define those extensions to indicate media types: # AddType application</span>/x-<span style="color: #000000;">compress .Z AddType application</span>/x-<span style="color: #0000ff;">gzip</span><span style="color: #000000;"> .gz .tgz # # AddHandler allows you to map certain </span><span style="color: #0000ff;">file</span> extensions to <span style="color: #800000;">"</span><span style="color: #800000;">handlers</span><span style="color: #800000;">"</span><span style="color: #000000;">: # actions unrelated to filetype. These can be either built into the server # or added with the Action directive (see below) # # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add </span><span style="color: #800000;">"</span><span style="color: #800000;">ExecCGI</span><span style="color: #800000;">"</span> to the <span style="color: #800000;">"</span><span style="color: #800000;">Options</span><span style="color: #800000;">"</span><span style="color: #000000;"> directive.) # #AddHandler cgi</span>-<span style="color: #000000;">script .cgi # For type maps (negotiated resources): #AddHandler type</span>-<span style="color: #000000;">map var # # Filters allow you to process content before it is sent to the client. # # To parse .shtml files </span><span style="color: #0000ff;">for</span> server-<span style="color: #000000;">side includes (SSI): # (You will also need to add </span><span style="color: #800000;">"</span><span style="color: #800000;">Includes</span><span style="color: #800000;">"</span> to the <span style="color: #800000;">"</span><span style="color: #800000;">Options</span><span style="color: #800000;">"</span><span style="color: #000000;"> directive.) # #AddType text</span>/<span style="color: #000000;">html .shtml #AddOutputFilter INCLUDES .shtml </span></ifmodule>
<span class="html"> <br> Extra MIME types can either be added to the file /private/etc/apache2/mime.types or by using an AddType directive as commented on above.</span>
5 years ago<span class="html"> Additionally, it seems that the default installation of php on Mac OS X (10.5 tested) does not point to the default location of the mysql.sock file that is installed in a standard MySQL 5.0 installation.<br> This prevents php working with locally hosted MySQL databases.<br> Adding the following line to the /private/etc/apache2/other/php5.conf file did the trick:<br> php_value mysql.default_socket /tmp/mysql.sock<br> (make sure you put it in between the statements)</span>
5 years ago<span class="html"> I am using MacOSX 10.5.4 and only enabling the mod_php5 wasn't enough to get the PHP support. I had to add following block before I could use php on machine -<br> </span>
<ifmodule mod_php5.c><span style="color: #000000;"> # If php is turned on, we respect .php and .phps files. AddType application</span>/x-httpd-<span style="color: #000000;">php .php AddType application</span>/x-httpd-php-<span style="color: #000000;">source .phps # Since most users will want index.php to work we # also automatically enable index.php </span><ifmodule mod_dir.c><span style="color: #000000;"> DirectoryIndex index.html index.php </span></ifmodule> </ifmodule>

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

ドリームウィーバー CS6
ビジュアル Web 開発ツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません
