Mac OS X Configuration apache+mysql+php Detailed tutorial

Source: Internet
Author: User
Tags mysql version socket error phpmyadmin

There are a lot of tutorials on the web, here is a concise record. Take Mac OS X Mavericks 10.9.X as an example.

First, attach how to enter the specified directory folder, press Command + Shift + G, and then enter the specified directory name.

Tools/Materials
    • Take Mac OS X Mavericks 10.9.X as an example.
First, start Apache
    1. 1

      MAC OS X System has integrated the apache+php environment, go to "System Preferences-sharing", turn on "Web sharing", you can open Apache.

      But in the new version of Mac OS X, Apple has removed the graphical interface for this shared feature, which can only be opened from the command line.

    2. 2

      Enter command in terminal, start Apache:sudo apachectl start

      Close Apache:sudo Apachectl Stop

      Restart Apache:sudo apachectl Restart

      View Apache version: Httpd-v

      Apache version information in Mac OS X 10.9.X:

      Server version:apache/2.2.26 (Unix) Server Built:dec 10 2013 22:09:38

    3. 3

      After Apache is enabled, Access http://localhost or http://127.0.0.1 in the browser, if "It works!" appears Indicates that it is operating normally.

      END
Second, the root directory
  1. 1

    OS X Default has two directories can run your Web program directly, one is the system-level Web root directory, one is the user-level root directory, everyone write down.

     

    Note: The following haibor are user names and need to be modified in real terms.

     

    The root directory of the Apache system level and the corresponding URL is:

    /library/webserver/documents/http://localhost

     

    The

    User-level root directory and the corresponding URL are:

    ~/sites http://localhost/~haibor/

     

     

     

     

    ~/sites is the "site" directory under your user directory, which may not be in OS X, so you need to manually create a directory with the same name.

     

    is built in a simple way, run directly in the terminal:

    sudo mkdir ~/sites

  2. 2

    Set up the Sites folder, check the/etc/folder below for the "haibor.conf" file:

    /etc/apache2 /users/

     

    If not, then you need to create one, named "Haibor.conf", which can be created using either VI or Nano, one of the two editors.

     

    sudo vi/etc/apache2/users/haibor.conf

     

    After creation, write the following lines to the Conf file above:

    <directory "/users/haibor/sites/";

        options Indexes multiviews

        allowoverride all

        order allow,deny

        allow from all

    < /directory>

  3. 3

    Once the file is saved, grant it the appropriate permissions:

    sudo chmod 755/etc/apache2/users/haibor.conf

    Next, restart Apache to make the configuration file effective:

    sudo apachectl restart

    After that you can access your user-level directory page through a browser, you can easily prevent a webpage to test it. The root directory address is:

    http://localhost/~haibor/

    You can also change the root directory, but to remember to set the new folder, the folder needs to have Execute permission x, set to 755:

    Mkdir/users/user/workspace chmod 755/user/user/workspace

    Replace the/library/webserver/documents/in the/etc/apache2/httpd.conf file with your own path, such as/user/user/workspace

    Restart Apache:apachectl restart, and then visit localhost again to display the contents of the changed file.

    END
Third, start PHP
    1. 1

      The PHP 5.4.30 version is already integrated in OS X Mavericks and needs to be turned on manually. You can use the VI or Nano Editor to open the following file:

      sudo nano/etc/apache2/httpd.conf

      Then press Ctl+w to find, search "PHP", the first match should be the following sentence code:

      LoadModule Php5_module libexec/apache2/libphp5.so

      Please remove the # in front of this code and save the file.

      Then restart Apache again:

      sudo apachectl restart

      Now that PHP should be working, you can put a PHP test file in the user-level root directory (~/sites/) with the following code:

      <?php phpinfo ();?>

      END
Iv. installation of MySQL
  1. 1

    There is no integrated Mysql in OS X Mavericks and requires manual installation.

    You can click http://dev.mysql.com/downloads/mysql/to download the MySQL installation package.

    Please download Mac OS X 10.7 (x86, 64-bit), DMG Archive (if you have a newer version, downloadable).

    After downloading the DMG, double-click you will extract three files and a RedMe.txt document. These three files are:

    Mysql-5.6.15-osx10.7-x86_64.pkg

    Mysqlstartupitem.pkg

    Mysql.prefpane

    You need to install each of these three files, mysqlstartupitem.pkg installation, MySQL will start with the system boot, Mysql.prefpane indicates that you can see the MySQL option in System Preferences, there is a MySQL installation.

  2. 2

    After all three files are installed, go to "system Preferences", at the bottom of the panel you will see a MySQL setting, click on it to start MySQL.

    You can also turn on MySQL by command:

    Sudo/usr/local/mysql/support-files/mysql.server start

    If you want to view the MySQL version, you can use the following command:

    /usr/local/mysql/bin/mysql-v

    After running the above command, you will log in to MySQL directly from the command line and enter the command \q to exit.

    Here MySQL is configured to complete and can be run.

  3. 3

    In order to be more convenient to use, it is better to set the system environment variables, that is, the MySQL command in any path can be directly started (do not need to enter a long string of exact path).

    Setting environment variables is also very convenient, directly with the command (here I use VI editor example):

    cd; VI. bash_profile

    Then press the letter I into the edit mode, the following code is pasted into the sentence:

    Export path= "/usr/local/mysql/bin: $PATH"

    Then press ESC to exit the editor, and then enter: Wq (don't forget the colon) to save the exit. Of course, if you use the Nano or other editor, the operation may not be the same as this, anyway, it means to write the above sentence into the. bash_profile file.

    The next step is to reload the Shell to make the above environment variable effective:

    SOURCE ~/.bash_profile

    After that you can use the MySQL command in any directory of the terminal, you can run mysql-v to try.

  4. 4

    The last step, after installing the default username is root, password is empty, you should also give your MySQL set a root user password, the command is as follows:

    mysqladmin-u root password ' here to fill in the password you want to set '

    (Remember that the password must be wrapped in half-width single quotation marks.)

    Above the mysqladmin command, I did not write the full path. Because we have set the environment variables above, if you do not set the environment variables, you need to use/usr/local/mysql/bin/mysqladmin ******** to run.

    END
V. Installation of phpMyAdmin or Adminer
    1. 1

      Before you install PhpMyAdmin, first fix the 2002 socket error:

      sudo mkdir/var/mysql

      sudo ln-s/tmp/mysql.sock/var/mysql/mysql.sock

      Then you can download the installation package in phpMyAdmin official website, the recommended download english.tar.gz, also can download all-languages.tar.gz use Chinese version, unzip, the extracted folder renamed to "phpMyAdmin", and put it in the "site" directory set up Above (~/sites).

      Then create a config folder under phpMyAdmin:

      When you're done here, you'll have access to http://localhost/~haibor/phpmyadmin/.

      To manage your database through Phpmysql.

      can also use Adminer to manage, very convenient to say, recommend related article lightweight mainstream database web-side management tool Adminer.

      END
VI. Setting up a virtual host
    1. 1

      To configure the Apache file:

      sudo vi/etc/apache2/httpd.conf

      Find "#Include/private/etc/apache2/extra/httpd-vhosts.conf" in httpd.conf, remove the "#" from the front, ": wq!" to save and exit.

      Restart Apache:sudo apachectl restart.

    2. 2

      Configuring the virtual Host file httpd-vhost.conf

      sudo vi/etc/apache2/extra/httpd-vhosts.conf

      In fact, these two virtual hosts do not exist, and when no other virtual host is configured, it may cause the following prompt when accessing localhost:

      Forbidden you don ' t have permission to access/index.php on the This server

      The simplest way to do this is to add the # to the front of each line and comment it out, so that you can refer to it without causing other problems.

      END
Vii. about PHP.ini
    1. 1

      Copy the php.ini first, then you can configure various PHP functions via php.ini.

      sudo cp/etc/php.ini.default/etc/php.ini

      For example, modify the Upload_max_filesize, Memory_limit, post_max_size three values to adjust the maximum value of the PHP commit file, such as the maximum value of the imported data in phpMyAdmin.

Mac OS X Configuration apache+mysql+php Detailed tutorial

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.