Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Configuring PHP/SQL/Apache in OSX

Configuring PHP/SQL/Apache in OSX
Thread Tools
James L
Mac Elite
Join Date: Aug 2003
Status: Offline
Reply With Quote
Nov 7, 2003, 01:44 AM
 
Hey all,

How's things? So, I am feeling pretty comfortable with my HTML/XHTML/CSS/Javascripting/Flash skills, and I feel it is time to move on to the world of server side scripting.

After surfing/lurking on various boards for a while, I have decided to learn PHP, as I agree with the open source / cross platform philosophy and it seems pretty straightforward to learn.

I would like any advice you could give a beginner on how to configure an apache server (shell?), then how to install PHP and mySQL within that.

Also, regularily I hand code all of my pages in BBEdit, validate then both within BBEdit's own markup check and on the W3 site, then launch the page(s) in various browsers to test for function and appearance.

How do I test a page with PHP and server side scripts in it? I would imagine I would have to somehow "upload" it to the apache server on my hard drive, then open it from within a browser. Never having done this, however, I am just wondering where to get started.

Thanks to all who reply. Cheers!

James
     
bens1901
Registered User
Join Date: Sep 2002
Location: New York City
Status: Offline
Reply With Quote
Nov 12, 2003, 05:00 AM
 
which version of OSX are you running?
     
James L  (op)
Mac Elite
Join Date: Aug 2003
Status: Offline
Reply With Quote
Nov 12, 2003, 07:32 AM
 
The latest 10.2 right now, but by the time I do this Panther 10.3.

Thanks again!
     
bens1901
Registered User
Join Date: Sep 2002
Location: New York City
Status: Offline
Reply With Quote
Nov 12, 2003, 09:38 AM
 
Below is a description of how I've configured my development environment. There are many ways to do it. Hope this helps.

