search
HomeBackend DevelopmentPHP Tutorial在Mac下配置php开发环境:Apache+php+MySql

启动Apache

有两种方法

1、打开网络共享

打开”系统偏好设置”->”共享”,在”互联网共享”那一项前面打√。

2、打开终端,输入

sudo apachectl start

这时需要输入密码,输入电脑密码即可,然后输入

sudo apachectl -v

可以查看到Apache的版本信息

Server version: Apache/2.2.24 (Unix)Server built:   Jul  7 2013 18:05:17

此时在浏览器中输入http://localhost,会出现It works!的页面

运行PHP

1、找到Apache的配置文件,在目录/etc/apache2/下,打开Finder,选择”前往”-“前往文件夹”,输入”/etc/apache2/”,找到其中的”httpd.conf”文件,选择用文稿打开进行编辑,点按Command+F,搜索#LoadModule php5_module libexec/apache2/libphp5.so,如图

把蓝色那一行的#号去掉,然后保存,如果出现文本锁定,无法解锁的情况,解决办法有两种

a)选中该文件,右击后选择”显示简介”,点击右下角的小锁的图标,输入电脑密码解锁,然后选择左边的+号键,选择自己当前电脑登陆的用户,将权限设置为读与写,如果还是不行,将其上一级文件夹权限同样再修改一次。

b)将该文件复制到桌面,进行修改,修改后再复制到原来的文件夹替换之前的文件即可。
2、重启Apache,在终端输入

sudo apachectl restart

3、在终端输入

sudo cp /Library/WebServer/Documents/index.html.en /Library/WebServer/Documents/info.php

即在Apache的根目录下复制index.html.en文件并重命名为info.php。

4、打开info.php,在It works后面加上,然后再次重启Apache,在浏览器中输入http://localhost/info.php,会出现一个显示php信息的页面,如图所示。

配置MySql

1、在http://dev.mysql.com/downloads/mysql/网站上,选择Mac OS X平台,然后选择图中的下载,我开始下载错了,安装出错,后来下载图中的版本安装成功

双击dmg文件

双击第一个安装,然后双击第三个安装,然后双击第二个,第二个是配置文件,安装之后,可以在系统偏好设置中选择启动或者关闭MySql。

2、修改密码

在终端输入,这里修改密码为12345,也可为其他,自定义即可

/usr/local/mysql/bin/mysqladmin -u root password 12345
使用phpMyAdmin

phpMyAdmin是用PHP开发的管理MySql的程序,非常实用

1、下载phpMyAdmin,在网址http://www.phpmyadmin.net/home_page/downloads.php中选择合适的版本下载,我选择的是phpMyAdmin-4.0.8-All-Languages.tar.bz2

2、将下载好的文件解压后,放进/Library/WebServer/Documents/文件夹中,并命名为phpmyadmin。

3、复制/Library/WebServer/Documents/phpmyadmin中的config.sample.inc.php,并命名为config.inc.php,并放在当前文件夹下。

4、编辑config.inc.php,修改其中的

$cfg['Servers']]$i]['host'] = 'localhost';

$cfg['Servers']]$i]['host'] = '127.0.0.1';

即可,如果想要无密码登陆,则将其中的下面语句中的false改成true

$cfg['Servers'][$i]['AllowNoPassword'] = false

5、在浏览器中输入 http://localhost/phpmyadmin,输入用户名”root”,和刚刚自己所更改的密码,如果未更改密码,则按照上一步骤中的无密码操作,然后就可以直接登陆了。

PS:到此配置完成,进行php开发还需下载一个php开发工具,mac下的php开发工具也挺多,大家自行谷歌百度,需要提醒的是,安装好开发工具之后,在建议php工程时,记得要将工程放在和phpmyadmin同一个目录文件下,可新建一个文件夹专门用来存放php工程,否则,是无法运行的(某大神指示,本人尚未亲自验证)

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

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 Article

Hot 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.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software