localhost/~username/ not working - macos

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".
here are the files i had been messing up
(sudo apachectl configtest : Syntax OK )
httpd-userdir.conf file
https://www.dropbox.com/s/3zmuc2jetpo3i0i/httpd-userdir.conf?dl=0
httpd.conf file
https://www.dropbox.com/s/vlrzqr95ge2qy3c/httpd.conf?dl=0
username.conf file
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
)

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. I've had a deadline and I had to finish the site, so this worked for me.
Go to httpd.conf change
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.
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.
Whatever it says in your file modify to this (that should be true for ALL configurations of the 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.

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.

Related

Laragon auto Vartual host file gets reset on refresh

hi I have many sites that I want to test on local, so when I edit the files on auto virtual host files under Apache->sites-enabled->file name, after reloading laragon, the file resets to its original default contents, ex-
Original
<VirtualHost *:80>
DocumentRoot "C:/laragon/www/cast.see.tech/public"
ServerName cast.see.tech.test
ServerAlias *.cast.see.tech.test
<Directory "C:/laragon/www/cast.see.tech/public">
AllowOverride All
Require all granted
</Directory>
edited
<VirtualHost 192.168.1.101:80>
DocumentRoot "C:/laragon/www/cast.see.tech/public"
ServerName cast.see.tech.test
ServerAlias *.cast.see.tech.test
<Directory "C:/laragon/www/cast.see.tech/public">
AllowOverride All
Order Deny,Allow
Allow from all
Require all granted
</Directory>
I cannot save any rules, any code, it comes back to its default original content once I restart laragon server. I am using windows 11, but the same problem I face on windows 10 also.
I tried uninstalling and installing back, but still no luck. Currently i am using latest version of laragon 5.0.0 210523, I also tried downgrading the version but still the same problem. Is it a windows issue or do I need to do something else. Please help me with this issue.
Each project has each own Virtual Host file located in:
For Apache:
{LARAGON_ROOT}\etc\apache2\sites-enabled\auto.{project}.test.conf
For Nginx:
{LARAGON_ROOT}\etc\nginx\sites-enabled\auto.{project}.test.conf
Content of a .conf file is auto generated. If you have a specific project which has modified content, just remove the auto. prefix from config file names eg : auto.example.test.conf => example.test.conf , Laragon will keep the content of the .conf file intact.
Virtual Host content is configurable, you can change it by modifying the template in:
{LARAGON_ROOT}\usr\tpl\VirtualHost.tpl
https://laragon.org/docs/pretty-urls.html
Laragon uses a template to auto-generate the virtual hosts.
On windows, the file is located at C:\laragon\usr\tpl\VirtualHost.tpl, assuming you installed it in C:\laragon.
Just edit this file and make the changes you want.
Keep in mind that all your sites will now use the same configurations.
One change I personally make is to remove the *. from ServerAlias, as I use subdomain format for my sites. Before I remove it, subdomain.example.com would always redirect to example.com.

Cannot get site loaded with Apache on Mac

I'm running El Capitan and trying to get my website hosted locally for development with Apache (that came with the OS). I followed the instructions here exactly. I made an anthony.conf file and put the Directory text in there, I replaced the actual directory with /Users/anthony/dev/web/unfinished-asteroids/ and then placed my web files in there. I started apache and navigated for localhost/~anthony but I get the
Not Found: The requested URL /~anthony was not found on this server.
standard 404 error. When I navigate to localhost it works fine and I get the "It works" from the index.html that is located in /Library/WebServer/Documents, I even changed that index.html file and it works fine.
Any ideas why I'm not able to see my website using apache? All I did was download this github repository and place it in my unfinished-asteroids folder, the index.html is at the root.
So it looks like there are a couple of extra steps that you need to do. There isn't really anything too special about apache that comes with OSX, so your standard apache configurations will work. but to get Userdir (~username) working on El Capitan,this is what I had to do
Edit /etc/apache2/httpd.conf
on (or near) line 166, uncomment
loadModule userdir_module libexec/apache2/mod_userdir.so
then on line 493 uncomment
Include /private/etc/apache2/extra/httpd-userdir.conf
then edit file /etc/apache2/extra/httpd-userdir.conf
uncomment line 16
Include /private/etc/apache2/users/*.conf
then in /etc/apache2/users/anthony.conf
<Directory "/Users/anthony/Sites/">
Options Indexes MultiViews
Require all granted
</Directory>
then sudo apachectl restart
That should make http://localhost/~anthony point to your sites directory.
Logs are stored in /var/log/apache2
Now if all you want is web access to say your dev directory you can do something like this.. (don't make any of the changes listed above)
in /etc/apache2/other/ create a file called mydev.conf (name doesn't really matter, save it needs to end in .conf')
and put this in that file
Alias /dev /Users/anthony/dev/
<Directory "/Users/anthony/dev">
Options Indexes MultiViews
Require all granted
</Directory>
and reload apache (sudo apachectl restart)
then you will be able to access your dev folder at http://localhost/dev and should be able to access your page at http://localhost/dev/web/unfinished-asteroids/
you can adjust the paths at will above, just need to make sure that the user or group _www has access to it, and that paths in the alias and the directory match.

OSX El Capitan - Apache 403 Forbidden

I just upgraded from Yosemite to El Capitan but unfortunately forgot to copy my old httpd.conf and now i need to configure all of its settings again.
I already changed the documentroot to the previous one /users/admin/www, and also configured to release access to this folder:
<Directory "/users/admin/www">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Restarted Apache but even this way I get the 'Forbidden' error when trying to access 127.0.0.1.
What am I'm missing here?
Do the following:
Open Terminal
Run:
cd /etc/apache2/
sudo mv httpd.conf httpd.conf.OLD
sudo mv httpd.conf~previous httpd.conf
sudo apachectl restart
After spending 3 hours on the issue - this worked for me!
I just found out that the old .conf file is saved during the El Captain update, in this folder :
/private/etc/apache2/httpd.conf.pre-update
So i just copied the old definitions to the new one :)
You can navigate to /private/etc/apache2/ and then diff httpd.conf httpd.conf.pre-update to see the differences between your old conf file and the new one that's been added.
For me there was a lot of LoadModules lines commented out, and my apache user/group had been changed back to _www
I am not familiar with the changes in Apache 2.4 so this one really stumped me for about 30 minutes. I just upgraded from Mavericks to El Capitan (Apache 2.2 to 2.4) and I could not load my personal Sites directory (http://localhost/~{username}. I kept getting "Forbidden". After a good bit of research I found that I needed to modify /etc/apache2/users/{username}.conf to add "Require all granted". Since I never upgraded to Yosemite (which also uses Apache 2.4) I never stumbled across this one.
I hope this info helps somebody
Updating the directory access control worked for me:
In this example, all requests are allowed.
2.2 configuration:
Order allow,deny Allow from all
2.4 configuration:
Require all granted
Source: http://httpd.apache.org/docs/trunk/upgrading.html (under Access control)
Note: I keep my custom settings separately under /private/etc/apache2/other/.
This helped as well (after doing everything else as well):
http://coolestguidesontheplanet.com/forbidden-403-you-dont-have-permission-to-access-username-on-this-server/
Like #delphirules said, you can copy your old httpd.conf file like so:
sudo cp /etc/apache2/httpd.conf.pre-update /etc/apache2/httpd.conf
I’ve had issues with connecting to my localhost all day but finally found this: https://mallinson.ca/web-development-with-el-capitan/
Just run the copy command and then do a sudo apachectl restart
I’ve also disabled the SIP ( System Integrity Protection ) in recovery mode. I don’t know if it actually did anything though.. You can find those instructions here: https://forums.developer.apple.com/thread/3981
I had a similar issue receiving a 404 error back when trying to access pages in my local sites directory after enabling myself at the user level to serve sites after upgrading to El Capitan. The issue was that Apache reset the httpd.conf file to its default which disables the user folders to load files from. So http://localhost loaded fine but http://localhost/~username/index.html would NOT load. Here's the fix:
back up the "new" config file that was created:
sudo cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf_capitan
restore the "old" config file that was renamed:
sudo cp /etc/apache2/httpd.conf~previous /etc/apache2/httpd.conf
In case you have symlinks to some of your projects in DocumentRoot directory, after upgrade to El Capitan you can get 403 for these projects, like I did.
You will need the following things to make them work again:
1) Your apache user (_www by default) should have execute access to directory that houses a directory to which you link to.
In my case in apache DocumentRoot I had:
MyProject -> /Users/Me/Documents/Aptana Studio 3 Workspace/MyProject
And for some reason access settings for
/Users/Me/Documents/Aptana Studio 3 Workspace/MyProject
were
-rw------- 1 Me staff My guess it was set during OS x upgrade.
So after sudo chmod 755 Aptana\ Studio\ 3\ Workspace error was resolved.
2) As upgrade also changes httpd.conf, make sure you have this for DocumentRoot directory, or restore from backup httpd.conf as suggested above:
Options Indexes FollowSymLinks
If you upgraded from Mavericks or earlier OS x and restored backup httpd.conf, you should, as jcfranko said, replace apache 2.2 setting for request allowance with:
Require all granted
Create a symlink in your /Users/{user name}/Sites folder
ln -s /Path/To/Target/Files /Users/{user name}/Sites/{name}

Apache 403 when hitting name.local Yosemite

This is the first time I'm setting up an apache web server, I'm doing this on my Mac with OS X Yosemite. For some reason I'm receiving 403 errors when I try to hit my user directory via the browser with the formate computerName.local. When I hit the default directory with that same format I get the "It works!" page, but when I try to hit my user directory it gives me the "Forbidden" error... If I hit it with localhost everything works fine, but I'm trying to hit it from my iPhone hence the localhost won't work from there...
I've tried every guide I could find, tried setting the vhosts configuration file (but when I do so the browser can't reach the folder even when trying localhost), I tried changing the httpd.conf file to have "Require all granted" on a new with the path to my user sites directory... Can anyone tell me if I'm doing something wrong? If you need I could upload my httpd.conf and httpd-vhosts.conf files (or any other related file that may need configuration).
Thanks!
Found the issue. It took me a while but it was really simple at the end. On my User conf file /private/etc/apache2/users/USERNAME.conf there was a line that was absolutely responsible for the behavior that from localhost everything worked fine but from computerName.local it wouldn't. This is what the file looked like:
<Directory "/Users/Santiago/Sites/">
AddLanguage en .en
LanguagePriority en fr de
ForceLanguagePriority Fallback
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from localhost
Require all granted
</Directory>
All I had to do was change that "Allow from localhost" to "Allow from all" and restart apache. Everything works now.

Apache localhost 403 error with Yosemite

I've just installed Mac OS X Yosemite fresh. I configured Apache and chmodded "users/user/Sites" to 755. When I hit localhost I receive a 403 Forbidden "You don't have permission to access / on this server". The same thing occurs with any other sites I add to my hosts file.
I tried configuring user directories following help from this post. The guys on this MacRumors thread know there is an Apache issue, but didn't offer a lot of suggestions.
My directory permissions look like this
drwxr-xr-x 29 root wheel 1054 Aug 11 07:30 /
drwxr-xr-x 6 root admin 204 Aug 11 07:29 /Users/
drwxr-xr-x+ 26 zachshallbetter staff 884 Aug 11 11:57 /Users/zachshallbetter/
0: group:everyone deny delete
drwxr-xr-x 5 zachshallbetter staff 170 Aug 11 10:16 /Users/zachshallbetter/Sites
Can anyone offer any suggestions or help? Here are links to my hosts and httpd.conf files and error logs for reference.
You do NOT want to open up the entirety of your hard drive to the web server process. In fact, lines 215-217 of httpd.conf say:
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
Apache 2.4 (OSX 10.10 Yosemite) has a different structure from Apache 2.2 (OSX 10.9) for the Directory directive in Module mod_authz_core.
EDIT: If you are setting up Apache from the START, please follow this instruction set to setup apache and php on OSX 10.10 Yosemite.
Assuming you have mod_userdir.so enabled already, your problem is within your user .conf file (/etc/apache2/users/username.conf), edit (or add) the following.
Apache 2.2:
<Directory "/Users/jnovack/Sites/">
Options Indexes MultiViews
AllowOverride All
# OSX 10.9 / Apache 2.2
Order from deny, allow
</Directory>
Apache 2.4
<Directory "/Users/jnovack/Sites/">
Options Indexes MultiViews
AllowOverride All
# OSX 10.10 / Apache 2.4
Require all granted
</Directory>
Edit the file:
/private/etc/apache2/httpd.conf
on line 250 (in Yosemite) change:
Options FollowSymLinks Multiviews
to:
Options FollowSymLinks Multiviews Indexes
then in the Terminal run:
sudo apachectl restart
This might be very late answer but i did followed most of Stack Overflow solutions, None of them helped me for various reasons. So i did reset my device as a fresh Yosemite OS to get this localhost working on Mac Yosemite (with Symlinks too),
Steps I did exactly :
sudo nano /etc/apache2/httpd.conf
Uncomment the following lines:
#LoadModule php5_module libexec/apache2/libphp5.so
to
LoadModule php5_module libexec/apache2/libphp5.so
#LoadModule userdir_module libexec/apache2/mod_userdir.so
to
LoadModule userdir_module libexec/apache2/mod_userdir.so
#Include /private/etc/apache2/extra/httpd-userdir.conf
to
Include /private/etc/apache2/extra/httpd-userdir.conf
Save and Exit (Ctrl+X press Enter and press Y and enter again)
sudo nano /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 (Ctrl+X press Enter and press Y and enter again).
Now go to apache Users folder to check your configuration file exist or not
cd /etc/apache2/users/
if you do not have configuration file in this folder, create one by
sudo nano /etc/apache2/users/<**YOUR USERNAME**>.conf
Replace <YOUR USERNAME> with the name of your machine (type whoami in terminal and enter that name).
after creating .conf file , copy below lines into that file
<Directory "/Users/<YOUR USERNAME>/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>
save and Exit
Now restart your apache
sudo apachectl restart
Now go to your browser and type localhost, it should work as expected,
Just as a Note: if it does not work even after try restarting your computer
create index.html as exactly index.html.en that you should find here:
open /Library/Webserver/Documents/
right click on index.html.en and duplicate it to index.html leaving original as it is
try again in browser and if you have success, you can delete the duplicated file
Just to be clear, leave the original file index.html.en where it is, untouched and unharmed throughout this step.
Not sure why I had to take this mysterious detour - probably something local to my machine, but if you're having trouble after following the guide above, see if it helps.
SymLinks :
if you have success, in Browser you should see
It works!
Now create symlink to any your project.
ln -s <Path_to_your_Project(index_file)> <Path_to_webroot>
For example if you have project folder in your Documents folder ,then point webroot to your index file by
ln -s /Users/<YOUR USERNAME>/Documents/project/ /Library/Webserver/documents/projectlink
you might need permission to create symlink (Use above command with Sudo)
Configure apache to follow symlinks ( Thanks to tomvon, i do not enough points to vote you)
sudo nano /private/etc/apache2/httpd.conf
on line 250 (in Yosemite) change:
Options FollowSymLinks Multiviews
to:
Options FollowSymLinks Multiviews Indexes
then in the Terminal run:
sudo apachectl restart
Now go to localhost/projectlink to see if your project index file shows here on browser.
Happy Coding..
The advice in this article helped me.
Specifically the "Yosemite Only" section:
First, there is a directive that helps secure your machine by denying access to the entire file system by default. I’ll show you how to remove this directive, since I find that easier on a machine meant for development. The section of code runs from line 220 through 223. You can comment out (place ‘#’ in front of each line) or just remove this section.
And the section is ...
<Directory />
AllowOverride none
Require all denied
</Directory>
Note:
As others have followed up on this with more details, the method outlined above can be insecure.
There are 2 possibility why your localhost is forbidden, first it may be because your apache setting is not correct and second, may be because you set vhost and you forget about set localhost too
sudo nano /etc/apache2/extra/httpd-vhosts.conf
Add this code
`
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Users/username/Sites"
<Directory "Users/username/Sites">
Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all
</Directory>
</VirtualHost>
Save it and restart your apache
`
sudo apachectl restart
it should be works :)
Suggestions might focus on your own user specific conf in apache but by default this configuration might not be loaded at all.
Edit the userdir module configuration:
sudo vi /etc/apache2/extra/httpd-userdir.conf
Uncomment the include of the user directory configuration files:
Include /private/etc/apache2/users/*.conf
Make sure you have a user directory configuration according our own username:
sudo vi /etc/apache2/users/.conf
Make sure you have good configuration for your home directory:
DocumentRoot "/Users/<username>/Sites/"
<Directory "/Users/<username>/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
Restart apache (webserver)
sudo apachectl restart
Check your site!
Just create the 'Sites' folder in your user folder. Go to
cd ~
mkdir 'Sites'

Resources