Mac升级到EI capitan重新设置Apache和php

 start Apache web sharing

sudo apachectl start

to stop it

sudo apachectl stop

to restart it

sudo apachectl restart

To find the Apache version

httpd -v

The Apache version that comes in OSX El Capitan is Apache/2.4.16

localhost-osx-apache

It Works!

After starting Apache – test to see if the webserver is working in the browser – http://localhost – you should see the “It Works!” text.

If you don’t get the localhost test, you can try troubleshooting Apache to see if there is anything wrong in its config file by running

apachectl configtest

This will give you an indication of what might be wrong.

Document Root

Document root is the location where the files are shared from the file system and is similar to the traditional names of ‘public_html‘ and ‘htdocs‘, OSX has historically had 2 web roots one at a system level and one at a user level – you can set both up or just run with one, the user level one allows multiple accounts to have their own web root whilst the system one is global for all users. It seems there is less effort from Apple in continuing with the user level one but it still can be set up with a couple of extra tweaks in configuration files. It is easier to use the user level one as you don’t have to keep on authenticating as an admin user.

System Level Web Root

– the default system document root is still found at –

http://localhost/

The files are shared in the filing system at –

/Library/WebServer/Documents/

User Level Root

The other web root directory which is missing by default is the ‘~/Sites’ folder in the User account. This takes a bit longer to set up but some users are very accustomed to using it.

You need to make a “Sites” folder at the root level of your account and then it will work. Once you make the Sites folder you will notice that it has a unique icon which is a throwback from a few versions older. Make that folder before you set up the user configuration file described next.

You have to make a few additional tweaks to get the ~/Sites folder back up and running.

user-level-webroot-sites-folder

Sites Folder

Add  a “username.conf” filed under:

/etc/apache2/users/

If you don’t already have one (very likely), then create one named by the short username of the account with the suffix .conf, its location and permissions/ownership is best tackled by using the Terminal, the text editor ‘nano‘ would be the best tool to deal with this.

Launch Terminal, (Applications/Utilities), and follow the commands below, first one gets you to the right spot, 2nd one cracks open the text editor on the command line (swap ‘username‘ with your account’s shortname, if you don’t know your account shortname type ‘whoami‘ the Terminal prompt):

cd /etc/apache2/users
sudo nano username.conf

Then add the content below swapping in your ‘username’ in the code below:

<Directory "/Users/username/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>

Permissions on the file should be:

-rw-r--r--   1 root  wheel  298 Jun 28 16:47 username.conf

If not you need to change…

sudo chmod 644 username.conf

Open the main httpd.conf and allow some modules:

sudo nano /etc/apache2/httpd.conf

And make sure these modules are uncommented (the first 2 should already be on a clean install):

LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule include_module libexec/apache2/mod_include.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so

 

Whilst you have this file open also to get php running uncomment. (Mentioned also in the PHP part of the article).

LoadModule php5_module libexec/apache2/libphp5.so

And also uncomment this configuration file also in httpd.conf – which allows user home directories.

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

Save all your changes (Control + O in nano)

Then open another Apache config file and uncomment another file:

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

And uncomment:

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

Save all your changes (Control + O in nano)

 

Restart Apache for the new file to be read:

sudo apachectl restart

Then this user level document root will be viewable at:

http://localhost/~username/

You should only see a directory tree like structure if the folder is empty.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值