Useing a Mac as a webserver...

MacEffects

macrumors 6502
Original poster
Apr 21, 2005
295
0
Darkspear
I am trying to set up my Mac (iMac 700/512/60) that is a spare Mac that I need to try to figure out how to use that as a Backend for my site, where it can handle Apache web server, and MySQL database server, and others... The site is being hosted from GeoCites, that does NOT Support Backend (CGI/PHP/SQL/ETC) and they are just horrible with things like that... My goal is to make a login system for the site, and some other things like that... I can also offer some $$$ for someone who can set that login stuff up.... I really need to get this thing done ASAP so please let me know if you can help or offer any help.

Thanks!
 

whocares

macrumors 65816
Oct 9, 2002
1,496
0
:noitаɔo˩
Your biggest problem will be not having a static IP... but there are ways around that, someone else can help you out with that. Your other problem will be bandwidth and upload speeds ; if you're expecting heavy traffic, it's going to be slooooow.

Apache is preinstalled with OS X (I'm assuming you're running OS X) and just needs to be started (via the Sharing panel in System Preferences). The default folder for your website is "Sites" in your home folder. To access the site from your machine:

http://127.0.0.1/~username/

And to access from a distant computer:

http://your_IP_#/~username/


PHP is also preinstalled with OS X but a bit more tricky to get working (involves use of the Terminal). MySQL is not installed so you need to download a package for it. Marc Liyanage's site is a good source for that and includes some installation tips (you should also find a package for installing and starting PHP which I recommend you use). I also recommend CocoaMySQL for administration your database(s) ; it's a free, opensource GUI for MySQL (others might recommend PHPMyAdmin).


Hope this helps you getting starting...


I can also help with the loggin stuff ;)


--------


It may be easier if you get some cheap hosting that includes PHP/MySQL. Other members here will be able to recommend good hosting that fit your needs. Just a thought.
 

Mitthrawnuruodo

Moderator emeritus
Mar 10, 2004
13,595
142
Bergen, Norway
To enable php on localhost with minimal use of Terminal:

1) Open Terminal ( :rolleyes: ) and type open /etc/httpd
2) Drag httpd.conf to Desktop (or wherever), it should be copied over, and not moved by default.
3) Make a copy of the httpd.conf file for backup purposes.
4) Open the httpd.conf file using a text-only editor (my favorite is TextWrangler, but SubEthaEdit is another nice, free one). Apple's TextEdit will also work, but make sure it's not in rtf mode.
5) Find the line (about line 240):
# LoadModule php4_module libexec/httpd/libphp4.so
and remove the '#'
6) Find the line (about line 284):
# AddModule mod_php4.c
and remove the '# '
7) Save the file and quit the text editor
8) Drag'n'drop the httpd.conf file back into the /etc/httpd folder (in the open Finder window)
9) Authenticate with admin password when asked
10) Agree to replace the existing file
11) Restart apache by stopping and starting the Personal Web Sharing option in System Preferences -> Sharing -> Services

Now, php should work when accessing your Sites folder using http://localhost/~user/ (or http://computername/~user/ or http://computername.local/~user/ or http://127.0.0.1/~user/ or http://ipaddress/~user/ ;)) in your browsers...
 

MacEffects

macrumors 6502
Original poster
Apr 21, 2005
295
0
Darkspear
WhoCares: Okay, well after looking at the details on that I think you are right, to be honest I do NOTHING about that sort of work, I know NO PHP,SQL,CGI etc, I thought I could get away with just copying free codes, but it turns out this may be quite a pain, however I have been trying to get some sort of login for my site, but since I no nothing about it I have no idea what do...

I am all for a hosting service but I have paid for those before with people saying they could help me set it up and sure enough the would only help for like $250-400 (Money I really can't afford right now)... However I can pay 100 at most, and I have plenty of Macs for trade or trade any money, if you or someone else could sort of 'do all the work' :) as I have no idea what I am doing, but like I said I can get a host service but as soon as I see a CPanel I have no idea what ANYTHING is or does... When it comes to things like this I wish there was an easy way out but the longer I wait the more I need one...

Please do let me know if there is any way I could pay you to set it up after I pay for the hosting thing, and get it to where I need it. I did want a PHP Search but right now I just need a BASIC Login 'System' please do let me know.
 

MacEffects

macrumors 6502
Original poster
Apr 21, 2005
295
0
Darkspear
I did not find
"# LoadModule php4_module libexec/httpd/libphp4.so" in the code, but I did all the other steps, I think it may work, w/o that, but since there is no site on my Mac (it is on GeoCites) the testing may be a bit, well that and I have no idea what am doing
:eek: :D .... But I will try every way I can until somthing works

(also, let me know if by not having that code I will have some sort of deserter on my computer like Kernel Panic, :rolleyes: )
 

whocares

macrumors 65816
Oct 9, 2002
1,496
0
:noitаɔo˩
To find out if it's working, create a file called 'test.php' with a text editor containing :

Code:
<?php

phpinfo();

?>
Put it in your Sites folder, open a browserwindow and type

http://127.0.0.1/~username/test.php

If PHP is working, you should get a page with general information on your PHP config/installation. If PHP is not working, you'll just see the code...

If it doesn't work, check out Marc's packages to install/start PHP (see my previous post for link.

---

What kind of login do you need? Multiple users or just one user?
 

MacEffects

macrumors 6502
Original poster
Apr 21, 2005
295
0
Darkspear
Well, I think I broke something because Personal Web Sharing will not turn back on, I did find the line, and deleted the # symbol... When I try to turn it on it says "Web Sharing Starting up..." and just stays like that... Any ideas how to get that to work, or should I just pay for service?
 

Mitthrawnuruodo

Moderator emeritus
Mar 10, 2004
13,595
142
Bergen, Norway
It might have something to do with the fact that you only altered one of the two php-lines mentioned above in the httpd-conf file...

And there's a chance that permissions may play a part. Try repairing them (httpd.conf should be mentioned in the once in need of repair).
 

MacEffects

macrumors 6502
Original poster
Apr 21, 2005
295
0
Darkspear
Okay, i used the backed up one to replace the whole file and i worked, so i don't know what to do... The file did have a different icon then the other in that folder and the original.. I used one of the editors mentioned above, so I am unsure what to do, but I will look ok Google to find another editor to see if that works.
 

feakbeak

macrumors 6502a
Oct 16, 2003
925
1
Michigan
Perhaps you saved the file in a different format, such as RTF? That would good explain why the web service did not start. If the icon changed, this is a likely reason for the problem.

Having someone else set up your simple login might be fine for now since you are not familiar with any of these technologies. However, I would strongly recommend reading some tutorials, picking up a few books or even taking a course or two related to these topics. The reason is that even if someone else gets you up and running it will be very difficult to maintain without the knowledge of how it works. You can always pay people to fix it whenever you have a problem, but that gets expensive and you seem to be on a budget.

I'm not saying you shouldn't pay someone to help you out now, but I would also start investing in becoming more knowledgable about running dynamic websites so that you can save yourself time, money and effort in the future.

Good luck!
 

MacEffects

macrumors 6502
Original poster
Apr 21, 2005
295
0
Darkspear
Success after about an hour of work I got the PHP info to show up and the PHP has a LOT of INFO on that page... What do I do now? And is the next step simple :D .

Please let me know.
 

csubear

macrumors 6502a
Aug 22, 2003
613
0
How much bandwidth do you need for your site? Will your home cable or dsl modem handle it?

If so, host it your self. You can get dynamic-dns from www.no-ip.com, for real cheap.
 

MacEffects

macrumors 6502
Original poster
Apr 21, 2005
295
0
Darkspear
Well there will be a small amount of people about (500-1000 per month). And I have the iMac hooked to a DSL line, so the speed should be alright. I would like to use my computer if possible to save money... But if you think I should do otherwise please let me know.
 

MacEffects

macrumors 6502
Original poster
Apr 21, 2005
295
0
Darkspear
Okay, I am still having problems, I got Navicat and CocaMySQL and it show stuff about ports, and all kinds of stuff that I have no idea about. I think I need step by step help on this. Again if some one could help me 'do all the work' (probably simple for some of you ) I would always pay for that, it is just set up that needs done, just the basics.

What I am trying to do:

Have Basic Login it does not have to be ultra secure or anything, I will pay for a service if needed or I can use my iMac. Thing is there will only be under 10 or so user names and passwords, just to view a certain section on the site (sounds simple enough) :rolleyes: .... But any more help would be great and much appreciated.
 

whocares

macrumors 65816
Oct 9, 2002
1,496
0
:noitаɔo˩
If it's only for a few users who aren't expected to change passwords very often, I think the best solution might be limited access directories. This is server level so you need to configure the Apache server on your iMac.

The first step is to create a file containing a liste of usernames and passwords. This file needs to be placed somewhere that can't be accessed by HTTP, ie typically outside of the 'Sites' folder. To create it type in Terminal:

Code:
htpasswd -cb /Users/your_username/Desktop/access username password
This will create the file on your Desktop (you should move it later, but not to Sites folder!) and add the first user (username and password). To add subsequent users, type the following command:

Code:
htpasswd -b /Users/your_username/Desktop/access username2 paswword2
That was the easy part :) Now we need to modify your Apache configuration file httpd.conf. First make a backup of it:

Code:
sudo cp /etc/httpd/httpd.conf /etc/httpd/httpd.conf.bak
This will prompt you for your root password. Now open the httpd.conf in pico text editor:

Code:
sudo pico /etc/httpd/httpd.conf
Scroll down to the bottom of the file (arrows or Control + V). Once your at the bottom, add the following:

Code:
<Directory /Users/your_username/Sites/protected_folder/>
AuthType Basic
AuthName "Password Required For This Area"
AuthUserFile absolute_path_to_access_file
Require user username username1
</directory>
Don't forget to set your username where appropriate, set the absolute path to your access file (starting with a slash /). List all usernames that have access to the folder seperated by a space. Now save the file (control + O, then hit enter) and quite (control + X). Restart webserver and test.

You may of course do this for several directories, just copy, paste and change the directory name. This protects the directory and all sub-directories.

You can also create usergroups which can make it simpler to grant access. I'll post that later, it's time for lunch.

Hope this helps, works and seems clear enough to follow :) Post if you need more help or I messed up.
 

