Mac OS X Mavericks configuration apache+mysql+php Detailed tutorial

Source: Internet
Author: User
Tags socket error phpmyadmin

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

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

First, start Apache

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.

Enter the command in the terminal to launch Apache:

sudo apachectl start

Close Apache:

sudo apachectl stop

Restart Apache

sudo apachectl restart

To view the Apache version:

Httpd-v

Apache version information in Mac OS X 10.9.1:

Server version:apache/2.2.24 (Unix) Server Built:sep 12 2013 16:12:49

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

Second, the root directory

There are two directories in OS X that can run your Web program directly, one is the system-level Web root directory, and the other is the user-level root directory.

Note: The following haibor are user names and need to be modified as per the actual.

The system-level root directory and the corresponding URL are:

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

The user-level root directory and the corresponding URL are:

~/siteshttp://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. The Setup method is simple and runs directly in the terminal:

sudo mkdir ~/sites

After establishing the "Sites" folder, check the/etc/folder for "haibor.conf" This file:

/etc/apache2/users/

If not, then you need to create one that is named "haibor.conf" and can be created using either the VI or the Nano Editor.

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

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

<directory "/users/haibor/sites/" >    Options Indexes multiviews    allowoverride all    Order Allow,deny Allow from    all</directory>

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/
Third, start PHP

The PHP 5.4.17 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 ();?>
Iv. installation of MySQL

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 (currently the latest version of OS X 10.7).

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

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.

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.

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.

V. Installation of phpMyAdmin or Adminer

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

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

Then you can download the installation package on the phpMyAdmin official website, the recommended download english.tar.gz, also can download all-languages.tar.gz use the 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 can then visit 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.

, Adminer website Download

VI. Setting up a virtual host

1. Configure Apache Files:

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

Forbiddenyou don ' t has 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.

Add the following configuration

<virtualhost *:80>    documentroot "/users/haibor/sites" #程序目录    ServerName localhost #此处也可以设置为其它, e.g. sites< C2/>errorlog "/private/var/log/apache2/sites-error_log"    customlog "/private/var/log/apache2/sites-access_log "Common    <directory/>        Options Indexes followsymlinks multiviews        allowoverride None        Order deny, Allow to    </Directory></VirtualHost>

: wq! Save the exit and restart Apache.

3. Configure the Hosts file to run the command:

sudo vi/etc/hosts

Add "127.0.0.1 localhost" or "127.0.0.1 sites" so that you can configure the Localhost/sites virtual host and Access "http://localhost" or "http://sites".

Before 10.8, the Mac OS x version has exactly the same content as the "http://localhost/~[user name".

Note that the log "errorlog"/private/var/log/apache2/sites-error_log "" can also be deleted, but logging is actually a good habit, in case of problems can help us to judge. If you keep these log code, a certain log file path is present, if you arbitrarily modify a non-existent, will cause Apache can not service without error prompts, this is more disgusting.

Vii. about PHP.ini

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.

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.