Results 1 to 14 of 14
  1. #1
    Join Date
    Mar 2006
    Posts
    41

    Unanswered: Help installing PHP on my PC

    Hi,

    I've followed the instructions on http://www.devarticles.com/c/a/Apach...der-Windows/5/
    and have succesfully installed Apache and mySQl. When I create the test.php file, store it in the folder .../Apache2.2/htdocs and run it from the web browswer by typping http://localhot/test.php in the address bar I get a webpage saying:

    Code:
    <?php
     echo 'PHP is working.<br>';
     echo phpinfo();
    ?>
    Indicating that php wasn't installed. Could someone tell me what's gone wrong and how to install php so I can make some test scripts.

    Cheers

  2. #2
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    Please list the versions of Apache (apparently 2.2 from your post), mysql (not so important for your PHP problem), and PHP version, and also if you installed PHP as an apache module (per the instructions at the link you provided) or under CGI.

    Note: The instructions at the link you provided as specific to PHP version 4 as an apache module on Apache version 2.0. There is not an official Apache 2.2 PHP sapi dll, so if you have Apache 2.2 and followed the instructions exactly, it won't work.

    You can find an Apache 2.2 PHP sapi dll here - http://www.apachelounge.com/index.php?menu=1

  3. #3
    Join Date
    Mar 2006
    Posts
    41
    Thanks for the reply.

    I've since uninstalled Apache 2.2 and installed Apache 2.0 and so PHP (version 4.4.4) is working now. I am now having trouble conencting to mySQL (version 4.1) using PHP. I granted all priviledges to a user called testuser with password testpassword on localhost and created a database called simple with a table called simple_table (as per the guide).

    When I run the php code:

    Code:
    <?php
     // Connect to the database
     $dbhost = 'localhost';
     $dbusername = 'testuser';
     $dbpasswd = 'testpassword';
     $database_name = 'simple';
     $connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")
      or die ('Couldn\'t connect to server.');
     $db = mysql_select_db("$database_name", $connection)
      or die('Couldn\'t select database.');
    
     // Generate SQL code to store data on database.
     $insert_sql = 'INSERT INTO simple_table (text) VALUES (\'test text, 1,2,3\')';
    
     // Execute SQL code.
     mysql_query( $insert_sql )
      or die ( 'It Didn\t Work: ' . mysql_error() );
    
     // Tell User we are done.
     echo 'Code Inserted';
    ?>
    I get the message:

    Code:
    Couldn't connect to server.
    I there any reason why it can't connect to the database I've created and any way I can check what the problem might be?

    Thanks

  4. #4
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    Try two things -

    1) Add the following line after your opening <?php tag -
    PHP Code:
    error_reporting(E_ALL); 
    I suspect that there will be an error message about an undefined function. If so, the following line in php.ini is commented out and needs to have the ";" removed (stop and start Apache to get the change to take effect) -
    Code:
    ;extension=php_mysql.dll
    2) Try these two lines without the double-quotes surrounding the variable names (the double-quotes should not matter in this case, but you never know) -
    PHP Code:
     $connection mysql_connect($dbhost,$dbusername,$dbpasswd) or die ('Couldn\'t connect to server.');
     
    $db mysql_select_db($database_name$connection) or die('Couldn\'t select database.'); 

  5. #5
    Join Date
    Mar 2006
    Posts
    41
    in the php.ini file there isn't a line that says:

    ;extension=php_mysql.dll

    but there are 2 similar lines which are:

    ;extension=php_mssql.dll
    ;extension=php_msql.dll


    I've uncommented these 2 lines (by removing the ; ) and restarted APACHE but this doen't help. In the php.ini file it says:

    ;Note that MySQL and ODBC support is now built in, so no dll is needed for it.
    So I'm not too sure whether this means it doesn't need the extension=php_mysql.dll


    I also tried removing the double quotation marks but this didn't help either. Is there anything else it could be?

    I am able to connect to this database with no problems using JAVA (and the appropriate JDBC) and so I assume there's nothing wrong with how the database is set up.

    Thanks for your help

  6. #6
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    Hmm. That is an interesting departure from what recent PHP version 4 and the current PHP version 5 is doing.

    Anyway, if we assume that support is in fact built in and available, try changing your mysql statements to include the mysql_error() reporting -
    PHP Code:
    $connection mysql_connect($dbhost,$dbusername,$dbpasswd) or die ('Couldn\'t connect to server.' mysql_error()); 
     
    $db mysql_select_db($database_name$connection) or die('Couldn\'t select database.' mysql_error()); 
    Edit: Also check the Apache server logs to see if there are any errors reported.

  7. #7
    Join Date
    Mar 2006
    Posts
    41
    I've added:

    $connection = mysql_connect($dbhost,$dbusername,$dbpasswd) or die ('Couldn\'t connect to server.' . mysql_error());
    $db = mysql_select_db($database_name, $connection) or die('Couldn\'t select database.' . mysql_error());


    and now get the output:

    Couldn't connect to server.Client does not support authentication protocol requested by server; consider upgrading MySQL client


    in the web browser window.

    in the apache logs I get the error message:

    PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\testconn1.php on line 8


    I'm currently using mySQL server 4.1. Will uninstalling this and installing mySQL 5.0 solve the problem or is there another way around the problem

    Cheers

  8. #8
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    It is normally not this difficult getting any version of PHP and mysql to work together.

    From the error message it would appear that the client library that PHP is using is not compatible with the mysql version and since the client library that PHP is using is built in, your choices would be to change the version of PHP or the version of mysql. I have used earlier PHP 4 versions with both mysql 4 and 5 and I have used PHP 5 versions with both mysql 4 and 5. I currently don't use PHP 4.

    You could check the PHP or mysql forum to see if there is a direct solution.

    For testing and development on a PC, I personally use Apache 2.0.59 (latest 2.0 version), PHP 5.1.6 (latest 5.1 version), and mysql 5.0.24a (latest 5.0 version.)

  9. #9
    Join Date
    Mar 2006
    Posts
    41
    I've downloaded and setup PHP 5 which works. I uncommented the line

    extension=php_mysql.dll

    in the php.ini file.

    I then restarted Apache and run the php file to connect to the mysql database and get the message:

    Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\htdocs\testconn.php on line 8

    In the PHP folder there's a folder called extensions with the file php_mysql.dll. I've copied this file to ...\Apache Group\Apache2\ along with the other php files. Is this correct or should this be located in a certain folder?

    Thanks

  10. #10
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    In PHP 5 the extensions folder should be called "ext".

    The following line in php.ini sets the path where php looks for the extension dll's -
    Code:
    extension_dir = "./"
    Change this to where you installed PHP, something like -
    Code:
    extension_dir = "C:/php5/ext/"
    Normally there is no need to copy any files around.

  11. #11
    Join Date
    Mar 2006
    Posts
    41
    I checked with phpinfo() and it says:

    Code:
    Configuration File (php.ini) Path 	C:\WINDOWS
    I then deleted all the text in the php.ini file in ...\Apache Group\Apache2\ and saved it. I then restarted Apache and php still works. So I assume the php.ini file that I have been modifying is not the one that is being read by Apache.

    The problem is that there isn't a php.ini file in C:\Windows even with all hidden folders/files shown

    Is there any way I can tell Apache which php.ini file it should be loading so I can make the appropriate changes to it.

  12. #12
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    Yes. See the following from the PHP installation instructions -
    Installing as an Apache module

    You need to insert these two lines to your Apache httpd.conf configuration file to set up the PHP module for Apache 2.0:

    # For PHP 5 do something like this:
    LoadModule php5_module "c:/php/php5apache2.dll"
    AddType application/x-httpd-php .php

    # configure the path to php.ini
    PHPIniDir "C:/php"

    Note: Remember to substitute your actual path to PHP for the c:/php/ in the above examples.

  13. #13
    Join Date
    Mar 2006
    Posts
    41
    Thanks .

    I made the changes, restarted Apache and ran the php code that connects to the database and it works . I checked the database and the entries were added to the database.

    Thanks for all your help. It's really appreciated

  14. #14
    Join Date
    Mar 2006
    Posts
    41
    Just one quick question.

    I'm making a mysql backed website where the admin will be able to update news stories and other information on the web site by logging on and simply completing text fields. This will update the database and therefore update the webpage which retrieves the informtion from the database to display it.

    I'm creatnig the website on my PC using the APACHE, PHP and mysql installed. Will it be a simple case of altering the database connection details and creating the appropriate datbase and tables on the mysql server when I come to upload it or are there some complexities involved when transfering it from local host to a webserver.

    Also, are there any free web hosts that offer php and mysql?

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •