Jump to content
moriahcgibbs

How do i run a local PHP server on a Mac?

Recommended Posts

I cant figure out what im doing wrong. Ive tried using a MAMP server but the only way my PHP documents would run is when i would open them through Netbeans, witch was really a pain. If i tried to open them in a browser without going through Netbeans they would always come out as plain text. I cant seem to uninstall MAMP for some reason and so I cant just use the PHP server already installed on macs. Its really frustrating. Im thinking pf just wiping my computer and starting over. I think something that I perviously downloaded is causing this but i cant figure out what. Am I just making some obvious mistake or could there be something else wrong? All I need is a private server for developing purposes.

  • Like 1

Share this post


Link to post
Share on other sites

MAMP works fine on OSX without having to use Netbeans. Some obvious questions to that point are1) did you follow the installation isntructions correctly?2) are saving your files in the Applications/MAMP/htdocs folders?3) are you accessing the files ovrer localhost?4) did you make sure to start MAMP and confirm that Apache is running? Aside from that, an AMP stack is installed natively in OSX, but takes a little more work and configuration to get up and running. And you don't have uninstall MAMP to get the native Apache and PHP to run. Just make sure Apache on MAMP is not running.

Share this post


Link to post
Share on other sites

1) I followed the instructions on the MAMP website exactly2) I saved all of my php documents in the htdocs folder3) to run the files all i did was copy their file location into a web browser, but Im pretty sure i was doing something wrong there, but I couldnt find out anything by just googling it. 4) I did start MAMP and confirm that Apache was running.

Share this post


Link to post
Share on other sites

The URL in the browser needs to start with HTTP, if it doesn't then you're not going through Apache and it's not going to run the PHP code. The domain for your computer is localhost, so start with http://localhost/ and go from there.

Share this post


Link to post
Share on other sites
3) to run the files all i did was copy their file location into a web browser, but Im pretty sure i was doing something wrong there, but I couldnt find out anything by just googling it.
3) are you accessing the files ovrer localhost?
This probably your problem http://documentation...amp/first-steps
The web server starts by default on port 8888. This port must be specified when calling the local web page in the browser, e.g.: http://localhost:8888!
The benefit of MAMP is to run Apache (amongst other things), which is a web server. PHP runs as an Apache module. So you can't just open PHP filles over the filesystem. Your browser needs to have the address http://localhost:8888 when you want to run your PHP scripts although a little harder to find in their docs is where your files need to go. in the folder /Applications/MAMP/htdocs/, put a php file with just these contents in itindex.php
<?phpphpinfo();?>

And in your browser try the address http://localhost:8888/ and you should see a bunch of PHP info display on the page

Edited by thescientist

Share this post


Link to post
Share on other sites

Now my server will not start at all. I think there is another issue with the download I just dont know what it is. I tried to uninstall and re install MAMP after it stopped working, but now the My SQL server will not start at all. only the Apache server will start. I cant figure out whats wrong with it.

Share this post


Link to post
Share on other sites

Ive just uninstalled MAMP and am going to use the php server already installed on OSX by uncommenting lines in the httpd.conf file. However, when i run a script in a browser it still comes out as plain text. Im saving the files under MacintoshHD/Library/webserver/documents but they still wont run properly. I think Im probly making some really obvious mistake i just dont know what.

Share this post


Link to post
Share on other sites

Apache isn't just going to be able to guess where it needs to run. For this i have virtual hosts setup for all my local sites, so in /etc/hosts, I'll have something like this for each site

127.0.0.1	   my-site.local

and in my /etc/apache2/extra/httdp-vhosts.conf, I have this for each site

<VirtualHost *:80>   ServerName "my-site.local"   ServerAlias "www.my-site.local"   DocumentRoot "/Users/thescientist/Documents/workspace/my-site/webroot/"   ErrorLog "/private/var/log/apache2/my-site.local-error_log"   CustomLog "/private/var/log/apache2/my-site.local-access_log" common</VirtualHost>

I also make sure in the same file that Apache has access to my workspace folder, like this

 <Directory "/Users/thescientist/Documents/workspace/">   Allow From All   AllowOverride All</Directory>

then, I test everything first

$ sudo apachectl -t

restart apache

$ sudo apachectl restart

and hit this in my browserhttp://my-site.local

Edited by thescientist

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...