Home >Operation and Maintenance >Apache >How to configure apache and php on mac

How to configure apache and php on mac

王林
王林forward
2020-04-14 09:56:354729browse

How to configure apache and php on mac

In the Mac environment, the Apache (Apache server) and PHP that come with the system are pre-installed. Let’s gradually operate the merger of Apache and PHP:

Step one: Check the pre-installed versions of Apache and PHP on the system

(1)打开终端,输入命令:sudo apachectl -version

How to configure apache and php on mac

(2)输入命令:sudo php -v

How to configure apache and php on mac

(Recommended tutorial: apache tutorial)

Step 2: Modify the Apache configuration file

(1) 前往Finder,(一般快捷键为:command+shift+G),输入地址:/private/etc/apache2

How to configure apache and php on mac

(2)找到名为 httpd.conf 的文件,选择TextEdit打开.
    (因为此文件为locked不允许被修改.所以,我们可以将其复制到桌面上,修改后将原文件删掉,再将修改后的文件移到原文件的位置)

How to configure apache and php on mac

(3)打开后使用搜索关键字“php” (一般快捷键为command+F),搜索结果如图所示:

How to configure apache and php on mac

(4)删除这行文本最前面的那个“#”号,删除后保存一下,关闭文档,用其替换原文档

How to configure apache and php on mac

##Step 3: Generate PHP configuration file

(1)前往Finder,(一般快捷键为:command+shift+G),输入地址:/private/etc   只需到etc目录下,在这个目录下找到一个名为 php.ini.default 的文件. 将这个文件复制一下,仍然拷贝到当前目录下,然后将新拷贝的文件重命名为 php.ini,注意:只改文件名,内容不需要修改.修改后,如图所示:

How to configure apache and php on mac

Step 4: Restart the Apache service

(1)打开终端,输入命令: sudo apachectl restart

(Open at this time

http://localhost: The web page will display it works!)

Step 5: Test and run the PHP file

(1)前往Finder,(一般快捷键为:command+shift+G),输入地址:/Library/WebServer(需要强调的是这个文件夹是服务器的根路径文件夹,默认情况下我们是没有读写权限的,所以我们需开启读写权限,这样也方便以后的开发工具对这里的文件进行读写。)具体操作步骤见图:

Display introduction:


How to configure apache and php on mac

Click the small lock in the lower right corner->Enter password

How to configure apache and php on mac

(2) 在 Documents 文件夹下(再次强调这就是服务器的根路径!)创建一个名为 index.php 的文件(名字随便起,为了测试),在里面写如下php的代码,保存一下:
<?php
    
  phpinfo();
    
?>

How to configure apache and php on mac

(3)打开浏览器访问我们刚才创建的文件,在地址栏输入:http://localhost/index.php, 如图所示,则成功:

How to configure apache and php on mac

Complete!

Recommended related video tutorials:

php video tutorial

The above is the detailed content of How to configure apache and php on mac. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete