Forum Moderators: phranque

Message Too Old, No Replies

Installing MAMP on Mac

simple question

         

Lorel

9:21 pm on Oct 27, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I intalled MAMP on Mac 10.7.x and it is working and I can see the localhost:8888 page.

However it appears that you need to know php in order to do anything. Is this true? I don't write php. All my websites are in .htm or .html

So does this mean I can't use MAMP?

I need a local server so I can view sites with extensionless urls.

penders

9:57 pm on Oct 27, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As you are no doubt aware, MAMP includes the Apache web server - probably the same web server you've been deploying on for years. (?) If you "don't write PHP" then don't write PHP, just write your ".htm / .html" pages the same as you have always done.

Lorel

12:08 am on Oct 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, I've only worked on Apache servers. However, I've just watched multiple video Tuts on installing and using MAMP (and LAMP, WAMP etc.) and they all talk about using php, and thus I'm confused as to how to get this started. Do I just load my website or will this require a tutorial also?

lucy24

1:47 am on Oct 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



penders, I think the question was meant the other way around: "I installed this pseudo-server, but now they're scaring me with this php talk."

lorel, if your pages include any php content, you can't view them by ordinary local means like a text editor's html preview, or opening an html file in a browser. You need a server of some kind, and that's where MAMP-or-equivalent kicks in. Sometimes it can go either way. I mainly use php for navigation headers/footers, so if I open the page by other means, it's missing a few pieces but the rest looks as intended.

Other small differences:
-- links to /directories/ (final slash) work as intended, instead of taking you first to a directory-index page.
-- conversely, site-absolute links with leading /slash work as intended, so you can code your pages correctly (no http: links and no ../../ links) and still navigate from one directory to another.

So it's more that once you've got MAMP, it will be much easier to experiment with php if & when you do decide to dabble in it. If you're going to see the White Screen Of Death -- and you will ;) -- you would much rather see it on your own machine where nobody but you need ever know.

If you have more than one site, there are some relatively simple tweaks that will let you run multiple sites on MAMP without having to install the fancy version. On my computer, it means for some reason that I have to enter my System password about every other time I shut down (and, this morning, also at startup-- new one on me!). But that's a small adjustment.

Just remember: always make a copy of the config file before you so much as breathe on it! And you will want to change one thing: allow overrides in the directory where your www sites live, so you can maintain an htaccess file that almost exactly matches what you use on the live site. (Er ... you are on shared hosting right?)

Samizdata

2:41 am on Oct 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I need a local server so I can view sites with extensionless urls.

All versions of OSX have an Apache webserver built in.

On OSX 10.7 just turn on Web Sharing (in System Preferences > Sharing) and you will be up and running.

If you are trying to mimic a webhosting account you will need to configure Apache to allow .htaccess overrides, and for this you will want to use Terminal.

Plenty of tutorials out there, it's pretty straightforward.

...

Lorel

5:00 pm on Oct 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@ Lucy, yes you interpreted my question correctly :)

I don't write php. Does this mean I don't need mamp? Penders seems to indicate that MAMP will accept html files.

@samizdata. I turned on web serving although I have no idea on what to do from there. I'll look for tuts on how to set this up.

Lorel

5:14 pm on Oct 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ok, that took about 5 minutes to figure out I"m not looking for a server on my computer to host websites.

All I want is to be able to work on websites with extensionless URLs on my computer, which I understand requires MAMP. Yes? Once I get the website and htaccess redirects for extensionless urls working correctly I intend to load on the client's server.

Samizdata

5:29 pm on Oct 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I turned on web serving although I have no idea on what to do from there

On the screen where you turn it on there should be two URLs.

One points to content in Library/Webserver/ and the other points to content in Users/~username/Sites/

Essentially you replace files in those locations with your own.

Note that a file named .htaccess (which as I understand it is what you mostly want) will be "hidden" on a Mac due to the leading period, a workaround is to name a copy -htaccess while you are setting things up.

The only truly nerdy bit is editing the Apache configuration files (ending in .conf) to allow you to use .htaccess files - this is usually done with a text editor via Terminal, so search the web for "osx 10.7 htaccess" or similar.

As you are not using PHP, MySQL and all the other possible goodies that Apache can work with, your learning curve should be gentle enough, and limited to very basic nerdiness.

...

Samizdata

5:38 pm on Oct 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



