Configure APACHE+PHP+MYSQL Environment under Mac

Source: Internet
Author: User
Tags mysql create socket error
Recently done a project, the front-end interaction API document has been in the form of Excel and Word management, feel very inconvenient, so is to find a more intuitive way. Looking for a lap around the internet, there are some open source API management platforms that look good (useless, so they can only be said to look good), such as Easyapi.

However, I do not want to put the API on someone else's server, continue to look for, found Showdoc. This is an open source API management project that can be deployed to its own server, using PHP. So, I began to toss apache+php+mysql on my Mac, the following into the topic.

apache+php Configuration

Mac OSX system comes with Apache and PHP environment, just not open by default, my personal device environment is as follows:

    • PHP Version: 5.5.27
    • Apache version: 2.4.16 (Unix)
    • System version: OS X EI Capitan (OS X 10.11)

Open Apache

Open Terminal, enter the following to open the command.

    • Open Apache:sudo apachectl Start
    • Close Apache:sudo Apachectl Stop
    • Restart Apache:sudo apachectl Restart

Enter localhost in the browser if the default "It works!" appears as follows interface, it means that Apache is open successfully.

Localhost-osx-apache.png

Open PHP

To open PHP, you need to modify the Apache configuration file as follows:

    1. Open terminal, enter command: sudo vim/etc/apache2/httpd.conf
    2. Locate the #loadmodule php5_module libexec/apache2/libphp5.so and remove the comment (delete the previous pound sign).

The default folder for Apache under Mac is/library/webserver/documents, in which a file named index.php is created, and the following is added to the file: . Delete the original directory of the index.html file, and then enter localhost in the browser, if the following PHP's Info page appears, it means that PHP open successfully, if not successful, restart Apache with the previous command and try again.

QQ20160219-0@2x.png

Modifying the Apache Directory

It says that the default folder for Apache under Mac is/library/webserver/documents, which is hidden by default and is not very convenient, and we can modify it to a custom directory.

    1. Open terminal, enter command: sudo vim/etc/apache2/httpd.conf
    2. Find the following two places DocumentRoot "/library/webserver/documents"
    3. Replace the directories in quotation marks in two places with a custom directory

After completing the three steps above, restart Apache, copy the previously created index.php file to the custom directory, then enter localhost in the browser, and if a PHP info page appears, the directory modification is successful.

MySQL Installation

OSX 10.11 does not own MySQL and needs to be installed on our own. Here is only the simplest way to download the latest DMG installation package on the MySQL website, I am downloading mysql-5.7.11-osx10.10-x86_64.dmg. After entering the download page, you will be prompted to log in or register, here do not bother, directly click on the bottom of the "No Thanks, just start my download."  To start the download. Double-click the downloaded DMG installation, the next installation, the final installation will pop up a prompt to tell you that MySQL root@localhost account generated a temporary password, be sure to save this password.

Mysql-root-password.png

Start MySQL

    1. Go to System Preferences and click MySQL.

      QQ20160219-2@2x.png

    2. Click Start MySQL Server

      QQ20160219-1@2x.png

To modify the root user's password

Open terminal, enter command (replace Temppassword with previously saved temporary password):/usr/local/mysql/bin/mysqladmin-u root-p ' temppassword ' password ' NewPassword '

Fix "2002 MySQL Socket Error"

If "2002 MySQL socket error" is present, the socket that supports MySQL/C/s communication cannot be found. The reason is that MySQL places it in the/ tmp directory, and OSX places it in the /var/mysql directory. So we just need to create a soft link, enter the following two commands: Create a directory: sudo mkdir/var/mysql create a soft link: sudo ln-s/tmp/mysql.sock/var/mysql/mysql.sock

PhpMyAdmin

Complete the above two steps, MySQL even if the installation configuration is complete, but for convenience, it is necessary to install a visual tool, I choose phpMyAdmin. Download the latest Zip package directly to phpMyAdmin website, we recommend to download the multi-language version, support Simplified Chinese.  After the download is complete, rename the extracted folder to phpMyAdmin and place it in the root directory of the custom Apache path. Enter Localhost/phpmyadmin in the browser, the landing page of MySQL appears, on which the language can be set, and then log in with root and previously set password. See the following two pages, you are done!!

QQ20160219-3@2x.png

QQ20160219-4@2x.png

Resources

    1. Configure Apache + Php + MySQL environment under Mac
    2. Get Apache, MySQL, PHP and phpMyAdmin working on OSX 10.11 El Capitan
  • Related Article

    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.