简体   繁体   English

本地主机/〜用户名/不起作用

[英]localhost/~username/ not working

So i have stuck on this thing since last week . 因此,自上周以来,我一直坚持做这件事。 i am new to web development , and wanted to learn php , as soon as i started i had to setup apache server , for root directory it works fine but for localhost/~username/ it can't connect to server "localhost". 我是Web开发的新手,并且想学习php,我一开始就必须设置apache服务器,对于根目录来说,它工作正常,但对于localhost /〜username /,它就无法连接到服务器“ localhost”。 错误图片

here are the files i had been messing up (sudo apachectl configtest : Syntax OK ) 这是我一直在搞乱的文件(sudo apachectl configtest:语法OK)

httpd-userdir.conf file httpd-userdir.conf文件

https://www.dropbox.com/s/3zmuc2jetpo3i0i/httpd-userdir.conf?dl=0 https://www.dropbox.com/s/3zmuc2jetpo3i0i/httpd-userdir.conf?dl=0

httpd.conf file httpd.conf文件

https://www.dropbox.com/s/vlrzqr95ge2qy3c/httpd.conf?dl=0 https://www.dropbox.com/s/vlrzqr95ge2qy3c/httpd.conf?dl=0

username.conf file username.conf文件

https://www.dropbox.com/s/f13cgfgfb56esi7/mfaizanulhaq.conf?dl=0 https://www.dropbox.com/s/f13cgfgfb56esi7/mfaizanulhaq.conf?dl=0

(OS X el Capitan 10.11.5 (15F34) & Server version: Apache/2.4.18 (Unix) Server built: Feb 20 2016 20:03:19 ) (OS X el Capitan 10.11.5(15F34)和服务器版本:Apache / 2.4.18(Unix)服务器内置:2016年2月20日20:03:19)

If this is still relevant and you are fed up with trying to find a solution you can change Documents root folder to your user Sites folder. 如果这仍然有意义,并且您厌倦了尝试找到解决方案的方法,则可以将“文档”根文件夹更改为用户的“站点”文件夹。 This will prevent everyone but you from accessing localhost from your machine, but it's a hotfix solution. 这将阻止除您之外的所有人从您的计算机访问localhost,但这是一个修复程序。 I've had a deadline and I had to finish the site, so this worked for me. 我有最后期限,必须完成网站,所以这对我有用。 Go to httpd.conf change 转到httpd.conf更改

DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">

to

DocumentRoot "/Users/username/Sites"
<Directory "/Users/username/Sites">

To look up your username in the terminal use whoami . 要在终端中查找用户名,请使用whoami

NOTE: Bear in mind you also need to change the following lines in httpd.conf it's located just below DocumentRoot within <Directory> tag you changed earlier. 注意:请记住,您还需要更改httpd.conf的以下行,它位于您之前更改的<Directory>标记内的DocumentRoot的正下方。 Whatever it says in your file modify to this (that should be true for ALL configurations of the Apache2) 不管文件中说的是什么,都对此进行修改(对于Apache2的所有配置都应该如此)

Options FollowSymLinks Multiviews
MultiviewsMatch Any
AllowOverride All
Require all granted

This is a really bad solution since your Users/username/Sites folder will be accessed directly when you type localhost in the browser, but when something goes wrong, or you've done something wrong this is the best solution so far especially if you are 100% certain you are not going to have more than 1 user access your localhost directory. 这是一个非常糟糕的解决方案,因为当您在浏览器中键入localhost时,将直接访问Users / username / Sites文件夹,但是当出现问题或执行错误时,这是​​迄今为止最好的解决方案,尤其是当您100%确定您将不会有超过1个用户访问您的localhost目录。

i hope no one faces this problem. 我希望没人面对这个问题。 In my case i had updated php to php 7 but in httpd.conf it was trying to load php 5 so by commenting out that line my problem was solved. 在我的情况下,我已将php更新为php 7,但是在httpd.conf中,它试图加载php 5,因此通过注释该行可以解决我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM