search
Homephp教程php手册Configuring Apache + PHP + MySQL in Mac OS X 10.8

Configuring Apache + PHP + MySQL in Mac OS X 10.8

Jul 09, 2016 am 09:09 AM
apachemac os xmysqlphpcodeOpen sourceprogrammingprogramming languagesoftware developmentConfiguration

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

Open the browser and enter:

http://localhost

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

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>

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>

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

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

http://localhost/~apple

2. Configure PHP

In the terminal enter:

cd /etc/apache2/
sudo vi httpd.conf

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

#LoadModule php5_module libexec/apache2/libphp5.so

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

Enter in the terminal:

cd ~/Sites
vi info.php

Then enter the following into info.php:

<span style="color: #0000ff;"><span style="color: #800000;">html</span><span style="color: #0000ff;">><span style="color: #800000;">body</span><span style="color: #0000ff;">><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></span></span></span>

Enter in the browser:

http://localhost/~apple/info.php

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

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'

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"

You can specify any password at position 123.

If you want to change your password, you can enter

mysqladmin -u root -p password "123"

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/

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;

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.