basic questions on Apache scope, servers, etc.

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
Simnia
Forum Newbie
Posts: 9
Joined: Tue Jul 07, 2009 5:37 pm

basic questions on Apache scope, servers, etc.

Post by Simnia »

Background: I'm supposed to set up a server at work, on a PC running Windows XP. I've taken a course in PHP, which showed us how to set up XAMPP, use PHP, and use MySQL. I installed and ran XAMPP on this PC and I now have Apache 2.2 and MySQL running as services. I also created a MySQL database with the tables and columns I want. But now I'm completely lost as to basics, which I was never taught, and I can't find online. Here are my basic questions:
When developing PHP programs they can be run only with Apache when in the "C:\xampp\htdocs\" folder. For example, the file...

C:\xampp\htdocs\form.php

...can be run only with the path name...

http://localhost/form.php

...in the browser (Internet Explorer), correct? However, when I created a MySQL database called "readings" it looks like it was automatically placed at the path...

C:\xampp\mysql\data\readings

...so how can anything work at all? Can PHP access this database outside of the HTDOCS folder? How can somebody on a client machine see my PHP web page? What folder do they go to? Certainly not HTDOCS, correct? What URL do I give them? I know that web hosting companies like LunarPages have Apache running with scope such that the users can run PHP programs from any folder, but I don't see how they can do that with the HTDOCS limitation. Or should I somehow use another program for installing Apache, like Apache on its own? Does the installer package make any difference? Am I doing something fundamentally wrong, like needing to use a professional web hosting company for our project? It seems I've learned a lot of detail but nothing about the big picture of how to get anything working at a professional level.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: basic questions on Apache scope, servers, etc.

Post by VladSun »

Simnia wrote:Can PHP access this database outside of the HTDOCS folder?
Yes. PHP doesn't access the MySQL data folder directly - it access it by using the MySQL client library (e.g. mysql_* functions). This library uses a row TCP connection to your MySQL server. No file access here.
Simnia wrote:How can somebody on a client machine see my PHP web page? What folder do they go to? Certainly not HTDOCS, correct? What URL do I give them?
In your Windows command prompt run:

Code: Select all

ipconfig
You will see the IP addresses assigned to your machine. Now replace the "localhost" thing with your (or one of yours) IP address. That's the way other users can browse to your website.

Creating a DNS record for this IP is the next step.
There are 10 types of people in this world, those who understand binary and those who don't
Doug G
Forum Contributor
Posts: 282
Joined: Sun Sep 09, 2007 6:27 pm

Re: basic questions on Apache scope, servers, etc.

Post by Doug G »

You will see the IP addresses assigned to your machine. Now replace the "localhost" thing with your (or one of yours) IP address. That's the way other users can browse to your website.
There is a bit more to it. As well as identifying the IP of your machine, you will need to open http through your windows firewall to allow access from a different computer. In addition, if you are behind a router and want people from the Internet to get to your site you'll need to identify your 'public' IP address which is provided by your ISP, and you'll need to forward http port from your router to your web server.
Simnia
Forum Newbie
Posts: 9
Joined: Tue Jul 07, 2009 5:37 pm

Re: basic questions on Apache scope, servers, etc.

Post by Simnia »

Thanks so much, VladSun. That worked!

The file at...
C:\xampp\htdocs\tests\hello.php
...became accessible with the URL...
http://xxx.xxx.xxx.xxx/tests/hello.php
...where the x's hold my IP address.

That still means that anything that I want to be displayed to the public must be placed in the folder or subfolder of...
C:\xampp\htdocs\
...correct? And any databases we use with such web pages must be placed in the folder or subfolder of...
C:\xampp\mysql\data
...correct?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: basic questions on Apache scope, servers, etc.

Post by VladSun »

Simnia wrote:That still means that anything that I want to be displayed to the public must be placed in the folder or subfolder of...
C:\xampp\htdocs\
...correct?

Yes.
Pay attention to what Doug G said.
Also, keep in mind that your IP could change when you reconnect to your ISP (i.e. DHCP enabled)
Simnia wrote:And any databases we use with such web pages must be placed in the folder or subfolder of...
C:\xampp\mysql\data
...correct?
Whether your DB is to be accessed by web pages. or desktop applications, or anything else, it simply doesn't matter. Your DB is accessed through a server (commonly by using TCP/IP) just like you access your Apache (HTTP) server.
Try to run telnet from the command prompt and connect to the MySQL server:

Code: Select all

telnet localhost 3306
and see what I mean
There are 10 types of people in this world, those who understand binary and those who don't
Simnia
Forum Newbie
Posts: 9
Joined: Tue Jul 07, 2009 5:37 pm

Re: basic questions on Apache scope, servers, etc.

Post by Simnia »

Thanks again, VladSun. Yes, I had already taken care of the firewall problem per other advice before I posted my question, but Doug's advice is also useful, and fills in the gaps most people forget to mention.
Post Reply