在 Mac OS 10.6 (Snow Leopard)、10.7 (Lion)、10.8 (Mountain Lion) 上激活 PHP 和 MySQL 的最简单方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1293484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 01:54:56  来源:igfitidea点击:

Easiest way to activate PHP and MySQL on Mac OS 10.6 (Snow Leopard), 10.7 (Lion), 10.8 (Mountain Lion)?

phpmysqlmacososx-snow-leopardosx-lion

提问by Matt Sephton

What is the easiest way to activate PHP and MySQL on Mac OS 10.6 (Snow Leopard), 10.7 (Lion), 10.8 (Mountain Lion)?

在 Mac OS 10.6 (Snow Leopard)、10.7 (Lion)、10.8 (Mountain Lion) 上激活 PHP 和 MySQL 的最简单方法是什么?

I'd prefer to use any bundled versions before resorting to downloading from the PHP or MySQL websites. That also rules out MAMP and similar.

在求助于从 PHP 或 MySQL 网站下载之前,我更喜欢使用任何捆绑版本。这也排除了 MAMP 和类似的情况。

I'm comfortable at the command line in Terminal.

我对终端中的命令行很满意。

回答by TWLATL

Open a good text editor (I'd recommend TextMate, but the free TextWrangler or vi or nano will do too), and open:

打开一个好的文本编辑器(我推荐 TextMate,但免费的 TextWrangler 或 vi 或 nano 也可以),然后打开:

/etc/apache2/httpd.conf

Find the line:

找到这一行:

"#LoadModule php5_module        libexec/apache2/libphp5.so"

And uncomment it (remove the #).

并取消注释(删除 #)。

Download and install the latest MySQL version from mysql.com. Choose the x86_64 version for Intel (unless your Intel Mac is the original Macbook Pro or Macbook, which are not 64 bit chips. In those cases, use the 32 bit x86 version).

从 mysql.com 下载并安装最新的 MySQL 版本。为 Intel 选择 x86_64 版本(除非您的 Intel Mac 是原始 Macbook Pro 或 Macbook,它们不是 64 位芯片。在这些情况下,请使用 32 位 x86 版本)。

Install all the MySQL components. Using the pref pane, start MySQL.

安装所有 MySQL 组件。使用首选项窗格,启动 MySQL。

In the Sharing System Pref, turn on (or if it was already on, turn off/on) Web Sharing.

在“共享系统偏好设置”中,打开(或者如果它已经打开,则关闭/打开)Web 共享。

You should now have Apache/PHP/MySQL running.

您现在应该运行 Apache/PHP/MySQL。

In 10.4 and 10.5 it was necessary to modify the php.ini file to point to the correct location of mysql.sock. There are reports that this is fixed in 10.6, but that doesn't appear to be the case for all of us, given some of the comments below.

在 10.4 和 10.5 中,需要修改 php.ini 文件以指向 mysql.sock 的正确位置。有报道称,这已在 10.6 中修复,但鉴于下面的一些评论,我们所有人似乎都不是这种情况。

回答by mdskinner

To complete your setup or MySQL:

要完成您的设置或 MySQL:

sudo vim /etc/profile
  1. Add alias

    alias mysql=/usr/local/mysql/bin/mysql
    alias mysqladmin=/usr/local/mysql/bin/mysqladmin
    
  2. Then set your root password

    mysqladmin -u root password 'yourPassword'
    
  3. Then you can login with

    mysql -u root -p
    
  1. 添加别名

    alias mysql=/usr/local/mysql/bin/mysql
    alias mysqladmin=/usr/local/mysql/bin/mysqladmin
    
  2. 然后设置你的root密码

    mysqladmin -u root password 'yourPassword'
    
  3. 然后你可以登录

    mysql -u root -p
    

回答by asdf1

It's an invisible folder. Just hit Command+ Shift+ G(takes you to the Go to Folder menu item) and type /etc/.

这是一个看不见的文件夹。只需点击Command+ Shift+ G(带您进入 Go to Folder 菜单项)并输入/etc/.

Then it will take you to inside that folder.

然后它会带你到那个文件夹里面。

回答by Duke

I strongly prefer HomeBrewover MacPorts for installing software from source.

我非常喜欢HomeBrew 而不是 MacPorts 从源代码安装软件。

HomeBrew sequesters everything in /usr/local/Cellar so it doesn't spew files all over the place. (Yes, MacPorts keeps everything in /opt/local, but it requires sudo access, and I don't trust MacPorts with root.)

HomeBrew 将所有内容隔离在 /usr/local/Cellar 中,因此它不会将文件散布到所有地方。(是的,MacPorts 将所有内容都保存在 /opt/local 中,但它需要 sudo 访问权限,而且我不信任具有 root 权限的 MacPorts。)

Installing MySQL is as simple as:

安装 MySQL 非常简单:

brew install mysql
mysql_install_db

To start mysql, in Terminal type:

要启动 mysql,请在终端中键入:

mysqld&

There's a way to start it upon boot, but I like to start it manually.

有一种在启动时启动它的方法,但我喜欢手动启动它。

回答by workdreamer

This help me a lot:

这对我有很大帮助:

http://maestric.com/doc/mac/apache_php_mysql_snow_leopard

http://maestric.com/doc/mac/apache_php_mysql_snow_leopard

It also works for Mac OS X Lion :D

它也适用于 Mac OS X Lion :D

.:EDIT:. On my case the prefepane only allows to start and stop mysql, but after some issues i've uninstalled him. If you need a application to run queries and create DB, you could use: Sequel Pro (it's free) or Navicat

。:编辑:。在我的情况下,prefepane 只允许启动和停止 mysql,但在一些问题之后我卸载了他。如果你需要一个应用程序来运行查询和创建数据库,你可以使用:Sequel Pro(它是免费的)或 Navicat

If you need start and stop mysql in ~/.bash_profile you can add these lines:

如果您需要在 ~/.bash_profile 中启动和停止 mysql,您可以添加以下几行:

#For MySQL
alias mysql_start="/Library/StartupItems/MySQLCOM/MySQLCOM start"
alias mysql_stop="/Library/StartupItems/MySQLCOM/MySQLCOM stop"

After reloaded the console just call:

重新加载控制台后只需调用:

$mysql_start 

or

或者

$mysql_stop 

agreding the desired action. Hope helped you.

同意所需的操作。希望对你有帮助。

回答by simonrjones

I would agree with Benjamin, either install MAMP or MacPorts (http://www.macports.org/). Keeping your PHP install separate is simpler and avoids messing up the core PHP install if you make any mistakes!

我会同意 Benjamin 的观点,要么安装 MAMP 要么安装 MacPorts(http://www.macports.org/)。将您的 PHP 安装分开更简单,并且可以避免在您犯任何错误时弄乱核心 PHP 安装!

MacPorts is a bit better for installing other software, such as ImageMagick. See a full list of available ports at http://www.macports.org/ports.php

MacPorts 更适合安装其他软件,例如 ImageMagick。在http://www.macports.org/ports.php查看可用端口的完整列表

MAMP just really does PHP, Apache and MySQL so any future PHP modules you want will need to be manually enabled. It is incredibly easy to use though.

MAMP 确实支持 PHP、Apache 和 MySQL,因此您将来需要的任何 PHP 模块都需要手动启用。虽然它非常容易使用。

回答by machuga

Considering it hasn't been released yet, I'm assuming this is a question for ahead-of-time or you have a developer's build. As Benjamin mentioned, MAMP is the easiest way. However, if you want a native install, the process should be like 10.5. PHP comes installed on OS X by default (not always activated for some), just download the 32-bit version of MySQL, start Apache, and you should be good to go. You may have to tweak Apache for PHP or MySQL, depending on what builds are present. I didn't have to tweak anything to have it working.

考虑到它还没有发布,我假设这是一个提前的问题,或者你有一个开发人员的构建。正如本杰明所说,MAMP 是最简单的方法。但是,如果您想要本机安装,则该过程应该类似于 10.5。PHP 默认安装在 OS X 上(某些情况下并不总是激活),只需下载 32 位版本的 MySQL,启动 Apache,就可以了。您可能需要针对 PHP 或 MySQL 调整 Apache,具体取决于存在的构建版本。我不需要调整任何东西就可以让它工作。

回答by Matt Sephton

If you've upgraded to Mac OS X 10.8 Mountain Lion, and previously had a working system, all you should need to do is re-enable PHP as in Step 1 of the above chosen answer.

如果您已升级到 Mac OS X 10.8 Mountain Lion,并且之前有一个可运行的系统,您需要做的就是重新启用 PHP,如上述所选答案的步骤 1 中所述。

You may also find the following Preference Pane useful for managing "web sharing" (Apache web server), which replaces system functionality removed in OS X 10.8: http://clickontyler.com/blog/2012/02/web-sharing-mountain-lion/

您可能还会发现以下首选项窗格对管理“网络共享”(Apache 网络服务器)很有用,它取代了 OS X 10.8 中删除的系统功能:http: //clickontyler.com/blog/2012/02/web-sharing-mountain -狮子/

I also had to re-add my virtual hosts include line to the httpd.conf

我还必须将我的虚拟主机包含行重新添加到 httpd.conf

回答by Daniel Lopez

In addition to the native versions, but you may want to try BitNami MAMP Stacks (disclaimer, I am one of the developers). They are completely free, all-in-one bundles of Apache, MySQL, PHP and a several other third-party libraries and utilities that are useful when developing locally. In particular, they are completely self-contained so you can have several one installed at the same time, with different versions of Apache and MySQL and they will not interfere with each other. You can get them from http://bitnami.org/stack/mampstackor directly from the Mac OS X app store https://itunes.apple.com/app/mamp-stack/id571310406

除了本机版本,您可能还想尝试 BitNami MAMP Stacks(免责声明,我是开发人员之一)。它们是 Apache、MySQL、PHP 和其他几个在本地开发时有用的第三方库和实用程序的完全免费的多合一捆绑包。特别是,它们是完全独立的,因此您可以同时安装多个,使用不同版本的 Apache 和 MySQL,它们不会相互干扰。您可以从http://bitnami.org/stack/mampstack或直接从 Mac OS X 应用商店https://itunes.apple.com/app/mamp-stack/id571310406获取它们

回答by crizCraig

ammpswas super easy for me and has a nice web-based configuration:

ammps对我来说非常简单,并且有一个不错的基于 Web 的配置: