在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工程,否则,是无法运行的(某大神指示,本人尚未亲自验证)

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











There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

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.

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

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.
