在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!的页面
运行PHP1、找到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信息的页面,如图所示。
1、在http://dev.mysql.com/downloads/mysql/网站上,选择Mac OS X平台,然后选择图中的下载,我开始下载错了,安装出错,后来下载图中的版本安装成功
双击dmg文件
双击第一个安装,然后双击第三个安装,然后双击第二个,第二个是配置文件,安装之后,可以在系统偏好设置中选择启动或者关闭MySql。
2、修改密码
在终端输入,这里修改密码为12345,也可为其他,自定义即可
/usr/local/mysql/bin/mysqladmin -u root password 12345
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工程,否则,是无法运行的(某大神指示,本人尚未亲自验证)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.