All I want is to be able to work on websites with extensionless URLs on my computer, which I understand requires MAMP. Yes?

Requires, no.

You can use MAMP if you prefer (the AMP stands for Apache-MySQL-PHP/Perl).

To test extionless URLs you only need to run a local Apache webserver configured to AllowOverrides (from .htaccess).

You don't have to make your local sites available to the outside world, and probably shouldn't.

If you use a router it would require extra steps anyway.

...

not2easy

5:40 pm on Oct 28, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



If you use BBEdit on OSX 10.7.x you can see and edit .htaccess files. I seem to remember I needed to ask for a workaround a few upgrades ago, it still works.

lucy24

6:06 pm on Oct 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I seem to remember I needed to ask for a workaround a few upgrades ago, it still works.

Similar here. Thanks to OS changes, I now have to do some extra jiggery-pokery to make leading-dot files visible in SubEthaEdit's Open dialog.

lorel, note that we're talking about two different things under the name "htaccess". One is the backup copy of the htaccess that you upload to your live site. I call mine by site-specific names like "htaccess_gs", "htaccess_shared" and so on-- no leading dot-- and rename them when uploading. The other htaccess is the one that is actually used by the MAMP installation. Since some things behave differently in htaccess than in config, and since changing the config file requires a server restart-- in MAMP, that means a single mouse click and wait two-three seconds-- I find it most practical to stick with htaccess.

There is one key difference between a local htaccess and a live htaccess. On a live site, any redirect (flag containing [R]) should include the full protocol-plus-domain: http://www.example.com/blahblah. On your local site, redirects within the same domain should start with / slash only; otherwise the browser will go out into the world, just where you don't want it to be.

penders

7:08 pm on Oct 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



penders, I think the question was meant the other way around: "I installed this pseudo-server, but now they're scaring me with this php talk."


Yep, that's what I thought I was answering. :) The scary PHP talk is just a red herring.

Lorel

8:41 pm on Oct 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have MAMP loaded and its working. I loaded the website and I can see the files by going into MAMP/htdocs, however, htaccess is not working due to the missing dot (thanks Lucy24). However I can't edit it using FTP or BBedit or the finder (using get info). Can someone tell me how to do this (I have show hidden files turned on).


@lucy24
Are you saying that every time I want to test htaccess on a local host that I have to change all the relative URLs so they begin with a slash?
This sounds like an unsurmountable process taking them on an off any time I want to test htaccess.

I can't test it yet however, as htaccess is not working.

@not2easy:
I use BBedit. Are you saying BBedit has a localhost type set up so I can see if htaccess rewrites for extensionless urls are working before loading it on the web?

not2easy

9:01 pm on Oct 28, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



BBEdit can work with your localhost environment and there are command line tools and a lot of capabilities I never have touched, I use it as an editor (and validator) for css, html and flat files. It has great regex search tools that have saved me tons of time - find and replace multiple lines across hundreds of pages or multiple folders with one click to make your 'unsurmountable process' a piece of cake. But for .htaccess files I only use it as a text editor. I don't know of a way to test rewrites without "trying it out" on Apache.

Lorel

3:27 pm on Oct 29, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




How to add the dot to htaccess while in MAMP?

I do this with FTP on the web server all the time, but using FTP to get to the site I'm working on within MAMP / htdocs (in client folder), the files are grayed out and not available. I can see the htacces without the dot but can't access it. I have show hidden files turned on in FTP.

Is there something else I need to do first?

not2easy

3:49 pm on Oct 29, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



have you tried naming it htaccess.txt? Then it may be accessible to rename.

lucy24

6:37 pm on Oct 29, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How to add the dot to htaccess while in MAMP?

You don't do it from within MAMP. Rename the actual file. But if you've currently got a visible version, it's probably more appropriate to open it in your text editor and do a "Save as..." with the new name. Or copy the file from the desktop and rename the copy.

