Detailed tutorials on Mac OS to build apache+php+mysql development environment _c language

Source: Internet
Author: User
Tags mysql in phpmyadmin

First, start Apache

There are two ways of

1, open the network share

Open "System Preferences"-> "sharing" and tick before "Internet sharing".

2, open the terminal, input

sudo apachectl start

Then you need to enter a password, enter the computer password, and then enter

sudo apachectl-v

can view version information for Apache

Server version:apache/2.2.24 (Unix)
server built: June  7 2013 18:05:17

When you enter http://localhost in the browser, you will receive an IT works! The page

Second, run PHP

1, find the Apache configuration file, in the directory/etc/apache2/, open the Finder, select "Go"-"Go to Folder", enter "/etc/apache2/", find the "httpd.conf" file, choose to open the document to edit, Click Command+f to search #loadmodule php5_module libexec/apache2/libphp5.so, as shown in

Remove the Blue Line of the #, and then save, if there is text locked, unable to unlock the situation, there are two ways to solve

A to select the file, right-click and select Show Profile. Click on the lower right corner of the small lock icon, enter the computer password unlock, and then select the + key to the left, select their current computer login users, set the right to read and write, if still not, will be the first level of folder permissions to modify the same.

b) Copy the file to the desktop, make changes, modify it, and then copy it to the original folder before replacing the file.

2, restart Apache, in the terminal input

sudo apachectl restart

PHP is ready to use.
3, in the terminal input

sudo cp/library/webserver/documents/index.html.en/library/webserver/documents/info.php

That is, copy the Index.html.en file in the root directory of Apache and rename it to info.php.

4, open info.php, after it works plus <?php phpinfo (), and then restart Apache, in the browser input http://localhost/info.php, there will be a display of PHP information page, as shown in the figure.

Third, the configuration of MySQL

1, on the http://dev.mysql.com/downloads/mysql/website, select the Mac OS x platform, and then select the download in the picture, I began to download the wrong, installation error, and then download the version of the installation of the successful

Double-click the DMG file

Double-click the first installation, double-click the third installation, double-click the second, and the second is the configuration file, after installation, you can choose to start or shut down MySQL in your system preferences.

2, modify the password

In the terminal input, here Modify the password is 12345, can also be other, custom can

/usr/local/mysql/bin/mysqladmin-u Root Password 12345

Iv. Use of phpMyAdmin

phpMyAdmin is a PHP-developed program for managing MySQL, very practical.

1, download phpMyAdmin, in the URL http://www.phpmyadmin.net/home_page/downloads.php select the appropriate version of the download, I chose is phpmyadmin-4.0.8-all-languages.tar.bz2

2, will download a good file after decompression, put into the/library/webserver/documents/folder, and named phpMyAdmin.

3, copy the/library/webserver/documents/phpmyadmin in the config.sample.inc.php, and named Config.inc.php, and placed under the current folder.

4, edit config.inc.php, modify the

$cfg [' Servers ']] $i] [' host '] = ' localhost ';

For

$cfg [' Servers ']] $i] [' host '] = ' 127.0.0.1 ';

Then, if you want to login without a password, change false in the following statement to True

$cfg [' Servers '] [$i] [' allownopassword '] = False

5, in the browser input http://localhost/phpmyadmin, enter the username "root", and just changed their password, if not changed the password, then follow the previous step without password operation, and then can be directly logged on.

PS: To this configuration complete, PHP development also need to download a PHP development tool, Mac under the PHP development tool is also quite a lot, we Google Baidu, we need to remind that the installation of good development tools, in the proposed PHP project, remember to put the project in and phpmyadmin the same directory file , you can create a new folder to store the PHP project, otherwise, it is unable to run (a great God instructed, I have not personally verified)

Five, Mac under the PHP connection MySQL database failure solution
MySQL successfully connected via phpMyAdmin, but failed to connect to database via PHP, execute the following PHP statement

@mysql_connect ("localhost", "root", "12345") or Die ("Database server Connection Failed");/Connect Server

After that, the browser output database server connection failed, the following is the workaround.
1, the Mac MySQL installation path is, * for the version number, is the number.

/usr/local/mysql_******_osx10.*_x86_64

2, enter this folder after the bin to find the MySQL, double-click Open, double hit does not open the choice of terminal Open, and then enter

STATUS

Value of UNIX socket found after carriage return

3. Find PHP.ini, find/etc/php.ini in Finder, copy to desktop, open with document, hold Command+f, then find Pdo_mysql.default_socket, Mysql.default_socket, Mysqli.default_socket these three values, change to the UNIX socket above the value, modified to copy to just the folder, replace the previous file

4, open the terminal, input sudo apachectl restart restart Apache can, again execution will not be an error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.