Page 1 of 1

How to Set Up Local Copies of Apache and PHP

PostPosted: Fri Jan 18, 2008 11:28 am
by TrapezeArtist
I was having problems with "Preview" in Rapid PHP, but I think I have traced it to Apache/PHP rather Rapid PHP itself.

In order to cut out some variables I got out of Rapid PHP and just tried to open http://localhost/*.php in a browser. I found that PHP pages open OK except when there is a MySQL connection. Then nothing happens at all; not even an error message.

I make the MySQL connection with a separate "include" file that is called from the first line of the *.php file. This file is along the lines of:
<php>

I've gone through some exhaustive checks with my hosting company (Clook. Brilliant company!) to make sure I am putting the right info into mysql_connect. They also pointed out that if it was just a problem with the info there, it should display the error message. But it doesn't: it just displays a blank page. If I check Page Source, that is blank too.

Any ideas, anyone?

Questions for You

PostPosted: Sun Jan 20, 2008 3:39 am
by s1tony
Paul,

Since you are trying to setup your local Apache/PHP/MySQL environment, I am not quite sure where your hosting company fits into the equation, because you (or whoever installs MySQL on your local machine) will define what data you need for your mysql connection request.

In order to view this from the same baseline, let's start from the beginning:

- To verify, you want to install Apache, php and MySQL on your local computer?

- What have you installed so far? Did you use some type of all-in-one installation package or install the packages separately? What versions of software are you planning to install?

- What operating system are you using for this environment?

Let's start with this and go from there.

I apologize for all of the questions, but I just want to make sure I am not way off base with what you are asking?

Thanks.

Tony

PostPosted: Mon Jan 21, 2008 11:43 am
by TrapezeArtist
Tony

Don't apologise for the questions. I appreciate your assistance for someone who is thrashing around way out of his depth.

The reason for my hosting company coming into the equation is because I am (was?) trying to see the MySQL database on the server, while using Apache and PHP on my local machine. Perhaps that's all wrong, and I should have a local copy of MySQL and the database as well.

Anyway, to answer your questions:
I've installed Apache 2.2 using the .msi Windows Installer. I've installed PHP 5.2.5 by a manual install. Both of those seem to work fine. If I open a php page without any MySQL connection in it, it displays properly including the bits that have to be decoded by PHP.

My operating system is XP Home.

I'm only trying to do this so that I can easily preview my pages and see everything in a representative way. I've got fed up with having to upload files to the server and then view them over the internet, because I have a satellite internet connection that is slow and bandwidth-limited. If I had to have a copy of MySQL software and the MySQL database on my local machine, it wouldn't be a problem that the data would be a little bit out-of-date.

Thanks.

PostPosted: Tue Jan 22, 2008 1:38 am
by ikeo
I remember having this exact problem with the same setup (php 5.2.5).

First of all do a phpinfo and tell me two things

is the variable

display_errors "on" or "off"

and then let me know if there is a mysql section in the report (ie: is the mysql extension loaded).

also post you connection code if possible.

PostPosted: Tue Jan 22, 2008 1:43 pm
by TrapezeArtist
Hi Ikeo

I think you may be on to something! :)

display_errors is "off".
There is no mySQL section in the report.

At this point I got excited, opened up php.ini and changed display_errors to "on". I ran phpinfo again and it still said display_errors is "off". :( Presumably I was changing the wrong thing.

I also found a mySQL section in php.ini but I couldn't see anything to say that it was switched off, so I couldn't see what I might do to switch it on. :(

Can you steer me the next step of the way?

The code for the connection is currently:
$hostname_MySQL = "littlehotels.co.uk:2083";
$database_MySQL = "DATABASE";
$username_MySQL = "USER";
$password_MySQL = "PASSWORD";
$MySQL = mysql_connect($hostname_MySQL, $username_MySQL, $password_MySQL) or die('Could not connect!');
I was using mysql_pconnect but was told I shouldn't. Also I did have a different for of dealing with the error that was created by Dreamweaver, but I couldn't understand it so changed to something simpler.

PostPosted: Tue Jan 22, 2008 2:07 pm
by TrapezeArtist
We're getting somewhere. :)

I got display_errors to "on" when I re-booted the computer.

Then when I tried to open a page, I got an error message:
Fatal error: Call to undefined function mysql_connect() in ............
If it doesn't recognise the function, presumably that means I don't have the "mySQL" bit of PHP running.

So, a bit more work to do to see how to switch on mySQL. Any ideas?

PostPosted: Tue Jan 22, 2008 2:23 pm
by chrisjlocke
Have you heard of Xampp? A 'ready to run' install of Apache, PHP and MySQL.

www.apachefriends.org/en/xampp.html

PostPosted: Tue Jan 22, 2008 7:19 pm
by ikeo
At this point I got excited, opened up php.ini and changed display_errors to "on". I ran phpinfo again and it still said display_errors is "off". Sad Presumably I was changing the wrong thing.

--- You are probably running php as a module instead of as a cgi process.
You needed to just restart Apache to see your changes, but the reboot works as well.


I also found a mySQL section in php.ini but I couldn't see anything to say that it was switched off, so I couldn't see what I might do to switch it on.

--- The error you are getting is just telling you that the mysql extension hasn't loaded.

search for the extensions section especially this line
;extension=php_mysql.dll

remove the ";" so it looks like
extension=php_mysql.dll

then restart Apache and you should be set.

PostPosted: Tue Jan 22, 2008 8:31 pm
by TrapezeArtist
chrisjlocke wrote:Have you heard of Xampp?


Only from reading this forum. I'm going to have a look at it now. Anything that makes Apache, PHP and mySQL less painful has got to be good.

PostPosted: Tue Jan 22, 2008 8:36 pm
by TrapezeArtist
Ikeo

I thought that was the solution, but sadly "No". :cry:

I found the line you mentioned, and modified it. I also found a bit in php.ini telling me I needed to set the extension directory. I did that (I think) by including the line:
extension_dir = ".;c:\php\ext"

Still no luck!

I think I'm going to try uninstalling Apache and PHP and put Xampp on instead.

PostPosted: Tue Jan 22, 2008 9:13 pm
by chrisjlocke
TrapezeArtist wrote:Only from reading this forum. I'm going to have a look at it now. Anything that makes Apache, PHP and mySQL less painful has got to be good.

It does! Easy to use control panel.
Ensure your other Apache/PHP/etc installs are turned off and not listening, otherwise you'll still get issues - the wrong Apache installation will be listening on port 80, etc...

Good luck! ;)

PostPosted: Thu Jan 24, 2008 10:14 am
by TrapezeArtist
XAMPP is installed, relatively painlessly. There are still a few hiccups though, and I'm beginning to wonder if this is something fundamental that I'm not going to resolve:

1. Setting the directory root. If I change that to where my local copy webpages normally reside, I can no longer get to the pages included with XAMPP.

2. I have several websites, each one living in it's own htdocs on the server but having to go in a separate folder in the local copy. This means that some internal links don't work in the local version.

3. SSI doesn't work. Presumably I'm just missing a setting somewhere and need to do a bit more digging for this.

4. I still can't open a page with a MySQL connection! Now, instead of delivering a blank page, it just sticks, with the egg-timer cursor showing interminably.

5. When I tried to make a local copy of the mySQL database, I couldn't get phpAdmin to open. It's in a different directory so seems to need more tweaks to httpd.conf to make it work.

I'm rapidly reaching the conclusion that the hassle outweighs the benefits. I should stick to uploading my pages by FTP and then downloading them with the browser to test them.

Ever Resolve?

PostPosted: Sun Feb 10, 2008 3:02 am
by s1tony
Paul,

Did you ever resolve this? I failed to check back and the "Notify me ...." option did not notify me.

A Quick Couple of Notes:

- To administer mySQL on your local machine, I suggest some free tools from mySQL:

http://dev.mysql.com/downloads/gui-tools/5.0.html

I use MySQL Query Browser all the time - you can even connect to your remote MySQL database with it.


- Concerning connecting to your remote MySQL database, I am assuming your ISP allows this and the port you listed is the correct port [FYI: 3306 is the default port], as they helped you with it.

For one of my ISP accounts, I had to add remote addresses before they could access MySQL. If your ISP admin interface is cPanel, you should have a page for MySQL Account Maintenance, or something similar, as part of your MySQL links in your site admin page.

In this page, check for a section called Access Hosts. Add your IP to this list.


I apologize for snoozing on you and hope you were able to get things figured out.

Tony

PostPosted: Mon Feb 11, 2008 10:45 am
by TrapezeArtist
Thanks for taking an interest. I had already got into the Access hosts bit of things. It should have worked according to what I was told from elsewhere (which agreed with what you told me) but it didn't. I even set it to %.%.%.% (dangerous, but very temporary) and that didn't help either.

Frankly, I have given up. I was thinking of changing over to Rapid PHP from Dreamweaver, and that made the need to see my pages in a pukka browser more pressing. In the end I changed to the latest Dreamweaver and gave up on the idea of a local server. It would still be useful at times with Dreamweaver, but the time and trouble of setting it up seem to outweigh the benefits. Of course, I might be just a mouse-click away from a total solution; but I might not.