Setting up a local web server on macOS 13 “Ventura”

When I follow etresoft's detailed instructions to set up a local webserver on macOS 13.4 "Ventura" here:


Setting up a local web server on macOS 13… - Apple Community


then type http://localhost/ in the URL bar, I get the expected


"It works!"


But when I request http://localhost/~<myshortusername>, Safari cannot find the index.html file placed in my Sites folder:


"Not Found

The requested URL was not found on this server."


Does the command:

chmod +a "_www allow execute" ~

no longer permit apache to access the Sites folder in my home directory?


Any help much appreciated!



iMac (2017 – 2020)

Posted on Sep 21, 2023 9:57 PM

Reply
Question marked as Best reply

Posted on Sep 23, 2023 8:04 AM

onyerleft wrote:

There is an index.html file in /usr/local/var/www/. Yes, I installed with Homebrew, because your instructions were unavailable at the time, and there was no alternative. I've since uninstalled Homebrew - there is nothing on my system with the word "homebrew" or "brew" in the name.

Have you tested your instructions with Ventura 13.4? Because they don't work on my system.

I've been updating that User Tip for more than ten years: Setting up a local web server on a Mac - Apple Community


I used those instructions myself to setup the web server on my new MacBook Air running Ventura 13.4.


The problem here is Homebrew. Based on my interactions with other Homebrew users here in the forums, it is not possible to uninstall Homebrew. In theory, it should be possible. But because Homebrew is pushed on people who don't know how to do advanced unix operations, those people are then unable to fix their computer when Homebrew breaks functionality like this.


I'm afraid that your best option is to erase the hard drive and reinstall the operating system. Then you can get the web server running in a few minutes and learn the command line on your own schedule.


I'm not entirely sure, because I don't know what Homebrew does, but it may be possible to restore your personal files. You just have to make sure that you restore only your user accounts and user files. Do not restore any software, apps, system settings, or "other files". That would just reinstall Homebrew.

24 replies
Question marked as Best reply

Sep 23, 2023 8:04 AM in response to onyerleft

onyerleft wrote:

There is an index.html file in /usr/local/var/www/. Yes, I installed with Homebrew, because your instructions were unavailable at the time, and there was no alternative. I've since uninstalled Homebrew - there is nothing on my system with the word "homebrew" or "brew" in the name.

Have you tested your instructions with Ventura 13.4? Because they don't work on my system.

I've been updating that User Tip for more than ten years: Setting up a local web server on a Mac - Apple Community


I used those instructions myself to setup the web server on my new MacBook Air running Ventura 13.4.


The problem here is Homebrew. Based on my interactions with other Homebrew users here in the forums, it is not possible to uninstall Homebrew. In theory, it should be possible. But because Homebrew is pushed on people who don't know how to do advanced unix operations, those people are then unable to fix their computer when Homebrew breaks functionality like this.


I'm afraid that your best option is to erase the hard drive and reinstall the operating system. Then you can get the web server running in a few minutes and learn the command line on your own schedule.


I'm not entirely sure, because I don't know what Homebrew does, but it may be possible to restore your personal files. You just have to make sure that you restore only your user accounts and user files. Do not restore any software, apps, system settings, or "other files". That would just reinstall Homebrew.

Sep 22, 2023 9:22 AM in response to onyerleft

onyerleft wrote:

When I follow etresoft's detailed instructions to set up a local webserver on macOS 13.4 "Ventura" here:
Setting up a local web server on macOS 13… - Apple Community
then type http://localhost/ in the URL bar, I get the expected
"It works!"

But when I request: http://localhost/~<myshortusername>

ref:

Now try your user home directory by entering the following into Safari's address bar:

http://localhost/~<your short user name>



? this would be :

http://localhost/~MyUserShortnameHereWithoutTheBrackets


or try

http://localhost/MyUserShortnameHereWithoutTheBrackets





I have always used MAMP without issue. it is an extremely user-friendly setup.

ref

https://www.mamp.info/en/mamp/mac/



Sep 22, 2023 4:20 PM in response to leroydouglas

Tried both

http://localhost/~MyUserShortnameHereWithoutTheBrackets

and

http://localhost/MyUserShortnameHereWithoutTheBrackets

and still "Not Found".


But since my last post, I've discovered the index.html file that displays "It works!" is located in

usr/local/var/www


- the directory to which localhost is pointing. But since it's protected I can't (easily) make changes to sites in development there.


Any idea how to point localhost at

~MyUserShortnameHereWithoutTheBrackets/Sites/?


Thanks leroydouglas


PS If all else fails I will try MAMPS but am trying to avoid third-party solutions





Sep 22, 2023 4:29 PM in response to onyerleft

I haven’t checked, lately, but it used to be hosted in /Library/WebServer/Documents.

The https.config file should have the path. If you found it to be usr/local/var/www, then I’m way behind.

I was going to suggest you use that path instead of the userdir unless you need individual per user sites.


I’m away from my Mac, so not sure, but you should be able to edit that folder by authenticating with admin user. BBEdit makes it easy to authenticate. It is free for a limited but still very powerful text editor.

Sep 22, 2023 6:24 PM in response to onyerleft

onyerleft wrote:

