Home > php教程 > php手册 > body text

Configuring Apache + PHP + MySQL in Mac OS X 10.8

WBOY
Release: 2016-07-09 09:09:23
Original
990 people have browsed it

Configuring Apache+PHP+MySQL in Mac OS X 10.8 includes:

  1. Configuring Apache
  2. Configure PHP
  3. Install MySQL
  4. Configure PHPAdmin
  5. Set database default character set

1. Configure Apache

1. Start Apache

Open the terminal and enter:

sudo apachectl start
Copy after login

Open the browser and enter:

http://localhost
Copy after login

You should see the "It works!" page, which is located in the /Library/WebServer/Documents/ directory, which is the default root directory of Apache.

2. Configure user access directory

In the terminal enter:

mkdir ~/Sites
cp /Library/WebServer/Documents/index.html.en index.html
Copy after login

Create a new directory named Sites in the user directory as the access path to the user directory, and copy /Library/WebServer/Documents/index.html to the user directory

Enter:

<span style="color: #000000;">cd /etc/apache2/users/
sudo vi apple.conf</span>
Copy after login

Note: apple is your username.

In vi, press i to start typing and enter the following:

<Directory "/Users/apple/Sites/">
  Options Indexes MultiViews
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>
Copy after login

After completing the input, press the ESC key, then enter: wq, save and close vi.

Note: The first line of the file is used to specify the location of the user directory, where apple is your username.

In the terminal enter:

sudo apachectl restart
Copy after login

Restart Apache and now you can access it in the browser:

http://localhost/~apple
Copy after login

2. Configure PHP

In the terminal enter:

cd /etc/apache2/
sudo vi httpd.conf
Copy after login

In vi, enter /php to search for text containing php and find:

#LoadModule php5_module libexec/apache2/libphp5.so
Copy after login

Delete the # in front, then save and exit. (Press shift i to enter at the beginning of the line, press ESC to exit editing, press x to delete the current character, and #, enter: wq, save and exit.)

Enter in the terminal:

cd /etc
sudo cp php.ini.default php.ini
sudo apachectl restart
Copy after login

Enter in the terminal:

cd ~/Sites
vi info.php
Copy after login

Then enter the following into info.php:

<span style="color: #0000ff;"><</span><span style="color: #800000;">html</span><span style="color: #0000ff;">><</span><span style="color: #800000;">body</span><span style="color: #0000ff;">><</span><span style="color: #800000;">h1</span><span style="color: #0000ff;">></span>It works!<span style="color: #0000ff;"></</span><span style="color: #800000;">h1</span><span style="color: #0000ff;">></span><span style="color: #0000ff;"><?</span><span style="color: #ff00ff;">php phpinfo(); </span><span style="color: #0000ff;">?></span><span style="color: #0000ff;"></</span><span style="color: #800000;">body</span><span style="color: #0000ff;">></</span><span style="color: #800000;">html</span><span style="color: #0000ff;">></span>
Copy after login

Enter in the browser:

http://localhost/~apple/info.php
Copy after login

3. Install Mysql

1. Download mysql-5.6.12-osx10.7-x86_64.dmg from the Mysql official website and double-click to open the dmg file.

2. Run mysql-5.6.12-osx10.7-x86_64.pkg to install the main package;

3. Run MySQLStartupItem.pkg to let mysql run automatically at boot;

4. Run MySQL.prefPane and add the mysql service management option in the system preferences;

Enter in the terminal:

<span style="color: #0000ff;">sudo</span> <span style="color: #0000ff;">chmod</span> +<span style="color: #0000ff;">w</span><span style="color: #000000;"> bashrc

</span><span style="color: #0000ff;">sudo</span> <span style="color: #0000ff;">vi</span> /etc/bashrc
Copy after login

Add the following two command aliases at the end of bashrc to facilitate quick use of mysql

#mysql
alias mysql='/usr/local/mysql/bin/mysql'
alias mysqladmin='/usr/local/mysql/bin/mysqladmin'
Copy after login

Tip: After adding the command alias in bashrc, you need to restart the terminal.

Change the default password of mysql and enter in the terminal:

mysqladmin -u root password "123"
Copy after login

You can specify any password at position 123.

If you want to change your password, you can enter

mysqladmin -u root -p password "123"
Copy after login

Before changing the password, you need to enter the previous correct password.

4. Configure PHPAdmin

1. Download PHPAdmin, extract it to the ~/Sites directory, and rename the directory to: phpmyadmin;

2. Enter in the browser:

http://localhost/~apple/phpmyadmin/setup/
Copy after login

Just add a server configuration.

5. Set the database default character set

Enter in the terminal:

mysql -u root -p
# 创建名为 mydb 的数据库
create database mydb;
# 将 mydb 的默认字符集设置为 utf8
alter database mydb default character set = utf8;
Copy after login

Note: The default character set used by mysql is latin1, which does not support Chinese and needs to be set.

Get it done and call it a day :)

P.S.

There are many documents on the Internet about configuring php mysql on mac. This article only focuses on my usage needs and simply records the steps. :)

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!