본문 바로가기

Web

[Mac] 웹공유 활성시키기

OS를 Mountain Lion으로 업그레이드 한 후, 웹공유를 사용하려 하니 공유 설정화면에서 사라진 것을 확인할 수 있었다.


(Mountain Lion에서 공유 화면)


1. 터미널 명령어로는 여전히 사용이 가능하다. 터미널을 이용하여, 아파치서버를 start한다.

# sudo apachectl start (apache서버 시작)


(..그 외 명령어)

# sudo apachectl stop (apache서버 종료)

# sudo apachectl restart (apache서버 재시작)


서버 실행 후, 브라우저를 열고 '127.0.0.1'에서 접속하면 "It works!"문구를 확인할 수 있다.



2. 홈 디렉토리로 이동하여, "Sites"라는 폴더를 만든다.



3. (터미널 작업)

/etc/apache2/users 로 이동하여, 홈 디렉토리명과 동일한 이름의 conf파일을 생성한다.

# sudo pico 홈디렉토리명.conf


4. 아래와 같이 입력 후, "control+o", enter, "control+x"로 빠져나온다.

<Directory "/Users/홈디렉토리명/Sites/">

        Options Indexes MultiViews

        AllowOverride All

        Order allow,deny

        Allow from all

</Directory>


5. 아파치 서버를 재시작 한다.

# sudo apachectl restart


6. Sites폴더에 "index.html"를 작성 후 저장한다.


7. 브라우저를 열고, http://localhost/~홈디렉토리명/이동하면 위에 입력한 index.html내용이 출력되는 것을 확인할 수 있다.


---------------------------------------------------

Yosemite

OS X 출처: https://discussions.apple.com/docs/DOC-3083


Here is my definitive guide to getting a local web server running on OS X. This is meant to be a development platform so that you can build and test your sites locally, then deploy to an internet server. This User Tip contains instructions for configuring the Apache and PHP. I have another User Tip for installing and configuring MySQL and Perl.

Note: Yosemite introduces some significant changes. Pay attention to your OS version.

Another note: These instructions apply to the client versions of OS X, not Server. Server does a few specific tricks really well and is a good choice for those. For things like database, web, and mail services, I have found it easier to just setup the client OS version manually.


Requirements:

  1. Basic understanding of Terminal.app and how to run command-line programs.
  2. Basic understanding of web servers.
  3. Basic usage of vi. You can substitute nano if you want.

Optional:

  1. Xcode is required for adding PHP modules.

 

Lines in bold are what you will have to type in at the Terminal.

Replace <your local host> with the name of your machine. Ideally, it should be a one-word name with no spaces or punctuation. It just makes life easier.

Replace <your short user name> with your short user name.

 

Here goes... Enjoy!

 

Lion and later versions no longer create personal web sites by default. If you already had a Sites folder in Snow Leopard, it should still be there. To create one manually, enter the following:

mkdir ~/Sites

echo "<html><body><h1>My site works</h1></body></html>" > ~/Sites/index.html.en

 

PHP is not enabled in recent versions of OS X. To enable it, do:

sudo vi /etc/apache2/httpd.conf

 

Uncomment the following line:

#LoadModule php5_module libexec/apache2/libphp5.so

to

LoadModule php5_module libexec/apache2/libphp5.so

(if you aren't familiar with vi, just press 'x' over the '#' character to delete it. Then type ':w!' to save and then 'ZZ' to quit.)

10.7 Lion - line 111

10.8 Mountain Lion - line 117

10.9 Mavericks - line 118

10.10 Yosemite - line 169

 

For Yosemite only, uncomment the following line at line 166:

#LoadModule userdir_module libexec/apache2/mod_userdir.so

to

LoadModule userdir_module libexec/apache2/mod_userdir.so

 

and do the same at line 493:

#Include /private/etc/apache2/extra/httpd-userdir.conf

to

Include /private/etc/apache2/extra/httpd-userdir.conf

Save and exit.

 

And again, for Yosemite only, open the file above with:

sudo vi /etc/apache2/extra/httpd-userdir.conf

and uncomment the following line at line 16:

#Include /private/etc/apache2/users/*.conf

to

Include /private/etc/apache2/users/*.conf

Save and exit.

 

While you are in /etc/apache2, double-check to make sure you have a user config file. It should exist at the path:/etc/apache2/users/<your short user name>.conf. That file may not be created in Lion and if you upgrade to Mountain Lion, you still won't have it. It does appear to be created when you create a new user in Mountain Lion. If that file doesn't exist, you will need to create it with:

 

sudo vi /etc/apache2/users/<your short user name>.conf


For all systems other than Yosemite, use the following as the content:

<Directory "/Users/<your short user name>/Sites/">

    Options Indexes MultiViews

    AllowOverride None

    Order allow,deny

    Allow from localhost

</Directory>

 

For Yosemite, use this content:

<Directory "/Users/<your short user name>/Sites/">

    AddLanguage en .en

    LanguagePriority en fr de

    ForceLanguagePriority Fallback

    Options Indexes MultiViews

    AllowOverride None

    Order allow,deny

    Allow from localhost

     Require all granted

</Directory>


In vi, press <esc> and then ZZ to save and quit.

 

If you want to run Perl scripts, you will have to do something similar:

Note: This section cannot be done on Yosemite. Yosemite does not include /usr/libexec/apache2/mod_perl.so. It should be possible to build your own mod_perl, but that would be outside the scope of this User Tip.

 

Uncomment the following line: (In Lion this is on line 110. In Mountain Lion it is on line 116. In Mavericks it is on 117.)

#LoadModule perl_module libexec/apache2/mod_perl.so

to

LoadModule perl_module libexec/apache2/mod_perl.so

 

Then, in /etc/apache2/users/<your short user name>.conf change the line that says:

    Options Indexes MultiViews

to:

    AddHandler perl-script .pl

    PerlHandler ModPerl::Registry

    Options Indexes MultiViews FollowSymLinks ExecCGI

 

Now you are ready to turn on Apache itself.

 

In Lion, do the following:

To turn on Apache, go to System Preferences > Sharing and enable Web Sharing.

 

NOTE: There appears to be a bug in Lion for which I haven't found a workaround. If web sharing doesn't start, just keep trying.

 

In more recent versions of OS X, the Web Sharing checkbox in System Preferences > Sharing is gone. Instead, do the following:

sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

 

In Safari, navigate to your web site with the following address:

http://<your local host>/

 

It should say:

 

It works!

Now try your user home directory:

http://<your local host>/~<your short user name>

 

It should say:

 

My site works

Now try PHP. Create a PHP info file with:

echo "<?php echo phpinfo(); ?>" > ~/Sites/info.php

 

And test it by entering the following into Safari's address bar:

http://<your local host>/~<your short user name>/info.php

 

You should see your PHP configuration information.

 

If you want to setup MySQL, see my User Tip on Installing MySQL.

 

If you want to add modules to PHP, I suggest the following site. I can't explain it any better.

 

If you want to make further changes to your Apache system or user config files, you will need to restart the Apache server with:

sudo apachectl graceful


'Web' 카테고리의 다른 글

추천 사이트 [추가중..]  (0) 2012.06.11
PHP + MSSQL on Mac OS  (0) 2012.05.22
[html] html에서 php인식 시키기  (0) 2012.05.16
[PHP] Mac에서 PHP사용하기  (0) 2012.05.16