Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

I still, after months of trying, cannot figure out how what brackets wants for the base url to live preview php file.

I am trying to figure out what the live preview base url is for Brackets so I can work on php files. The file and folder is in my documents (I have put it htdocs also, doesn't help). It's set to php at bottom right corner also. I am on a mac running High Sierra. MAMP is directed to the correct folder.

For base url i have tried:

/ http://localhost/ users/(my home folder)/Documents/Sites/testsite/index.php

None of the above work.

I have watched the setting up local development course which goes through MAMP setup. But, it does not tell me what the BASE URL for live preview is suppose to be.

I have also tried Using Atom with "atom-live-server" package. When I view in browser all i see is:

~ /

index.php

When i click on index.php I see nothing. I am asked to save the file.

I am at a complete loss.

6 Answers

Yes, i have my port to 80 which i also tried.

I am also trying various packages in Atom. I can't see to get one to open a php file in browser. Atom live server opens ~/ index.php

index.php is the file i want to view but when i click on it it just wants me to save it.

I am at a loss.

Alena Holligan
STAFF
Alena Holligan
Treehouse Teacher

First let's make sure MAMP is set up the same for both of us.

Under "Preferences" > "Web Server", my "Document Root" shows

Macintosh HD > Applications > MAMP > htdocs

So my index.php file is stored in that location.

Under the "Ports" tab, I chose "Set Web & MySQL Ports to 80 & 3306" so my ports are

Apache Port: 80
Nginx Port: 80
MySQL Port: 3306

Now, after starting the server, I can click "Open WebStart page". That takes me to http://localhost/MAMP

From there I click "My Website", which takes me to http://localhost and shows my index.php file

Alena Holligan
Alena Holligan
Treehouse Teacher

To make this work with Brackets Live Preview there are two steps

  1. In Brackets under "File" > "Project Setting", the Live Preview Base URL should be http://localhost/
  2. You MUST have MAMP servers actually started

This should allow you to go to "File" > "Live Preview" and pull up the site. HOWEVER it's not actually LIVE. No changes to your php file will show until you refresh the browser. So this is the same as just pulling up http://localhost/ in your browser. This is all that Brackets supports.

Yes I do get all of that. I am trying to figure out why I can't seem to get a code editor to live preview .php files. In brackets it wants the base url which I can't seem to figure out what it wants as stated in my post. In Atom, it opens the browser, but again not to anything useable. So, if I should just be typing in the location (independent of a code editor's live preview function) then that is what I need to know. If, however, I should be able to use live preview (for php files) then I would like to know what I am doing wrong.

Thank you.

Alena Holligan
Alena Holligan
Treehouse Teacher

I added a comment above with more on Brackets, but I wanted to make sure I addressed your question about "live preview". Client side code such as CSS and browser based javascript are the only things that will work with a "live preview" because the are only run in the browser. NodeJS and PHP are server side and will only update when the browser is refreshed.

I did try what you suggest with Brackets (and MAMP) running. It does not work. It keeps asking for base url (and that apparently is not what it wants).

Thanks.

Melissa

Thanks your your reply. I will just go about doing it as I am. I appreciate your time in responding.

Melissa