Configure apache,php under Mac

Source: Internet
Author: User

Note: If you feel that the terminal editing is too troublesome, you can also directly drag the file out of the manual edit after the original folder to replace it

1. Enable Apache:

Open terminal under Mac, enter "sudo apachectl start" (without quotation marks, same as below)

Enter your computer password to start Apache

2. Detecting Apache:

Enter "sudo apachectl-v" in the terminal to see the Apache version number

or enter "localhost" in the browser to see "It works! "Words

Here are two ways to detect whether Apache is enabled successfully

3. Enable PHP:

First, modify the httpd.conf configuration file

Enter "sudo vi/etc/apache2/httpd.conf" in the terminal

Move the cursor over "#" before "#LoadModule php5_module libexec/apache2/libphp5.so"

Click the "X" key to delete the "#" (If the error is deleted, you can simply press ESC and enter ": Q" to exit edit mode and then re-execute step 3)

After the deletion is successful, press ESC and enter ": Wq" to save the content and exit

Second, copy php.ini

Enter "cd/etc/" in the terminal and enter "sudo cp php.ini.default php.ini"

4. Check if PHP is enabled successfully

In terminal, type "sudo apachectl-k restart" to restart Apache

Create a new file, such as the name "test.php" (Suffix is php), the contents of "<?php echo" PHP enabled success! "?>"

Drag the file into the "/library/webserver/documents/" directory, which is the default access directory for Apache

Then enter "http://localhost/test.php" in the browser to see "PHP enabled successfully!" "The text

5. Modify the Apache default root directory

Enter "sudo vi/etc/apache2/httpd.conf" in the terminal

Find the DocumentRoot and <Directory> tags in the file

Modify it to your own directory, such as:

DocumentRoot "/users/chenyang/code/web"

<directory "/users/chenyang/code/web" >

where "Chenyang" is my user name, you need to follow your own username to replace the changes

When you're done editing, press ESC and enter ": Wq" to save the content and exit

You can follow step 4来 to detect if the new directory is enabled for success

At this point the entire Apache and PHP environment are configured successfully under the Mac!

Configure apache,php under Mac

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.