Thanks, yes I'm using BBEdit. Editing the files isn't a problem, it's making "/Library/WebServer/Documents/" the webserver root, i.e. localhost. Apparently internal security doesn't allow it.

What do you mean? Just edit httpd.conf and make _www the owner and group of Documents.


Setting up a secure WebServer on any platform is very difficult.

When I last took the SANS Web App Penetration course, about 50% of all web apps were vulnerable to exploit.

Sep 22, 2023 6:59 PM in response to onyerleft

onyerleft wrote:

…But when I request http://localhost/~<myshortusername>, Safari cannot find the index.html file placed in my Sites folder:

"Not Found
The requested URL was not found on this server."

Does the command:
chmod +a "_www allow execute" ~
no longer permit apache to access the Sites folder in my home directory?

Any help much appreciated!


Here are the directions: https://httpd.apache.org/docs/2.4/howto/public_html.html


The files in the per-user target directory will need to be read-accessible to the web server user; to _www.

Sep 22, 2023 10:29 PM in response to onyerleft

onyerleft wrote:

But since my last post, I've discovered the index.html file that displays "It works!" is located in
usr/local/var/www

There is no index.html file in /usr/local. This sounds like Homebrew.


When I update that document for Sonoma, I will add a disclaimer warning that my instructions only apply to the built-in software.

Sep 22, 2023 11:02 PM in response to etresoft

There is an index.html file in /usr/local/var/www/. Yes, I installed with Homebrew, because your instructions were unavailable at the time - there was no other alternative, and I've since uninstalled Homebrew - there is nothing on my system with the word "homebrew" or "brew" in the name.


Have you tested your instructions with Ventura 13.4? Because they certainly don't work on my system.

Sep 22, 2023 11:23 PM in response to onyerleft

There is an index.html file in /usr/local/var/www/. Yes, I installed with Homebrew, because your instructions were unavailable at the time, and there was no alternative. I've since uninstalled Homebrew - there is nothing on my system with the word "homebrew" or "brew" in the name.


Have you tested your instructions with Ventura 13.4? Because they don't work on my system.

Sep 23, 2023 5:56 AM in response to onyerleft

You're going to have to reset it from what homebrew did to it.


Open the /etc/Apache2 folder.

You should see an "original" folder.

Open that and copy (don't move) the https.conf and pasted it into the Apache2 folder replacing the one homebrew created.

Then, follow Etresoft's instructions to modify the config file. If you need to edit any of the files in extra, copy them from the original/extra folder into the Apache2/extra folder replacing what is there.

Sep 24, 2023 9:41 AM in response to onyerleft

onyerleft wrote:

Victory! localhost is not pointing to ~/Sites, but to Library/WebServer/Documents - fine for dev purposes. And I didn't see changes until I restarted my computer, but it looks like at least Apache is functional

Localhost points to wherever you want it to point. The instructions in my User Tip enable the user_dir module so that you can use the ~/Sites folder without having to deal with permissions issues in /Library/WebServer/Documents. You also don't have to restart.

now on to PHP and MySQL.

Please don't. It's not 1998 anymore. Those are dead-end technologies.


Running a local web server is useful to check for things like HTML, CSS, and Javascript in a real environment. But it has very limited usefulness beyond that. Even Apache itself is a dead-end. It's simply a convenience.


Setting up a real web server is much more difficult than it was in 1998. Use your local environment to build HTML and CSS web pages and debug your Javascript. To actually deploy anything, you'll need AWS. An that environment is radically different. AWS will certainly sell you a Lightsail-based server with Apache, MySQL, and PHP. But if you ever want to setup anything more complicated than your local pickleball league newsletter, it just isn't going to scale.

Sep 24, 2023 4:59 PM in response to etresoft

I configured the file <my short user name>.conf exactly as you described:


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


and localhost resolves to Library/WebServer/Documents. You can blame it on homebrew if you like, but I don't care. I will have a development platform that allows me to design not only the necessary HTML, CSS, and Javascript, but build the databases and content management systems that tie it all together.


Re: "Please don't. It's not 1998 anymore. Those are dead-end technologies."


Where does the "1998" condescension come from? I've been a full-stack programmer since the mid-1980s, working in 7 different languages (including assembly language). Though it's true I have little experience setting up newsletters, I've made a career out of creating secure, custom production management systems for industry. My clients wax ecstatic about their reliability, speed, and functionality - and until they don't, I'll probably continue to rely on those dead-end technologies, Apache/PHP/MySQL, to design, build, and test them.


Re: AWS, I wouldn't go near it. In 2012 I developed a site for a luxury womenswear franchise, and in the first week after launch it disappeared into thin air. Worse, tech support was non-existent.


Again, I appreciate your help with this issue, but ultimately we each have our own way to get the job done.

Sep 25, 2023 1:12 PM in response to Barney-15E

Not familiar with the Web App Penetration Testing class, but if it was "web apps" they were probably testing WordPress apps, which are built as add-ons to WP's PHP framework. Though the framework is secure, the third-party apps that interface with it are not.


They range from acceptable to godawful, both in terms of reliability and security. Though they've improved in recent years, unless interfacing with another system is required I write all apps I need for WP myself.

Setting up a local web server on macOS 13 “Ventura”

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.