Local web page programming on a Mac

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 1K views
Messages
1,753
Reaction score
143
I'm used to Windows. I open notepad or wordpad and type
<html>
Hello world
</html>
and save it as a .txt file with an .html extension.

How do I do this on a Mac?
It seems the free included text editor is called textEdit.
But it does not allow me to save as a simple txt file with an .html extension.
I can choose .html as the file type, but it doesn't execute my code as a web page. It just echos my code back to me when I open the file in a browser.
 
Physics news on Phys.org
DrClaude said:
You can save it as a txt file, then change the extension.

I suggest you install and use Emacs.
The problem is that .txt is not in the dropdown list of file types on the Save interface.
I'd have to get the IT guys to install software since this is my work computer. So I'm looking for a simple way to do it with the Mac's default programs.
 
tony873004 said:
The problem is that .txt is not in the dropdown list of file types on the Save interface.
In the Format menu, choose "Make Plain Text". It converts to plain text and will save automatically with an extension .txt.
 
DrClaude said:
In the Format menu, choose "Make Plain Text".

To make plain text (instead of rich text) the default, choose TextEdit --> Preferences --> New Document, and click the "Plain Text" button.

By the way [for the OP] your Mac already has Apache installed, so you can see how a web server delivers your pages. If you're using Mac OS 10.8 or later, launch the Terminal application (it's in Applications --> Utilities), give the command 'sudo apachectl start' and give your administrator password if requested.

In older versions of Mac OS 10, there is a "Web Sharing" item in the Sharing section of System Preferences which does the same thing.

Then create a folder named Sites in your top-level (home) folder: /Users/yourusername/Sites. This is the equivalent of the public_html folder that Apache usually uses for users' home folders on Linux/Unix systems.

A file named index.html in the Sites folder has the URL http://localhost/~yourusername/ . A file named hello.html would have the URL http://localhost/~yourusername/hello.html . And so on.

I maintain my website by keeping a complete copy on my Mac. I add new pages and images there first, test them, and then upload them to my public web site. This automatically gives me a complete backup of my website in case my web-host crashes or disappears. This came in handy when my old web-host at my college crashed and they decided not to continue having a public web server for faculty/staff/students. I bought a domain name, found a commercial web host, fixed my backup pages a bit to remove all links to the old server, and uploaded them to the new one.
 
Last edited by a moderator: