Jump to content

Enabling PHP for use with the Apache Server


mattlevs

Recommended Posts

Hello everyone.

 

I am completely new to the world of PHP and Apache and really need some help with something I'm having trouble with.

 

I am trying to run MySQL, Apache and PHP so that I can begin to understand the use and function of PHP, creating web database applications. I have installed MySQL, the Apache Server and PHP from offical sources on the web.

 

To my problem:

 

According to the guide I'm following the "Apache httpd.conf Configuration File should contain these elements: LoadModule php5_module and AddType application/x-httmpd-php .php

 

The configuration file doesn't contain any of these elements. Therefore when I try to use PHP it doesn't work as it would appear the Apache server is unaware of the use of PHP. Even though they are developed to work along side each other??

 

I'm really confused and would really really appreciate anyones help or suggestions as I am at a loss.

 

Thanks in advance.

 

Matt

 

 

Link to comment
Share on other sites

You'll need to add those lines manually to Apaches configuration file. The following lines can be added anywhere:

LoadModule php5_module "C:/path/to/php/php5apache2_2.dll"

AddType application/x-httpd-php .php

NOTE: Change the path highlighted above to where PHP is installed to.

 

Save the httpd.conf and restart Apache.

Link to comment
Share on other sites

Hello again.

 

I get this message now when trying to test MySQL.

 

Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\mysql_up.php on line 24

 

 

I'm using a test page to try and access MySQL through PHP.

 

This is the page:

 

<?php

 

/* Program: mysql_up.php

 

* Desc:    Connects to MySQL Server and

 

*          outputs settings.

*/

 

echo "<html>

     

      <head><title>Test MySQL</title></head>

     

      <body>";

 

$host="localhost";

 

$user="";

 

$password="";

 

 

 

$cxn = mysqli_connect($host,$user,$password);

 

$sql="SHOW STATUS";

 

$result = mysqli_query($cxn,$sql);

 

if($result == false)

 

{

   

  echo "<h4>Error: ".mysqli_error($cxn)."</h4>";

 

}

 

else

 

{

 

  /* Table that displays the results */

 

  echo "<table border='1'>

 

        <tr><th>Variable_name</th>

     

            <th>Value</th></tr>";

 

  for($i = 0; $i < mysqli_num_rows($result); $i++)

 

  {

   

    echo "<tr>";

   

    $row_array = mysqli_fetch_row($result);

 

    for($j = 0;$j < mysqli_num_fields($result);$j++)

 

    {

       

      echo "<td>".$row_array[$j]."</td>\n";

     

    }

 

 

  }

  echo "</table>";

}

?>

</body></html>

 

 

}

?>

</body></html>

 

 

 

The host user and password elements aren't necessary as I am only using one computer. I wasn't provided with a host user or password...

 

Again, any help would be appreciated...

 

Thanks in advance,

 

Matt

 

 

Link to comment
Share on other sites

php.ini stores all of the settings of PHP.

 

There is a certain format that ini files generally follow.

 

 

[category]

key=value

 

[category2]

key=value

 

 

And then programs have ways of extracting the data.

 

 

 

 

Anyway, you would just open it in notepad (or any other plain-text editor.  vim or gedit on linux for example) search for extension_dir and set a new value.

 

For example, if the extension directory were C:\PHP\ext, you could change extension_dir=blah to:

extension_dir=C:/PHP/ext/

 

(I have a habit of using linux style paths in Apache/PHP files because Windows understands linux paths, but linux does not understand Windows paths.  [in this case, you would have to change it anyway if you moved the file to a linux box for some reason, but it's just a habit.])

Link to comment
Share on other sites

Okay. So just for clarity purposes I noticed there are 2 .ini files in my C:\php folder. There's a "php ini-recommended file" and a "ini-dist file".

 

Before  searching for the extension_dir and setting a new value, which one is correct to use?

 

Also what and where is the PHP's extension folder?

 

Thank you,

 

Matt

Link to comment
Share on other sites

Okay. I added it here:

 

; Windows Extensions

; Note that ODBC support is built in, so no dll is needed for it.

; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)

; extension folders as well as the separate PECL DLL download (PHP 5).

; Be sure to appropriately set the extension_dir directive.

 

;extension_dir=C:/php/ext/php_mysqli.dll

;extension=php_bz2.dll

;extension=php_curl.dll

;extension=php_dba.dll

;extension=php_dbase.dll

 

Is that correct or off the mark?

Link to comment
Share on other sites

lines that start with a seimi-colon ( ; ) are ignored. However the extension_dir should be configured on/near line 542

 

To enable mysql support, remove the semi-colon from the following two lines:

;extension=php_mysql.dll
;extension=php_mysqli.dll

 

Save the php.ini and restart Apache.

Link to comment
Share on other sites

Okay I have followed these instructions to the letter, brilliant.

 

It would seem I'm hitting brick wall after brick wall at the minute, thanks for sticking with me.

 

 

When I try to open a page which tests if MySQL is working correctly, this error message is displayed:

 

Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\mysql_up.php on line 13

 

The document consists of this content:

 

<?php

/* Program: mysql_up.php

* Desc:    Connects to MySQL Server and

*          outputs settings.

*/

echo "<html>

      <head><title>Test MySQL</title></head>

      <body>";

$host="localhost";

$user="";

$password="";

 

$cxn = mysqli_connect($host,$user,$password);

$sql="SHOW STATUS";

$result = mysqli_query($cxn,$sql);

if($result == false)

{

    echo "<h4>Error: ".mysqli_error($cxn)."</h4>";

}

else

{

  /* Table that displays the results */

  echo "<table border='1'>

        <tr><th>Variable_name</th>

            <th>Value</th></tr>";

  for($i = 0; $i < mysqli_num_rows($result); $i++)

  {

    echo "<tr>";

    $row_array = mysqli_fetch_row($result);

      for($j = 0;$j < mysqli_num_fields($result);$j++)

      {

        echo "<td>".$row_array[$j]."</td>\n";

      }

  }

  echo "</table>";

}

?>

</body></html>

 

On setting up of the Apache server I set-up a password as suggested, I didn't opt for the other option of not having one. Therefore, if the file requires a user name, I am lost as to what to enter.

 

I'll get there sooner or later, thanks for being so patient!

 

Matt

 

Link to comment
Share on other sites

check if MySQL is in your phpinfo();

also do you have mysql installed and running ?

 

I can't see a MySQL section in the phpinfo() results when entered into a document saved.php under htdocs... I can't see anything related to MySQL in the table... The table starts with Version 5.28... then Configuration PHP Core... then Apache Handler...

 

MySQL was installed successfully and is running.

 

So I am still clueless.

Link to comment
Share on other sites

Why don't you try out XAMPP?

 

It is a very nice bundle of Apache, MySQL and PHP

 

Worth to give it a try.

 

Regards,

LPM

 

I will have a look into it. If I can I'd like to just try and get the 3 components working side by side as I have made it this far. Once everything is operational and recognising each other, I can then start to learn PHP, as I have the resources to do so... in the form of a nice PHP and MySQL for dummies book...  8)

Link to comment
Share on other sites

If I had a specific problem I'd hope to resolve it from one question, but sadly I'm coming up against more problems as I resolve each one...

 

All I know is PHP is installed and working as it should. The Apache server is functioning correctly as well as the MySQL database. However, when trying to open the PHP file through the server it comes up with this error:

 

Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\mysql_up.php on line 13

 

I might just try the method suggested earlier of using the XAMPP package as, I am just trying to set-up so that I can get to grips with the basics.

 

The book that I am following instructions for is PHP and MySQL for Dummies, but it kind of fools short if things going wrong in the set-up process, hence why I looked for a techincal forum, which could act as a resource later as well.

 

I'm just about to hand in the towel and uninstall then download XAMPP, as I feel you guys have helped all you can.

 

Thanks for everything, it's highly appreciated  ;)

 

Matt

Link to comment
Share on other sites

mysqli_connect is a function defined in the mysqli extension for PHP.

 

 

So, you need to tell PHP to load the MySQLi extension....

 

 

Steps from the beginning:

1.  Make a file with <?php phpinfo(); ?> in it somewhere under your web root.

2.  Go to it in a web browser

3.  See where it says PHP is reading php.ini from.

4.  Open that php.ini in notepad (or copy one there if you want, or you can set an Apache var to control where PHP reads it from)

5.  Find extension_dir and set it to the full path of the directory that the PHP extensions reside in.  (Something like C:/Program Files/PHP/ext/ most likely.)  Make sure to put the trailing slash.  (Not actually sure if it's required, but it would be better to put it anyway.)

6.  Add or uncomment "extension=php_mysqli.dll" someone in the php.ini file.

6.  Restart Apache.

7.  Read the Apache error log and see if it says something about unable to load php_mysqli.dll.  If so, either the wrong php.ini was edited, or the extension_dir is set wrongly.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.