Configure Apache in Mac OS X

Source: Internet
Author: User

In Mac OS x, the Mac OS X used to configure Apache is 10.8.2, and Mac comes with the Apache environment. Start Apache and set the virtual host to start Apache. Open terminal and enter sudo apachectl-v (you may need to enter the machine secret ). The following figure shows the Apache version. Then, enter sudo apachectl start to start Apache. Open the address bar of Safari and enter "http: // localhost". The content is "It works !". It is located under "/Library (resource Library)/WebServer/Documents/", which is the default root directory of Apache. The installation directory of Apache is:/etc/apache2/, and etc is hidden by default. There are three ways to view: Right-click the Finder under the dock, select "go to folder", enter "/etc" under the finder ---- go to --- "to go To the folder, then input/etc. You can enter "open/etc" in terminal to set the VM To Run "sudo vi/etc/apache2/httpd" on the terminal. conf, open the configuration file of Apche in httpd. find "# Include/private/etc/apache2/extra/httpd-vhosts.conf" in conf, remove the previous "#", save and exit. Run "sudo apachectl restart" and restart Apache to enable the VM configuration function. Run sudo vi/etc/apache2/extra/httpd-vhosts.conf to open the configuration VM file httpd-vhost.conf and configure the VM. Note that by default, this file enables two virtual hosts as an example: Xml Code <VirtualHost *: 80> ServerAdmin webmaster@dummy-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 *: 80> ServerAdmin webmaster@dummy-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> In fact, the two virtual hosts do not exist. when no other virtual hosts are configured, the following prompt may appear when accessing localhost: ForbiddenYou don't have permission to access/index. the simplest way for php on this server is to add # before each of them. Note: Just release it, so that you can refer to it without causing other problems. 5. add the following Xml configuration code <VirtualHost *: 80> DocumentRoot "/Library/WebServer/Documents" ServerName localhost ErrorLog "/private/var/log/apache2/localhost-error_log" CustomLog "/private/var/log/apache2/localhost-access_log" common </VirtualHost> <VirtualHost *: 80> DocumentRoot "/Users/snandy/work" ServerName mysites ErrorLog "/private/var/log/apache2/sites-error_log" CustomLog "/private/var/log/apache2/site S-access_log "common <Directory/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order deny, allow Allow from all </Directory> </VirtualHost> Save and quit, and restart Apache. 6. run "sudo vi/etc/hosts", open the hosts configuration file, and add "127.0.0.1 mysites". In this way, you can configure the sites virtual host and access "http: // mysites ". The content of Mac OS X and" http: // localhost /~ [User name] "is completely consistent. 7. note that the "ErrorLog"/private/var/log/apache2/sites-error_log "for logging can also be deleted, but logging is actually a good habit, when a problem occurs, it can help us determine. If the log Code is retained, the path of the log file must exist. If you modify the log Code that does not exist, Apache cannot be served and no error prompt is displayed. This is quite disgusting.

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.