Build your own Database Driven Website using PHP & MySQL - Part 1: Installation

Yep, it definitely sounds like you missed the ‘make install’ step. If you look in the book, the build process for PHP is two steps: make and then make install. The first one compiles PHP, the second one copies the libphp5.so file to your Apache module directory and adds the LoadModule line to your apache configuration file.

So I’d suggest getting the PHP5 source package and redoing the compilation step, then making sure you do the ‘make install’, watching carefully for any errors in this second process.

Okay, can do. I am sure I did both “make” and “make install” - I remember the first gave pages and pages of output, and the second only 20 lines or so. But I must confess I didn’t pore over it for errors, I didn’t know what to look for.

I am (obviously) a total newbie to compiling from source…this is my first attempt to compile anything! Sorry my questions are so basic, I know this is pretty off-topic.

If I am to go back, is there anything I need to “undo” first? And what step should I start at - do I need to do the configure stuff again?

Many thanks,
Pete

Okay, I tried going back to the tarball, and I found that there were indeed errors of some kind at the “make” stage.

Since I haven’t the slightest idea what to do about them, I’m thinking I’m over my head at this point, and maybe should choose something simpler than PHP for my first compile.

So, I used apt-get to install libapache2-mod-php4 and then used the configuration suggestions from your book…and it works!

Since my only goal from this PC at this point is to learn, I expect that’s good enough for now, and I’ll just use it as is. It would probably take much coaching to get the compile-from-source approach to work.

Thanks for your help though! Got me out of my rut. And if my decision do use the Debian package is a bad one for any reason, feel free to let me know!

-Pete

PHP4 should do just fine for now, yep. If at any stage you decide to re-attempt the compilation, let me know and I should be able to help you nut out the error messages. Usually it’s just a package or two you need to apt-get.

I have a question about numeric data types.

In a different book, it says that “Numeric” and “Decimal” types are interchangeable, and while they are intended for numeric values they “cannot be used for mathematical purposes.”

Can anybody shed any light on what this limitation means in practical sense? What is an example of the kind of operation you could perform with a “Float” or “INT” field, but would not be able to do with data in a “Numeric” field?

NUMERIC and DECIMAL are indeed two names for the same column type in MySQL. The key purpose of this column type is to allow you to specify the exact number of digits before and after the decimal point, and to be assured of exact precision of the values you store (as opposed to floating point numbers, which suffer from limited precision).

At least in current MySQL versions, there are no practical limitations on the use of NUMERIC/DECIMAL values in mathematical operations.

Full documentation on these data types is provided in chapter 11 of the MySQL manual.

Thanks for that link Kevin, that clarifies a lot - I hadn’t quite understood the difference between storage range and display width, but it makes perfect sense now. Also, it appears that “decimal” does differ in that it’s STORED as characters rather than binary, but it doesn’t say anything about that affecting how you can manipulate it. Looks like I misunderstood that too. I’ll have to explore that manual in more depth!

On a different note, I’ve been unsuccessful at getting a PHP script to connect to a MySQL database. I typed in the example on page 76 of your book (2nd ed) and it’s not displaying anything. (By the way the file in the code archive seems incomplete, unless my download somehow got corrupted.) By putting “echo” statements in at various points in the code and observing whether or not the text is displayed, I narrowed it down to the line where it tries to connect:

$dbcnx = @mysql_connect(‘localhost’, ‘root’, ‘mypassword’);

If I load up the page in a web browser, nothing after that line shows up…not even the HTML that’s outside of the PHP tag (“Here are all the jokes in our database.”) It just seems to stop.

From the linux command line, the syntax of ‘msql -h localhost -u root -p’
followed by my password works fine.

Any idea where else I can look? I’ve tried some of the things suggested elsewhere in the forums (for instance removing the root password, and fooling with single-, double, and no quotes), but so far no luck!

-Pete

It sounds like the MySQL support in your PHP installation isn’t working. Remove the error suppression operator (@) from that line and see what error message PHP displays. If it complains that the function mysql_connect doesn’t exist, you’ll need to reconfigure/recompile PHP with MySQL support enabled.

yes…

Fatal error: Call to undefined function: mysql_connect() in /var/www/apache2-default/nddpage.php on line 10

So…will the apt-get installation not work for me? Do I need to go back to the compile-from-source approach?

In another forum config_doug suggestes turning REGISTER_GLOBALS on, but said that might present a security risk. Seemed easy enough to test so I tried it, and then did ‘apache2ctl graceful’ but it made no difference.

Maybe a step closer??

I found a web site
http://www.projektfarm.com/en/support/debian_setup/
with instructions for setting up all this stuff on Debian. For one thing, it said to install a bunch of PHP-related packages I didn’t have installed. So I did that (all but a couple that I couldn’t find.) But, these instructions were for Apache 1.3, and I have Apache 2. I followed the instructions as best I could, making some guesses along the way.

Now, I get a different error message when trying to load my page:
Warning: mysql_connect(): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /var/www/apache2-default/nddpage.php on line 10

On inspection, the file mentioned in the error code (/var/run/mysqld/mysqld.sock) indeed does not exist on my system.

Seems like progress…but I’m not sure what the next step is!

Yep, you’ve got MySQL support added to PHP, which is good. Now if you’re sure MySQL is running, it sounds like MySQL is set up to accept TCP/IP connections only, not local socket connections.

I’m afraid I don’t know how to solve that one offhand – worth a trawl through the relevant mailing lists. If you strike out, try installing MySQL manually rather than via apt.

This is an awesome book. It’s exactly what I needed.

The problem I’m having is that when I restart the World Wide Web Publishing Service as described on page 9 of the book, I get the error message:

PHP Startup: Unable to load dynamic library ‘C:\PHP\ext\php_mysql.dll’

I’m absolutely sure that this file is in the correct place, but it still gives me that. The today.php file later crashes the window spouting some memory access violation and show the text on the screen in numbers. Any advice?

You’re a disgrace :smiley:

Can you confirm you have copied the file libmysql.dll to your \WINDOWS\SYSTEM32 folder?

The today.php file later crashes the window spouting some memory access violation and show the text on the screen in numbers. Any advice?
You’re talking about a Windows Blue Screen of Death (BSOD), right? Sounds like a driver or hardware problem unrelated to (but simply being triggered by) PHP and MySQL. If the problem’s repeatable, I’d consider a Windows reinstall.

Yes, I can confirm that I have copied the file. And no, it’s just an alert box crash with some inetinfo.exe application error. I have uninstalled IIS and reinstalled again using the exact processes you described, but it displays this in the browser instead of “Today’s Date (according to this Web server) is”:

-2147467259 (0x80004005)

Does that help anymore? Thanks for your assistance.

These chapters are very helpful. So far so good. I have a muddled installation in that there seem to be vestiges of an earlier installation, and have ended up installing 4.1.12 as MySQL41 under Windows services. The command line operations seem to be working properly, so far, having got part way through the joke database.

Why don’t you provide any info about the configuration wizard you have to go through?

I, too, am having problems with the examples. I ran the simple examples early in the book (to make sure PHP is working), PHP is working fine. But for some reason I cannot connect to the MySQL database.

I am running WinXP SP2, and all the latest Apache, MySQL, and PHP software. I posted a thread about this here:

Is it possible that the code in the example tutorials are not compatible with the latest versions of MySQL or PHP? As sneakypete mentioned above, none of the HTML code after the PHP code prints out. It’s almost as if the code halts mid processing. Also, I removed the “@” symbols before the functions and the errors don’t even print out.

Any ideas at all?

mithtered, I’ve responded to your thread.

Just tried out Example 1.1 and it works just fine. Running Win XP. Tried uploading the same page on my (under construction) website - host:Tripod.com and the php line does come up as invalid code… No idea wonder why yet. Will try to find out.

Thank you for posting this information.

Very Happy :slight_smile: :- Cass