Configuring Apache + PHP + MySQL in Mac OS X 10.8
Configuring Apache+PHP+MySQL in Mac OS X 10.8 includes:
- Configuring Apache
- Configure PHP
- Install MySQL
- Configure PHPAdmin
- 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><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>
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. :)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











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.

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

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.

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.

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.

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

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