whocares

macrumors 65816
Oct 9, 2002
1,496
0
:noitаɔo˩
MacEffects said:
Okay, I am still having problems, I got Navicat and CocaMySQL and it show stuff about ports, and all kinds of stuff that I have no idea about. I think I need step by step help on this. Again if some one could help me 'do all the work' (probably simple for some of you ) I would always pay for that, it is just set up that needs done, just the basics.
CocoaMySQL is asking for the parameters to connect to the MySQL database server. Of course, if you haven't installed MySQL, CocoaMySQL will be pretty useless :eek:

Simple MySQL installation (clicking and copy/pasting commands into Terminal) is available here.
 

MacEffects

macrumors 6502
Original poster
Apr 21, 2005
295
0
Darkspear
Wow, that is sure a lot of work :rolleyes: I will get started trying to do that, how ever another problem my Router (D-Link DI-604) something else must be blocking out side users (out side my local network) because when I tested from a local library and had send people the link (http://xx.xxx.x.xx/~xxxxx) it said not found, and it worked in my network, so I should try to fix that too other wise this will not work... I did talk to about 4 hosting sites and they ALL told me I should NOT Buy any services for that (and thats odd form companies :rolleyes: :D ) so I think you are right my best bet is to my iMac that coincidentally is always on.

And ideas about the router?
 

MacEffects

macrumors 6502
Original poster
Apr 21, 2005
295
0
Darkspear
Okay I messed up on the simple part :(... On Terminal I put

"htpasswd -cb /Users/ihateyou/Desktop/access testuser1 mypassword" in and it says "Adding password for user testuser1" what dose that mean, I did not see any folder? Also may be since the iMac has two user account "ihateyou" (a bad day on the computer was the cause for that name:) ) and "somethingelse", so that is why I put "/Users/ihateyou/Desktop/" so it would work, unless that is wrong, as I have no idea... What should I be looking for?
 

whocares

macrumors 65816
Oct 9, 2002
1,496
0
:noitаɔo˩
MacEffects said:
Okay I messed up on the simple part :(... On Terminal I put

"htpasswd -cb /Users/ihateyou/Desktop/access testuser1 mypassword" in and it says "Adding password for user testuser1" what dose that mean
Means that it should be good. Check your desktop for any new files called access ;)
 

whocares

macrumors 65816
Oct 9, 2002
1,496
0
:noitаɔo˩
MacEffects said:
And ideas about the router?
The router needs to know where to route the HTTP request to, ie which computer on your home network should answer the 'internet' requests.

This is done on the router setup page (usually accessed with http://192.168.1.1); some documenttation should come with your router. I guess you're using DHCP (dynamic) IP leases, so each time you restart your computer, it's IP might change and the routing tables messed up. Someone else needs to help you out on this one...
 

MacEffects

macrumors 6502
Original poster
Apr 21, 2005
295
0
Darkspear
Okay, now I am stuck on the Hard part:)... I found the access it was on my desktop (I have way to much on there it got lost)... I am unsure what I should do with the codes below, I put them in terminal but I do not know, it gets more and more confusing :rolleyes: .

Code:
sudo cp /etc/httpd/httpd.conf /etc/httpd/httpd.conf.bak


This will prompt you for your root password. Now open the httpd.conf in pico text editor:

Code:
sudo pico /etc/httpd/httpd.conf
Scroll down to the bottom of the file (arrows or Control + V). Once your at the bottom, add the following:

Code:
<Directory /Users/your_username/Sites/protected_folder/>
AuthType Basic
AuthName "Password Required For This Area"
AuthUserFile absolute_path_to_access_file
Require user username username1
</directory>
 

whocares

macrumors 65816
Oct 9, 2002
1,496
0
:noitаɔo˩
Basically, you're modifiying httpd.conf with is Apache configuration file (a bit like Preference Panel for OS X, but no GUI ;) ). The first command is just a back up. Copy, paste into terminal and hit return. Easy.

The second command opens httpd.conf in the pico text editor (a command line editor - like Woed, minus the GUI). It looks ugly but is quite easy to use. Copy and paste the command into Terminal. Once you hit return, it will open the file. Press Control+V until you reach the bottom of the file (should be obvious when you reach it).

The cursor is a grey rectangle, make sure its on a new line (use arrows to go to the last line, and return to add a new line). Now copy the last bit of code and paste it in on the last line of your httpdf.conf file.

You now need to save the changes (Control+O, then return), and exite (Control+X). You're now done with Terminal and can close it. Restart Webserver in System Preference.
 

feakbeak

macrumors 6502a
Oct 16, 2003
925
1
Michigan
Well you now have a link to help you with DDNS to get your domain linked to your home IP address.

You will still need to configure your router correctly though. Here is a link that talks about port forwarding and how to set it up on a DLink router. I recall you telling me you had DLink, but don't recall the model. You will also want to make sure that your iMac gets a static IP on your LAN so that the port-forwarding rule will always work properly.