Yes, you'll need to maintain two htaccess files. But the major editing-- the part where you replace
http://www.example.com/
with
/
alone-- only needs to happen once, and that's a global replace. Note too that this only applies to redirects. In practice you won't get redirected all that often on your local site, since you yourself already know the correct URLs, and of course all your links point to the intended URL. (Ahem. They do, don't they?) It's good insurance, though, in case you've overlooked something.

On your local htaccess you can also omit any access-control rules, since Ukrainian robots will never get near your personal computer. The main thing that will be the same is any rewrites, like the extensionless URLs that started this discussion. Those will look identical in live and local htaccess.

:: quick detour to check ::

On my primary site, the full htaccess is about 18k while the MAMP version is 9k or about half that size-- and that's not including a further 20+k of shared htaccess, which I don't need for MAMP at all since it's just about headers and access control.

There's a very simple toggle called HiddenWay that turns dot-file display off and on in the Finder. I've used it in both 10.6 and 10.9 so it should work for you. Faster and easier than just about any other possible approach.

Lorel

10:49 pm on Oct 29, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I opened the current htaccess located in my client file (not in MAMP, with my text editor (BBedit) then tried to save it with the dot and the finder will not let me do it.

I then opened Mamp/htdocs/client and at the same time opened the active website via FTP and drug the current htaccess file with the dot into that folder. However I can't tell that it did anything. And even if it did it would be invisible and then I couldn't edit it.

If MAMP is needed to test extensionless URLs on your computer, they why aren't there instructions on how to load the htaccess file, which is necessary to accomplish this task? I've spend hours and hours searching for the answer and can't find this being discussed anywhere.

There are plenty of discussions on editing the conf file however. I didn't want to do that until an apache expert on this forum tells me it's truly needed however.

phranque

11:17 pm on Oct 29, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



why can't you simply use shell commands?

mv(1) Mac OS X Manual Page:
http://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/mv.1.html [developer.apple.com]

lucy24

12:16 am on Oct 30, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



the finder will not let me do it.

Are you sure? As I remember, you get a special alert warning that the file will be invisible, but you just have to keep insisting yes, yes, I really mean it. That's in both 10.6 and 10.9; I can't imagine it being different in 10.7. Unless it was one of those short-lived changes they soon thought better of.

:: detour to check ::

Yup. There's an extra alert about "reserved for use by the system" but just click
use '.'
(it's in place of the default "Yes") and you're good to go.

:: now off to delete the file I just created ::

Incidentally, you don't have to use an htaccess file. You can edit the config file itself. That's what people do if they're big enough to have their own servers. But editing the config file is admittedly a lot scarier-- and may not even be the best approach if your live site uses htaccess.

why can't you simply use shell commands?

phranque, please ;) "simply" and "shell" have no place in the same sentence.

Lorel

3:38 pm on Oct 30, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't know why I didn't see the "use'.'" note before. That worked.

I loaded the htaccess with just enough for the includes to work and they are working. Next I'll check out the extensionless url rewrites.

Thanks for your help Lucy

@phranque I'd have to retire from web design before tackling using htaccess in Conf files. At least not till I learn how to write Perl or whatever language is involved. I took one quarter of programming in college -- just enough to be dangerous!

lucy24

6:01 pm on Oct 30, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



At least not till I learn how to write Perl or whatever language is involved.

No language. The config file looks exactly the same as htaccess, using exactly the same commands. The only difference is that, well, it's called the config file.

In fact, go do this right now. Find your config file in MAMP:
Applications > MAMP > conf > apache > httpd.conf
It's in the same place, regardless of where you keep your site files. Make a copy of httpd.conf in the Finder. Open the copy in the text editor of your choice. (In SubEthaEdit there's a third-party add-on mode that color-codes for apache, so the comment lines are visually distinct. Don't know about other editors.) You'll see
(1) zillions of comment lines with leading # just like in your htaccess.
(2) a lot of indented sections beginning and ending in either <Directory> or <IfModule...>
(3) what's left over is identical to what you're used to seeing in htaccess.

phranque

12:25 am on Oct 31, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



for your purposes, the main difference between httpd.conf and .htaccess is outlined here.

RewriteRule Directive:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
What is matched?

In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (e.g. "/app1/index.html").

In Directory and htaccess context, the Pattern will initially be matched against the filesystem path, after removing the prefix that led the server to the current RewriteRule (e.g. "app1/index.html" or "index.html" depending on where the directives are defined).

phranque

12:31 am on Oct 31, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the shell commands can be run from the Terminal application and would be useful to rename the file to .htaccess.
the shell commands are part of the bsd operating system, not the apache web server.

Shell Scripting Primer: Command Line Primer:
http://developer.apple.com/library/mac/documentation/OpenSource/Conceptual/ShellScripting/CommandLInePrimer/CommandLine.html [developer.apple.com]