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

一、启动Apache

有两种方法

1、打开网络共享

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

2、打开终端,输入

?
1
sudo apachectl start
这时需要输入密码,输入电脑密码即可,然后输入

?
1
sudo apachectl -v
可以查看到Apache的版本信息
?
1
2
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,在终端输入


?
1
sudo apachectl restart
PHP就可以用了。
3、在终端输入

?
1
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,也可为其他,自定义即可


?
1
/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,修改其中的


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

?
1
$cfg['Servers']]$i]['host'] = '127.0.0.1';
即可,如果想要无密码登陆,则将其中的下面语句中的false改成true

?
1
$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
What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

How do you optimize PHP applications for performance?How do you optimize PHP applications for performance?May 08, 2025 am 12:08 AM

TooptimizePHPapplicationsforperformance,usecaching,databaseoptimization,opcodecaching,andserverconfiguration.1)ImplementcachingwithAPCutoreducedatafetchtimes.2)Optimizedatabasesbyindexing,balancingreadandwriteoperations.3)EnableOPcachetoavoidrecompil

What is dependency injection in PHP?What is dependency injection in PHP?May 07, 2025 pm 03:09 PM

DependencyinjectioninPHPisadesignpatternthatenhancesflexibility,testability,andmaintainabilitybyprovidingexternaldependenciestoclasses.Itallowsforloosecoupling,easiertestingthroughmocking,andmodulardesign,butrequirescarefulstructuringtoavoidover-inje

Best PHP Performance Optimization TechniquesBest PHP Performance Optimization TechniquesMay 07, 2025 pm 03:05 PM

PHP performance optimization can be achieved through the following steps: 1) use require_once or include_once on the top of the script to reduce the number of file loads; 2) use preprocessing statements and batch processing to reduce the number of database queries; 3) configure OPcache for opcode cache; 4) enable and configure PHP-FPM optimization process management; 5) use CDN to distribute static resources; 6) use Xdebug or Blackfire for code performance analysis; 7) select efficient data structures such as arrays; 8) write modular code for optimization execution.

PHP Performance Optimization: Using Opcode CachingPHP Performance Optimization: Using Opcode CachingMay 07, 2025 pm 02:49 PM

OpcodecachingsignificantlyimprovesPHPperformancebycachingcompiledcode,reducingserverloadandresponsetimes.1)ItstorescompiledPHPcodeinmemory,bypassingparsingandcompiling.2)UseOPcachebysettingparametersinphp.ini,likememoryconsumptionandscriptlimits.3)Ad

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

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.