Home php教程 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
apache mac os x mysql php code Open source programming programming language software development Configuration

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

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

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

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Steps to add and delete fields to MySQL tables Steps to add and delete fields to MySQL tables Apr 29, 2025 pm 04:15 PM

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

What is the significance of the session_start() function? What is the significance of the session_start() function? May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

How to uninstall MySQL and clean residual files How to uninstall MySQL and clean residual files Apr 29, 2025 pm 04:03 PM

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

An efficient way to batch insert data in MySQL An efficient way to batch insert data in MySQL Apr 29, 2025 pm 04:18 PM

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

How to use MySQL functions for data processing and calculation How to use MySQL functions for data processing and calculation Apr 29, 2025 pm 04:21 PM

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

How to configure the character set and collation rules of MySQL How to configure the character set and collation rules of MySQL Apr 29, 2025 pm 04:06 PM

Methods for configuring character sets and collations in MySQL include: 1. Setting the character sets and collations at the server level: SETNAMES'utf8'; SETCHARACTERSETutf8; SETCOLLATION_CONNECTION='utf8_general_ci'; 2. Create a database that uses specific character sets and collations: CREATEDATABASEexample_dbCHARACTERSETutf8COLLATEutf8_general_ci; 3. Specify character sets and collations when creating a table: CREATETABLEexample_table(idINT

How to analyze the execution plan of MySQL query How to analyze the execution plan of MySQL query Apr 29, 2025 pm 04:12 PM

Use the EXPLAIN command to analyze the execution plan of MySQL queries. 1. The EXPLAIN command displays the execution plan of the query to help find performance bottlenecks. 2. The execution plan includes fields such as id, select_type, table, type, possible_keys, key, key_len, ref, rows and Extra. 3. According to the execution plan, you can optimize queries by adding indexes, avoiding full table scans, optimizing JOIN operations, and using overlay indexes.

Composer: The Package Manager for PHP Developers Composer: The Package Manager for PHP Developers May 02, 2025 am 12:23 AM

Composer is a dependency management tool for PHP, and manages project dependencies through composer.json file. 1) parse composer.json to obtain dependency information; 2) parse dependencies to form a dependency tree; 3) download and install dependencies from Packagist to the vendor directory; 4) generate composer.lock file to lock the dependency version to ensure team consistency and project maintainability.

See all articles