Configure the Apache server on your Mac

Source: Internet
Author: User

Apache server is a server that comes with your Mac, and the Apache installation directory is:/ETC/APACHE2/,ETC is hidden by default.

Viewing methods are:

1.dock Right-click Finder, select "Go to Folder" and enter "/etc".

2. Enter "Open/etc" in the terminal.

How to open the Apache server: sudo apachectl start. When open, enter "http://localhost" in the Safari's address bar to see the "It works!" content The page.

How to turn off Apache server: sudo apachectl stop.

The root directory of the Apache server is in "/library (Resource Library)/webserver/documents/".

To set up a virtual server:

1. Run "sudo vi/etc/apache2/httpd.conf" on the terminal to open the Apche configuration file

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

3. Run "sudo apachectl restart" to restart Apache and turn on the virtual host Configuration feature.

4. Run "sudo vi/etc/apache2/extra/httpd-vhosts.conf", open the configuration virtual host file httpd-vhost.conf, configure the virtual host. It is important to note that the file is opened by default to two virtual hosts as an example (the following is a virtual host example):

<virtualhost *: the>ServerAdmin [email protected]-host.example.com DocumentRoot"/usr/docs/dummy-host.example.com"ServerName Dummy-host.example.com errorlog"/private/var/log/apache2/dummy-host.example.com-error_log"Customlog"/private/var/log/apache2/dummy-host.example.com-access_log"Common</VirtualHost> <virtualhost *: the>ServerAdmin [email protected]-host2.example.com DocumentRoot"/usr/docs/dummy-host2.example.com"ServerName Dummy-host2.example.com errorlog"/private/var/log/apache2/dummy-host2.example.com-error_log"Customlog"/private/var/log/apache2/dummy-host2.example.com-access_log"Common</VirtualHost>

It is important to note that the examples of these two virtual hosts do not exist, and when you do not configure any other virtual hosts, you may get the following prompt when you access localhost:

  Forbidden  You don‘t have permission to access /index.php on 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.

5. Under the information that the terminal opens, add the following configuration:

 <virtualhost *:80  > DocumentRoot   "/library/webserver/documents  "   ServerName www  .moxue.com errorlog 
     /private/var/log/apache2/    Dummy-host.example.com-error_log    Customlog   /private/var/log/apache2/ Dummy-host.example.com-access_log    Common  <directory/> Options Indexes followsymlinks multiviews AllowOverride None Order deny,allow allow from all  </Directory> </virtualhost> 
DocumentRoot is where the server places the files. ServerName is the address of the server you are visiting and can be filled out casually.

After saving, you can launch it.

6. Run " sudo vi /etc/hosts ", open the Hosts configuration file, add " 127.0.0.1 www.moxue.com ", so you can configure the completion of the virtual host, you can access
"Http://www.moxue.com".



Attached: Mac Some simple commands to use:
: x equals: Wq
: W Save
: Q Not saved direct exit
: Wq Save and exit
: w! Force Save
: q! Force exit
: wq! Force Save exit
7XL Force Save exit





Configure the Apache server on your 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.