mattlevs Posted January 31, 2009 Share Posted January 31, 2009 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted January 31, 2009 Share Posted January 31, 2009 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. Quote Link to comment Share on other sites More sharing options...
mattlevs Posted January 31, 2009 Author Share Posted January 31, 2009 Perfect. Thank you. Quote Link to comment Share on other sites More sharing options...
mattlevs Posted January 31, 2009 Author Share Posted January 31, 2009 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 Quote Link to comment Share on other sites More sharing options...
corbin Posted January 31, 2009 Share Posted January 31, 2009 You need to set php to load the MySQLi extension. Uncomment: extension=php_mysqli.dll in php.ini Quote Link to comment Share on other sites More sharing options...
mattlevs Posted January 31, 2009 Author Share Posted January 31, 2009 You need to set php to load the MySQLi extension. Uncomment: extension=php_mysqli.dll in php.ini Hey. The php_mysqli.dll file is located in the main PHP directory. How do I set it up to load the extension? Cheers. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted January 31, 2009 Share Posted January 31, 2009 php_mysqli.dll should be located within the ext/ folder. Before enabling PHP extensions you should first add PHP to the PATH Environment Variable. You should also set the extension_dir directive within the php.ini to the full path to PHP's extension folder. Quote Link to comment Share on other sites More sharing options...
mattlevs Posted January 31, 2009 Author Share Posted January 31, 2009 Okay. I have added PHP to the Path Environment Variable. I am still unclear as to what php.ini is and how to set the extension_dir directive within it? I'm really greatful to all the help as I am progressing. Thanks in advance, Matt Quote Link to comment Share on other sites More sharing options...
corbin Posted February 1, 2009 Share Posted February 1, 2009 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.]) Quote Link to comment Share on other sites More sharing options...
mattlevs Posted February 1, 2009 Author Share Posted February 1, 2009 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 1, 2009 Share Posted February 1, 2009 rename the file named php.ini-recommended to just php.ini (forgot to mention this earlier). This is the file you use to configure PHP. Whenever you make any changes to this file make sure you restart Apache Quote Link to comment Share on other sites More sharing options...
mattlevs Posted February 1, 2009 Author Share Posted February 1, 2009 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? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 1, 2009 Share Posted February 1, 2009 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. Quote Link to comment Share on other sites More sharing options...
mattlevs Posted February 1, 2009 Author Share Posted February 1, 2009 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 Quote Link to comment Share on other sites More sharing options...
MadTechie Posted February 1, 2009 Share Posted February 1, 2009 check if MySQL is in your phpinfo(); also do you have mysql installed and running ? Quote Link to comment Share on other sites More sharing options...
mattlevs Posted February 1, 2009 Author Share Posted February 1, 2009 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. Quote Link to comment Share on other sites More sharing options...
mattlevs Posted February 1, 2009 Author Share Posted February 1, 2009 P.S. I just downloaded the 5.2.8. debug pack. Inside it has files relating to MySQL. Where should I put this files contents? Quote Link to comment Share on other sites More sharing options...
Lucky_PHP_MAN Posted February 1, 2009 Share Posted February 1, 2009 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 Quote Link to comment Share on other sites More sharing options...
mattlevs Posted February 1, 2009 Author Share Posted February 1, 2009 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... Quote Link to comment Share on other sites More sharing options...
mattlevs Posted February 1, 2009 Author Share Posted February 1, 2009 Any suggestions guys? Quote Link to comment Share on other sites More sharing options...
corbin Posted February 1, 2009 Share Posted February 1, 2009 We've already told you how to set the extension directory and uncomment the line.... That's all you should need to know. Do you have a specific problem, or are you just stuck? Quote Link to comment Share on other sites More sharing options...
mattlevs Posted February 1, 2009 Author Share Posted February 1, 2009 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 Quote Link to comment Share on other sites More sharing options...
corbin Posted February 1, 2009 Share Posted February 1, 2009 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. Quote Link to comment Share on other sites More sharing options...
mattlevs Posted February 1, 2009 Author Share Posted February 1, 2009 Thank you so much for your time and effort! The phpinfo() page displayed: Configuration File (php.ini) Path C:\WINDOWS So it doesn't actually have a path. Quote Link to comment Share on other sites More sharing options...
corbin Posted February 1, 2009 Share Posted February 1, 2009 You can add a PHPIniDir line in httpd.conf, or you can just put a php.ini in C:\Windows\. Sometimes it will load files outside of the search path though. Does it say anything about a php.ini file that is currently loaded? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.