设为首页 收藏本站
查看: 739|回复: 0

[经验分享] Installing Apache, PHP, and MySQL on Mac OS X

[复制链接]

尚未签到

发表于 2015-8-6 09:57:29 | 显示全部楼层 |阅读模式
  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 root to avoid permission issues while running these commands.

sudo su -

Enable Apache on Mac OS X

apachectl start

  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 Apache
  First, make a backup of the default Apache configuration. This is good practice and serves as a comparison against future versions of Mac OS X.

cd /etc/apache2/
cp httpd.conf httpd.conf.bak

  Now edit the Apache configuration. Feel free to use TextEdit if you are not familiar with vi.

vi httpd.conf

  Uncomment the following line (remove #):

LoadModule php5_module libexec/apache2/libphp5.so

  Restart Apache:

apachectl restart

Install MySQL


  • Download the MySQL DMG for Mac OS X
  • Install MySQL
  • Install Preference Pane
  • Open System Preferences → MySQL
  • Ensure the MySQL Server is running
  • Optionally, you can enable MySQL to start automatically. I do.
  The README also suggests creating aliases for mysql and mysqladmin. However there are other commands that are helpful such as mysqldump. Instead, I updated my path to include /usr/local/mysql/bin.

export PATH=/usr/local/mysql/bin:$PATH

  Note: You will need to open a new Terminal window or run the command above for your path to update.
  I also run mysql_secure_install. While this isn’t necessary, it’s good practice.

Connect PHP and MySQL
  You need to ensure PHP and MySQL can communicate with one another. There are several options to do so. I do the following:

cd /var
mkdir mysql
cd mysql
ln -s /tmp/mysql.sock mysql.sock

Creating VirtualHosts
  You 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.

vi /etc/apache2/httpd.conf

  Uncomment the following line:

Include /private/etc/apache2/extra/httpd-vhosts.conf

  Now Apache will load httpd-vhosts.conf. Let’s edit this file.

vi /etc/apache2/extra/httpd-vhosts.conf

  Here is an example of VirtualHosts I’ve created.


DocumentRoot "/Library/WebServer/Documents"


DocumentRoot "/Users/Jason/Documents/workspace/dev"
ServerName jason.local
ErrorLog "/private/var/log/apache2/jason.local-error_log"
CustomLog "/private/var/log/apache2/jason.local-access_log" common

AllowOverride All
Order allow,deny
Allow from all



  The first VirtualHost points to /Library/WebServer/Documents. The first VirtualHost is important as it behaves like the default Apache configuration and used when no others match.
  The second VirtualHost points to my dev workspace and I can access it directly from http://jason.local. For ease of development, I also configured some custom logs.
  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:

apachectl restart

  In order to access http://jason.local, you need to edit your hosts file.

vi /etc/hosts

  Add the following line to the bottom:

127.0.0.1       jason.local

  I run the following to clear the local DNS cache:

dscacheutil -flushcache

  Now you can access http://jason.local.
  Note: You will need to create a new VirtualHost and edit your hosts file each time you make a new local site.

A note about permissions
  You may receive 403 Forbidden when you visit your local site. This is likely a permissions issue. Simply put, the Apache user (_www) needs to have access to read, and sometimes write, your web directory.
  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 755. You can change permissions with the command:

chmod 755 some_directory/

  In my case, all my files were under my local ~/Documents directory. Which by default is only readable by me. So I had to change permissions for my web directory all the way up to ~/Documents to resolve the 403 Forbidden issue.
  Note: There are many ways to solve permission issues. I have provided this as the easiest solution, not the best.

Install PHPMyAdmin
  Unless 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.

cd /Library/WebServer/Documents/
tar -xvf ~/Downloads/phpMyAdmin-3.5.2.2-english.tar.gz
mv phpMyAdmin-3.5.2.2-english/ phpmyadmin
cd phpmyadmin
mv config.sample.inc.php config.inc.php

Closing
  A 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/

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-94638-1-1.html 上篇帖子: apache + tomcat + oracle + opencms 备忘 下篇帖子: [Apache Spark源码阅读]天堂之门——SparkContext解析
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表