OS X Mountain Lion System configuration apache+mysql+php Detailed tutorial

Source: Internet
Author: User
Tags exit chmod mysql mysql version php file socket error variable phpmyadmin

If you are a WEB developer, there are many times when you need to build a server test environment locally, such as the apache+mysql+php environment. In fact Mac OS X wants to build such an environment is very simple, this article we will be a detailed tutorial to share.

The first thing to note is that MAC OS X system has actually integrated the apache+php environment, the user manually open it. In previous OS X systems, you could turn on Apache simply by going to "system preferences-sharing" and then opening "web sharing. However, in the latest mountain Lion, Apple has canceled the graphical interface for this shared feature, which can only be opened from the command line.

There is no web share in the mountain Lion

Enable Apache/web sharing

Open the terminal and run the Apache command to start:

sudo apachectl start

Close command:

sudo apachectl stop

Reboot command:

sudo apachectl restart

To view the Apache version command:

Httpd-v

The Apache version integrated in Mountain Lion is as follows:

mbp:~ eyon$ Httpd-v
Server version:apache/2.2.22 (Unix)
Server Built:jun 20 2012 13:57:09

After you enable Apache, you can access http://localhost directly in the browser, if "It works!" Indicates that the operation is normal.

root directory

After you enable Apache, you first have to know which directory the page files should be placed in order to function properly, I believe that there is experience in the Linux server configuration will not be unfamiliar. The default in OS X is two directories to run your Web program directly, one is the system-level Web root directory, and one is the user-level root directory, you can write down.

The system-level root directory is:

/library/webserver/documents/

Its corresponding URL is:

http://localhost

The user-level root directory is:

~/sites

~/sites is also the "site" directory below your user directory, which may not be in the OS X mountain Lion, so you need to manually create a directory with the same name. It is simple to build and run directly in the terminal:

sudo mkdir ~/sites

After you set up the Sites folder, check that the following folder contains the file "your username. conf".

/etc/apache2/users/

If not, then you need to create one, named "Your username. conf", which you can create using either the VI or the Nano Editor.

sudo vi/etc/apache2/users/your username. conf

After it is created, write the following lines to the Conf file above:

<directory "/users/username/sites/" >
Options Indexes MultiViews
AllowOverride All
Order Allow,deny
Allow from all
</Directory>

After the file is saved, give it the appropriate permissions:

sudo chmod 755/etc/apache2/users/your username. conf

Next, restart Apache so that the profile takes effect:

sudo apachectl restart

Then you will be able to access your user-level directory page through the browser, you can easily prevent a Web page to test. The root directory address is:

http://localhost/~username/

(Please change the username to your username)

Enable PHP

The PHP 5.3.13 version has been integrated in the mountain Lion and needs to be opened manually. You can use the VI or Nano Editor to open the following file:

sudo nano/etc/apache2/httpd.conf

Then 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 have started working, you can put a PHP test file in the user-level root (~/sites/) code as follows:

<?php phpinfo ();?>

Installing MySQL

Mysql is not integrated in the mountain Lion and needs to be manually installed. You can click this link to download the MySQL installation package, download Mac OS X ver 10.6 (x86, 64-bit), DMG Archive (can work under Mountain Lion).

Click to download, will jump to a registration/login page, you do not need to register and do not need to login, direct point login box below: No, just take me to the downloads! You can skip this step to start the download directly, the entire DMG package is about 113MB.

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

    • Mysql5.5.xxx.pkg
    • Mysqlstartupitem.pkg
    • Mysqlprefpane

You need to install each of these three files, double-click the system may be prompted you because the package from unknown developers, can not install. In this case, you can hold down the command key, then right click on the installation file, and then click "Open" in the right menu, so that you can bypass the security restrictions (you can also change the system Preferences-security and privacy-general to open "any source" application).

After all three files have been installed, go to "system Preferences", at the bottom of the panel you will see a MySQL settings, click it to start MySQL, or you can also use the following command to open:

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 be able to login directly from the command line to MySQL, and enter the command \q to exit.

Here MySQL has been configured to complete and can run. But in order to be more convenient to use, you had better set the system environment variable, that is, let MySQL this command in any path can be started directly (no need to enter a long string of exact path).

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

cd; VI. bash_profile

Then press the letter I into edit mode and paste the following code in:

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 editors, the operation is not the same as this, anyway, the meaning is to write the above sentence into the. bash_profile file.

The next step is to reload the Shell for the above environment variable to take effect:

SOURCE ~/.bash_profile

Then you can use the MySQL command at any directory in the terminal, and you can run mysql-v to try it.

In the final step, you should also set a root user password for your MySQL command as follows:

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

(Please remember that the password must be wrapped in half-width single quotes)

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

Install phpMyAdmin

Before installing phpMyAdmin, first fix the 2002 socket error:

sudo mkdir/var/mysql

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

Then go to the phpMyAdmin website to download the installation package, recommended download english.tar.gz. After decompression, the extracted folder is renamed "phpMyAdmin" and placed in the "site" directory (~/sites) set up above. Then create a config folder under phpMyAdmin:

mkdir ~/sites/phpmyadmin/config

Modify Permissions:

chmod o+w ~/sites/phpmyadmin/config

You can then access the phpMyAdmin initial settings page from the browser:

http://localhost/~username/phpmyadmin/setup/

(Please change the username to your username)

After you open the page, you basically don't need to configure it. Go in and click "New Server", in Basic Settings page to ensure that Serverhostname is localhost, in authentication configured login username and password (previously set the root password), click to save on it.

Once the phpMyAdmin configuration is complete, a config.inc.php file appears in the/config directory that is created above, moves the file to the phpMyAdmin root (Level one), and then deletes the empty/config directory.

When you're done here, you can then visit http://localhost/~username/phpmyadmin/(replace username with your username) to manage your database through Phpmysql.

This is the complete tutorial on configuring apache+mysql+php on OS X Mountain Lion. If there is anything you don't understand, please ask in the comments box below.



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.