在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
I have installed Apache, PHP, and MySQL on Mac OS X since Leopard. Each time doing so by hand. Each version of Mac OS X having some minor difference. This post serves as much for my own record as to outline how to install Apache, MySQL, and PHP for a local development environment on Mac OS X Mountain Lion. I am aware of the several packages available, notably MAMP. These packages help get you started quickly. But they forego the learning experience and, as most developers report, eventually break. Personally, the choice to do it myself has proven invaluable. It is important to remember Mac OS X runs atop UNIX. So all of these technologies install easily on Mac OS X. Furthermore, Apache and PHP are included by default. In the end, you only install MySQL then simply turn everything on. First, open Terminal and switch to
Enable Apache on Mac OS X
Note: Prior to Mountain Lion this was an option for Web Sharing in System Prefrences → Sharing. Verify It works! by accessing http://localhost Enable PHP for ApacheFirst, make a backup of the default Apache configuration. This is good practice and serves as a comparison against future versions of Mac OS X.
Now edit the Apache configuration. Feel free to use TextEdit if you are not familiar with vi.
Uncomment the following line (remove
Restart Apache:
Install MySQL
The README also suggests creating aliases for
Note: You will need to open a new Terminal window or run the command above for your path to update. I also run Connect PHP and MySQLYou need to ensure PHP and MySQL can communicate with one another. There are several options to do so. I do the following:
Creating VirtualHostsYou could stop here. PHP, MySQL, and Apache are all running. However, all of your sites would have URLs like http://localhost/somesite/ pointing to /Library/WebServer/Documents/somesite. Not ideal for a local development environment. To run sites individually you need to enable VirtualHosts. To do so, we’ll edit the Apache Configuration again.
Uncomment the following line:
Now Apache will load httpd-vhosts.conf. Let’s edit this file.
Here is an example of VirtualHosts I’ve created.
The first The second Note: I use the extension local. This avoids conflicts with any real extensions and serves as a reminder I’m in my local environment. Restart Apache:
In order to access http://jason.local, you need to edit your hosts file.
Add the following line to the bottom:
I run the following to clear the local DNS cache:
Now you can access http://jason.local. Note: You will need to create a new A note about permissionsYou may receive 403 Forbidden when you visit your local site. This is likely a permissions issue. Simply put, the Apache user ( If you are not familiar with permissions, read more. For now though, the easiest thing to do is ensure your web directory has permissions of
In my case, all my files were under my local Note: There are many ways to solve permission issues. I have provided this as the easiest solution, not the best. Install PHPMyAdminUnless you want to administer MySQL from the command line, I recommend installing PHPMyAdmin. I won’t go into the details. Read the installation guide for more information. I install utility applications in the default directory. That way I can access them under, in this case, http://localhost/phpmyadmin.
ClosingA local development environment is a mandatory part of the Software Development Process. Given the ease at which you can install Apache, PHP, and MySQL on Mac OS X there really no excuse. - See more at: http://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x/#sthash.TbwD4ABp.dpuf From: http://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x/ |
2022-08-17
2022-11-06
2022-08-17
2022-07-18
2022-07-29
请发表评论