=====for PHP installation on 10.3
-from Finder, use the "Go" menu, select "Go to Folder..."
-enter "/etc/httpd/users/"
-(you will need admin priviledges for this...let me know if you want more info on this) open the ".conf" file using any text editor you like...I use "vi", but you can also use Apple's TextEdit by dragging your .config file onto the TextEdit app icon
-add these lines to it...I read somewhere that the AddModule is needed, but my system works with it commented-out
~~~~~~ terminal stuff to type ~~~~~~
# make sure Apache knows what to do with php files
LoadModule php4_module libexec/httpd/libphp4.so
# AddModule mod_php4.c
AddType application/x-httpd-php .php
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-also, if you want the default "index.php" for the site at port 6650 to automatically be loaded when you type "127.0.0.1:6650", then modify (just like the .conf file editing) the file located at "/etc/httpd/httpd.conf"...find the lines "DirectoryIndex index.html" and modify it to be like this "DirectoryIndex index.html index.php"
-when you turn on your computer you must open the "Terminal" app (found in Applications/Utilities), type this stuff: (You must type these Terminal commands at least once at you reboot/restart your computer, otherwise you'll get a server unavailable message) I use this approach so that my web server isn't always running on my computer...you can automatically have it startup with your machine if you like)
~~~~~~ terminal stuff to type ~~~~~~
cd /etc/httpd
sudo apachectl graceful
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(you'll be prompted for your admin account password. enter it, then apache will startup)

=====below is what I do for developing a php site. I go into my "home" folder, create a "projects", then create a "proj1" folder...this will contain all the site files for this project. To access this site I go into a web browser and type "http://127.0.0.1:6650" For each additional site I just increment the port. the 127.0.0.1 points to the local web server. To make it easier for me to remember the port assignments, I use this port 6650 site as an index page that lists all of my sites with links to the ports (let me know if you want more info on this)
(you can repeat this text-insert for each project ,as long as you modify the port number and the directory it points to)
~~~~~~ put into config file~~~~~~
# tell the server to listen to an IP and port for the site
Listen 127.0.0.1:6650
# bind the address and port to the site
BindAddress 127.0.0.1:6650
# name the virtualhost ip and port for the site
NameVirtualHost 127.0.0.1:6650
#describe the virtual host for the site
<VirtualHost 127.0.0.1:6650>
DocumentRoot /Users/myUserAccount/projects/proj1
ServerName proj1
</VirtualHost>
~~~~~~~~~~~~~~~~~~

=====for MySQL installation on 10.3
-go to http://www.entropy.ch/software/macosx/mysql/ and follow the installation instructions
-To enable the automatic startup of MySQL on bootup, you can download Marc Liyanage's MySQL StartupItem from the following location and install it (simply click on the package):
http://www2.entropy.ch/download/mysq...tem.pkg.tar.gz
-restart the machine (to make sure that the mysql starts at startup automatically)
-if you want to go into mysql and build a db, create a user, etc., (you can exit mysql by typing 'exit')go to a terminal window and type:
~~~~~~ terminal stuff to type ~~~~~~
/usr/local/mysql/bin/mysql -u root mysql
~~~~~~~~~~
-I use the mysql terminal thingy to manager db users and tables
-I use "CocoaSQL" for testing sql queries and stuff with the data in the db

=====to test your pages, simply go to "http://127.0.0.1:6650" and you'll get that page. The actual page would be located in you "myUserAccount/projects/proj1" folder.
( Last edited by bens1901; Nov 12, 2003 at 09:49 AM. )
     
hunkhuang
Forum Regular
Join Date: Jun 2003
Location: Earth
Status: Offline
Reply With Quote
Nov 12, 2003, 01:24 PM
 
whoa, i was about planning to learn PHP, but it seems so complicated now...

headache...


17" widescreen LCD, 1GHz PowerPC G4,
1GB DDR266 SDRAM, 80GB Ultra ATA HD,
NVIDIA GeForce4 MX, 64MB DDR video memory
     
Simon Mundy
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Nov 12, 2003, 06:04 PM
 
Originally posted by hunkhuang:
whoa, i was about planning to learn PHP, but it seems so complicated now...

headache...
Nah, it's complicated to set up, but using it is really straight forward. Especially if you're already comfortable with Javascript and/or Actionscript.

There's at least a dozen current articles around the web dedicated to getting Apache and PHP up and running, and there's also the point-and-click packages from Server Logistics who provide the Complete Apache, Complete PHP and Complete MySQL packages (complete with documentation, too!)

Another great source of info is http://www.entropy.ch/software/macosx/ - there's also some straight-forward text about configuring these modules.

Don't be shy - back up all your data and dive right in. The worst that can happen is that you will need to do a system re-install if things get really screwy, but in 99.5% of times things won't get THAT bad
Computer thez nohhh...
     
hunkhuang
Forum Regular
Join Date: Jun 2003
Location: Earth
Status: Offline
Reply With Quote
Nov 12, 2003, 10:49 PM
 
well, i am confuse of using php and asp... are they the same? i heard many people using .asp because it's much easier..

By the way, besides setting up, do you guys have any recommendation of php scripts sites for "dummies" like me??

I dont know how to start...


17" widescreen LCD, 1GHz PowerPC G4,
1GB DDR266 SDRAM, 80GB Ultra ATA HD,
NVIDIA GeForce4 MX, 64MB DDR video memory
     
clam2000
Dedicated MacNNer
Join Date: Aug 2002
Status: Offline
Reply With Quote
Nov 13, 2003, 12:10 AM
 
you won't get much better then http://www.php.net

it has everything you need.

asp is a more 'microsofty' language, it actually isn't a language, more of a way to run visual basic / javascript on the server with extra webserver functions.

php is opensource, and in my humble oppinion much easier to use and learn.

--will
     
si_lance
Dedicated MacNNer
Join Date: Nov 2003
Location: SoCal
Status: Offline
Reply With Quote
Nov 22, 2003, 03:03 AM
 
bens,
you made that so complicated when it's really very much easier on Panther.

1. open /etc/httpd/http.conf (I use vi so it would look like sudo vi /etc/httpd/http.conf)
2. uncomment (remove the # in front) these lines:
#LoadModule php4_module libexec/httpd/libphp4.so
#AddModule mod_php4.c
3. goto to System preferences and turn on Personal Web Sharing (which turns on apache)
4. look in your home dir under Sites and you should see a /images folder and index.html
5. you access by doing http://localhost/~username, where username is your login name ex. http://localhost/~lance
6. to see for sure, make a file info.php with:

&lt;?php
&nbsp;phpinfo();
?>

and goto http://localhost/~username/info.php
7. add MySQL (not quite as simple)
( Last edited by si_lance; Nov 22, 2003 at 03:18 AM. )
     
Arkham_c
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Nov 22, 2003, 04:05 PM
 
You could also just download the nice OSX installer for PHP here:

http://www.entropy.ch/software/macosx/php/

He keeps the latest packages built and up to date. It's quite nice.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
opheim
Junior Member
Join Date: Jun 2003
Location: Bergen, Norway
Status: Offline
Reply With Quote
Nov 23, 2003, 06:47 PM
 
I asked almost the same question a while back, and ended up creating a step-by-step guide on my own, based on info from several locations in addition to some experimenting.

The guide is aimed at configuring multiple local development-sites in order to conduct web development for multiple clients without having to change configuration along the way. It covers installing a complete Apache2, PHP-support, MySQL database-server and setting up /etc/hosts and httpd.conf in order to achieve the above stated goal. I think it's fairly easy to follow...

You're of course free to use it:

http://tersus.no/virtualhosts.html
Hallvard Opheim
Dual 2GHz G5, 9800Pro, 2.5GB, BT, iSight
PB17 1GHz, 1GB
     
DavideMac
Fresh-Faced Recruit
Join Date: Sep 2003
Location: Canada
Status: Offline
Reply With Quote
Nov 24, 2003, 05:05 PM
 
Well, let me start off by saying that I've been using Mac for over a year now and I actually have two of them; an eMac and an iBook G3. I bought these computers because I have my mind set on becoming a serious part time web designer. I've managed to get a grip on the basics (xhtml, css, javascript etc.) but now I want to learn server side, specifically PHP and MySQL. I downloaded the the Complete Apache, PHP, and MySQL from Serverlogistics and installed them on my iBook which is running 10.3. Now what I like to have is an enviorment set up where I could learn PHP and MySQL at my own pace. By the way, I'm a working father so this is all nights and weekends. I use DWMX and I'm wondering how to this on my own computer, that is make PHP files and test them. It would be great if someone could explain this to me (realizing that I'm not a serious programmer or geek) how this works so that I could begin to learn and test on my own. I'm thinking of using CocoaMySQL for the databasing and SubEthaEdit for PHP, but like I said, I have no clue how to serve these files to my own computer. Any help would be greatly appreciated. And remember I'm not a sophisticated user like most of you are so just a little english here and there would be appreciated. Thanks
     
James L  (op)
Mac Elite
Join Date: Aug 2003
Status: Offline
Reply With Quote
Nov 24, 2003, 09:44 PM
 
Hey,

A belated thank you to all who posted their thoughts on this thread. Yesterday I finally got around to doing this, and was amazed at how easy it was! Having apache and PHP built into 10.3 meant the whole process took me about 15 minutes to get it up and running. Simply uncomment a couple of modules in a file, click to enable personal web sharing, save the files to the sites folder for the server read, viola!

I haven't yet tried to d/l MySQL, but that will be coming soon.

Thanks again!
     
si_lance
Dedicated MacNNer
Join Date: Nov 2003
Location: SoCal
Status: Offline
Reply With Quote
Nov 25, 2003, 01:42 AM
 
James,
I'm glad you're up and running ...

David,
Please look at my post above to get php/apache working in 7 steps (which includes testing). Also, let me explain in plain english. The style of programming here is client-server. The client being the browser and Apache being the (web)server. Often, to do development you can run the server AND the client on the same machine, and "trick" the browser. By trick I mean use "localhost" or 127.0.0.1 as the server. Both of these is a means of referring to oneself (the machine you're working on). If you look at the /etc/hosts file you will be an entry for localhost and that it "resolves" to 127.0.0.1, and when I say resolve it means take a english-readable name and turn it into an ip (internet protocol) address (this is normally done by a nameserver, but we're taking a shortcut). You can serve PHP files to yourself to learn this way. I highly recommend the Wrox book PHP Progamming (ISBN#1861002963). Good luck.

Sorry post is long
     
DavideMac
Fresh-Faced Recruit
Join Date: Sep 2003
Location: Canada
Status: Offline
Reply With Quote
Nov 25, 2003, 08:10 AM
 
ok si_lance

Just a few questions:

1. Is it ok to use the serverlogistic package for Apache 2?

2. Is it ok to use the serverlogistic package for PHP.

I mean, are these 2 programs already on the computer or not?

3. What is "/etc/"? Is that supposed to be Apache 2?

I'm going to try your way tonight after work.

Thanks
     
si_lance
Dedicated MacNNer
Join Date: Nov 2003
Location: SoCal
Status: Offline
Reply With Quote
Nov 25, 2003, 02:21 PM
 
Originally posted by DavideMac:
ok si_lance

Just a few questions:

1. Is it ok to use the serverlogistic package for Apache 2?

2. Is it ok to use the serverlogistic package for PHP.

I mean, are these 2 programs already on the computer or not?

3. What is "/etc/"? Is that supposed to be Apache 2?

I'm going to try your way tonight after work.

Thanks
I'm afraid someone else will have to answer questions 1. and 2. as I have not ventured into the Apache 2 arena. I use 1.3.28 (which is what is default on OS 10.3).

However, question 3. I can answer. /etc is a folder found in the root (/) of your computer. Open a terminal window and type:
cd /etc
if you "ls" this dir you will see the hosts file. Peruse it with any text editor, but you'll need root to change it (which I recommend against unless you know what you're doing).

Take care.
     
DavideMac
Fresh-Faced Recruit
Join Date: Sep 2003
Location: Canada
Status: Offline
Reply With Quote
Nov 25, 2003, 10:40 PM
 
Well I'm not sure if I'm doing it right but after I installed the PHP software from entropy, turned on personal web sharing, and put the test file into my sites folder I got the info paged served to me. The thing is though, I have to use http://1##.1#8.0.101/~username/test.php to serve the file and not 127.0.0.1. Is that ok or am I doing something wrong?

p.s. Thanks for helping me this far.
     
DavideMac
Fresh-Faced Recruit
Join Date: Sep 2003
Location: Canada
Status: Offline
Reply With Quote
Nov 25, 2003, 10:48 PM
 
...oh by the way, I'm also looking for some good beginner tutorials on the web to help me get off and running. I'm not looking for sample scripts but rather something that will help me understand and learn the language. And thanks for the book tip si_lance, price looks reasonable.
     
si_lance
Dedicated MacNNer
Join Date: Nov 2003
Location: SoCal
Status: Offline
Reply With Quote
Nov 25, 2003, 11:00 PM
 
Originally posted by DavideMac:
The thing is though, I have to use http://1##.1#8.0.101/~username/test.php to serve the file and not 127.0.0.1. Is that ok or am I doing something wrong?

p.s. Thanks for helping me this far.
That's ok if you're actually online, but if you ever unplug from the net you'll probably need to use 127.0.0.1. Did you try localhost? Try this as a tutorial:
http://us3.php.net/tut.php

You're welcome. The book is great, but I think there are newer ones. The book was published in 1999.
     
James L  (op)
Mac Elite
Join Date: Aug 2003
Status: Offline
Reply With Quote
Nov 26, 2003, 12:54 PM
 
All I need to type to view the index page on my server is:

localhost/~james


...and If I wanted a specific page, than the name of it, i..e.:

localhost/~james/page.php
( Last edited by James L; Nov 26, 2003 at 01:01 PM. )
     
opheim
Junior Member
Join Date: Jun 2003
Location: Bergen, Norway
Status: Offline
Reply With Quote
Dec 3, 2003, 07:17 PM
 
Originally posted by DavideMac:
ok si_lance

Just a few questions:

1. Is it ok to use the serverlogistic package for Apache 2?

2. Is it ok to use the serverlogistic package for PHP.
Hi!

Yes, it's ok to use both. I prefer them to the built-in, merely because you get the PrefPanes to control the MySQL server and Apache2. Combined with CocoaMySQL it's a blast.

I'm currently running 10.3 on my PB17 and serving several projects in development using the three packages from ServerLogistics.

Editing the PHP-files when programming can be done in several different ways. Using BBEdit, SubEthaEdit, DWMX or others. The main issue is to have a directory where you store the files, and have some sort of URL pointing in that direction. If you take a look at my guide (linked above somewhere), you'll get a grip on how to create URLs pointing to different directories.

As soon as you have that directory up and running, and you've initialized the MySQL-server, you'll be up and running with the programming-bit in no time.

Good luck to you!
Hallvard Opheim
Dual 2GHz G5, 9800Pro, 2.5GB, BT, iSight
PB17 1GHz, 1GB
     
barbarian
Senior User
Join Date: Apr 2001
Location: Palo Alto, CA
Status: Offline
Reply With Quote
Dec 4, 2003, 06:06 PM
 
I'm not sure what is going on... I have basic php access (I can access a test page and so on), but if I try to pass a variable it is simply not being passed...

ie if I have a link that looks something like this

[php]<a href="index.php?myvariable=1">Home Page</a><br>

which looks like this in my browser address bar after clicking the link and testing locally:

http://10.0.1.3/~myusername/phptest/index?myvariable=1[/php]


The myvariable is not being passed. I know there's nothing wrong with the code because if I upload it to my live server I have no problem.

Furthermore doing and echo of the myvariable produces nothing when testing on the local server.

Any troubleshooting ideas?

Is this a config error?
( Last edited by barbarian; Dec 4, 2003 at 06:57 PM. )
     
si_lance
Dedicated MacNNer
Join Date: Nov 2003
Location: SoCal
Status: Offline
Reply With Quote
Dec 4, 2003, 11:52 PM
 
your register_globals=off on your machine and it's "on" on your server.

try using (on your machine):
print $_GET['myvariable']
or
print $_POST['myvariable']
depending on method you use or even
print $_REQUEST['myvariable'] which has contents from GET, POST, or COOKIE

or find register_globals in your php.ini

hope this helps.
     
barbarian
Senior User
Join Date: Apr 2001
Location: Palo Alto, CA
Status: Offline
Reply With Quote
Dec 5, 2003, 05:39 PM
 
My bad.

I had just installed the entropy php package (because I was having all sorts of issues with the default php install).

I had restarted apache, and logged in/out, but apparently it required a full reboot.

I hadn't rebooted in so long that I forgot this might be something I needed to do.

Anyway all is hunky dory now.

I highly recommend the entropy install package by the way if you are a unix/php newbie like myself.

http://www.entropy.ch/software/macosx/php/

Makes the whole process simple and relatively painfree (just reboot when you are done!).
     
si_lance
Dedicated MacNNer
Join Date: Nov 2003
Location: SoCal
Status: Offline
Reply With Quote
Dec 6, 2003, 03:07 AM
 
barbarian,
I hate to disagree, but nothing short of kernel changes (like security patches) or finder tweaks should force you to reboot. We're not on windows here so all sorts of things can be restarted like to restart|start|stop apache issue the command:
apachectl [start|stop|restart]
     
barbarian
Senior User
Join Date: Apr 2001
Location: Palo Alto, CA
Status: Offline
Reply With Quote
Dec 7, 2003, 07:16 PM
 
I hate to disagree, but nothing short of kernel changes

Hmmm. Curious, because that's exactly what I did to restart apache...

Oh well... it works now after the reboot. And while we are certainly not in Windows or OS 9 world anymore I've found that the occasional reboot seems to cure a variety of problems...

-----
Re MySQL I'm still having some problems two machines that I have tried in vain to get sorted out...

I'm almost sure the problem has to do with the fact that on these machines panther was "archive & installed" instead of being clean installed as it was on the other machines. On my other machines mysql installed without issue following exactly the same instructions.

I downloaded the standard mysql package and tried to install it on a G5 under 10.3.1 using the instructions on the entropy site:

http://www.entropy.ch/software/MacOSx/mysql/

When I get to step 5 ie:

To start the server, issue sudo echo first, then type sudo ./bin/mysqld_safe &

I get this error:


Starting mysqld daemon with databases from /usr/local/mysql/data
031205 15:43:24 mysqld ended


and if I try to run the test I get:

ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[1]+ Done


Any help would be appreciated... as I am too dense to figure this out.

The only thing I can think of is that this has something to do with the fact that jags tsch settings are copied over to panther. I have since set my shell to bash, but have noticed that many path settings and so on were not carried over.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 06:22 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,