search
HomeOperation and MaintenanceApacheHow to configure apache and php on mac

How to configure apache and php on mac

Apr 14, 2020 am 09:56 AM
apachemacphp

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. If there is any infringement, please contact admin@php.cn delete
Apache's Role: Serving HTML, CSS, JavaScript, and MoreApache's Role: Serving HTML, CSS, JavaScript, and MoreApr 19, 2025 am 12:09 AM

Apache can serve HTML, CSS, JavaScript and other files. 1) Configure the virtual host and document root directory, 2) receive, process and return requests, 3) use .htaccess files to implement URL rewrite, 4) debug by checking permissions, viewing logs and testing configurations, 5) enable cache, compressing files, and adjusting KeepAlive settings to optimize performance.

What Apache is Known For: Key Features and AchievementsWhat Apache is Known For: Key Features and AchievementsApr 18, 2025 am 12:03 AM

ApacheHTTPServer has become a leader in the field of web servers for its modular design, high scalability, security and performance optimization. 1. Modular design supports various protocols and functions by loading different modules. 2. Highly scalable to adapt to the needs of small to large applications. 3. Security protects the website through mod_security and multiple authentication mechanisms. 4. Performance optimization improves loading speed through data compression and caching.

The Enduring Relevance of Apache: Examining Its Current StatusThe Enduring Relevance of Apache: Examining Its Current StatusApr 17, 2025 am 12:06 AM

ApacheHTTPServer remains important in modern web environments because of its stability, scalability and rich ecosystem. 1) Stability and reliability make it suitable for high availability environments. 2) A wide ecosystem provides rich modules and extensions. 3) Easy to configure and manage, and can be quickly started even for beginners.

Apache's Popularity: Reasons for Its SuccessApache's Popularity: Reasons for Its SuccessApr 16, 2025 am 12:05 AM

The reasons for Apache's success include: 1) strong open source community support, 2) flexibility and scalability, 3) stability and reliability, and 4) a wide range of application scenarios. Through community technical support and sharing, Apache provides flexible modular design and configuration options, ensuring its adaptability and stability under a variety of needs, and is widely used in different scenarios from personal blogs to large corporate websites.

Apache's Legacy: What Made It Famous?Apache's Legacy: What Made It Famous?Apr 15, 2025 am 12:19 AM

Apachebecamefamousduetoitsopen-sourcenature,modulardesign,andstrongcommunitysupport.1)Itsopen-sourcemodelandpermissiveApacheLicenseencouragedwidespreadadoption.2)Themodulararchitectureallowedforextensivecustomizationandadaptability.3)Avibrantcommunit

The Advantages of Apache: Performance and FlexibilityThe Advantages of Apache: Performance and FlexibilityApr 14, 2025 am 12:08 AM

Apache's performance and flexibility make it stand out in a web server. 1) Performance advantages are reflected in efficient processing and scalability, which are implemented through multi-process and multi-threaded models. 2) Flexibility stems from the flexibility of modular design and configuration, allowing modules to be loaded and server behavior adjusted according to requirements.

What to do if the apache80 port is occupiedWhat to do if the apache80 port is occupiedApr 13, 2025 pm 01:24 PM

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

How to solve the problem that apache cannot be startedHow to solve the problem that apache cannot be startedApr 13, 2025 pm 01:21 PM

Apache cannot start because the following reasons may be: Configuration file syntax error. Conflict with other application ports. Permissions issue. Out of memory. Process deadlock. Daemon failure. SELinux permissions issues. Firewall problem. Software conflict.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Atom editor mac version download

Atom editor mac version download

The most popular open source editor