Help - Search - Members - Calendar
Full Version: Xamp/wamp alt. for mac?
Forums > Community Center > Technology > Tech Help
Maccabee
I have a mac now and im looking for something that will allow me to test website that use php includes without outting them ive on my server. Whats a free program that can do this? Is there something at http://www.apple.com/downloads/? And I dont get that site. How can I just view all the free downloads? hehe. thanks.

Edit:
I just saw that php and apache are actually pre installed on the mac. Who knows how to enable it? I was hoping there was a way to do it, not in the terminal but it looks like their isnt.
mipadi
Macs already have Apache and PHP. Just go to System Preferences > Sharing > Web Sharing (and check the Web Sharing checkbox). Here's a page detailing how to get MySQL installed.

Or alternatively you can use MacPorts to download, install, and update to the latest versions. (That's what I use.)
Maccabee
I take it macports is more for programming? I couldnt really figure out what it even was by reading the site.

But dang! That was easy. And I love how there is a sites folder. If I had known about this on macs I would have bought one ages ago!
mipadi
QUOTE(jcp @ Aug 14 2009, 12:06 PM) *
I take it macports is more for programming? I couldnt really figure out what it even was by reading the site.


It's a package manager (similar to BSD Ports or Gentoo Portage, and similar in spirit to apt-get on Debian Linux).

QUOTE(jcp @ Aug 14 2009, 12:06 PM) *
But dang! That was easy. And I love how there is a sites folder. If I had known about this on macs I would have bought one ages ago!


Yes. It is.
Maccabee
So, where exactly do I put the sites contents? I put a whole site that uses php into the sites folder but then when I go http://555.555.5.55/~joseph/ or http://555.555.5.55/ it doesnt actually change anything.

That isnt the actual number but I wasnt sure if it was something I needed to keep private. haha.
mipadi
QUOTE(jcp @ Aug 14 2009, 12:26 PM) *
That isnt the actual number but I wasnt sure if it was something I needed to keep private. haha.

You want to got to http://localhost/~joseph (assuming "joseph" is your username). Or http://127.0.0.1/~joseph.
Maccabee
Php files arent working. All its doing is showing the text in the file. Why is it doing this? Don't macs come preinstalled with php? there is an index.php in the sites folder but it is just showing the directory files.
mipadi
Oh, sorry. Forgot that PHP isn't enabled by default in Leopard. First, disable web sharing. Then you need to edit the file /etc/apache2/httpd.conf. Open that file, find the line #LoadModule php5_module libexec/apache2/libphp5.so, and uncomment it (remove the # mark). Then restart web sharing (to restart Apache). Should work after that.
Maccabee
ok. I was hoping there was a way to do it that didnt involve getting into those files but watevs. haha.

How exactly do I get there? I looked for a etc folder in the macintosh hd and I looked in library and system.

?
mipadi
QUOTE(jcp @ Aug 14 2009, 01:20 PM) *
How exactly do I get there? I looked for a etc folder in the macintosh hd and I looked in library and system.

?

It's hidden. You can get to it in 2 ways:
  1. Fire up a Terminal and cd into it using cd /etc/apache2.
  2. In the Finder, go to Go > Go to Folder..., and type /etc/apache2 into the dialog box.
Maccabee
I took away the # and hit command+s and it asked for the password so I entered it but when I went back to web sharing to turn web sharing back on, it was un clickable. Only bluetooth is clickable now.

nvm, I ha to unlock the settings.

Its working! Thanks :) Please dont close this yet though.
Maccabee
Do you know how I could make a "sub domain" for localhost? Often my sites need to be tested in the base directory and I dont want to have to remove one site to test out another one. Something like http://test.localhost/~joseph/
heyo-captain-jack
why not just http://localhost/~joseph/test ?
mipadi
QUOTE(jcp @ Aug 14 2009, 05:28 PM) *
Do you know how I could make a "sub domain" for localhost? Often my sites need to be tested in the base directory and I dont want to have to remove one site to test out another one. Something like http://test.localhost/~joseph/

Read this. Although I'm inclined to say just use http://localhost/~joseph/test, etc.
Maccabee
QUOTE(Buttsex @ Aug 14 2009, 06:04 PM) *

Because then the pointing of everything works differently.
mipadi
QUOTE(jcp @ Aug 15 2009, 12:06 PM) *
Because then the pointing of everything works differently.

If you're using absolute paths, then they're not going to work anyway since you're serving under ~joseph.
Maccabee
I mean when im working on a large site I dont want to have to go through every page and change <?php include("/includes/header.php") ?> to <?php include("../includes/header.php") ?> or whatever the case is. Unless I can find a script that goes through all the pages and replaces one thing with another.
mipadi
QUOTE(jcp @ Aug 15 2009, 12:17 PM) *
I mean when im working on a large site I dont want to have to go through every page and change <?php include("/includes/header.php") ?> to <?php include("../includes/header.php") ?> or whatever the case is.


Right, I know... But if you're serving under localhost/~joseph, /includes/... isn't going to work anyway, it'd have to change to /~joseph/includes.

QUOTE(jcp @ Aug 15 2009, 12:17 PM) *
Unless I can find a script that goes through all the pages and replaces one thing with another.

You can. It's called "awk" or "sed", and it comes with your Mac.
Maccabee
QUOTE(mipadi @ Aug 15 2009, 11:22 AM) *
Right, I know... But if you're serving under localhost/~joseph, /includes/... isn't going to work anyway, it'd have to change to /~joseph/includes.
You can. It's called "awk" or "sed", and it comes with your Mac.

Are you for freaking serious? They have all these hidden features!
heyo-captain-jack
They're not hidden.
mipadi
QUOTE(jcp @ Aug 15 2009, 12:26 PM) *
Are you for freaking serious? They have all these hidden features!

awk and sed are standard utilities on Unix, and Mac OS X is a Unix, so they're not really "hidden" per se.
Maccabee
Well I didnt know about them. haha. How do I use them? I cant find them in spotlight.
mipadi
They're command-line programs -- you call them from the Terminal.

Here's a quick bash script to do what you want:

CODE
#!/bin/bash

for f in ~/Sites/**/*.php; do
  sed 's_/includes_../includes_' < $f > "${f}.new"
  mv "${f}.new" $f
done


Or Ruby, if you prefer:

CODE
#!/usr/bin/env ruby

def fix(file)
    tmp = File.open "#{file}.tmp", 'w'
    File.open(file).each do |line|
        s = line.gsub %r{/includes}, '../includes'
        tmp.puts s
    end
    tmp.close
    File.rename tmp.path, file
end

def getfiles(path)
    Dir.foreach(path) do |f|
        if File.directory? f
            getfiles f unless f =~ /^\.\.?/
        else
            fix "#{path}/#{f}" if f =~ /\.php$/
        end
    end
end

if __FILE__ == $PROGRAM_NAME
    getfiles File.expand_path '~/Sites'
end
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.