Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Installing PHP,Apache and MySQL

  • 18-09-2007 7:57pm
    #1
    Registered Users, Registered Users 2 Posts: 4,075 ✭✭✭


    OK, I give up. I'm at my wits end, I did PHP a few years ago but I didn't have to install the server and database as it was in college and it was all done already.
    I have been trying to do it on my own machine for the last two days with little success. I've got PHP working as I got that page to display where it shows the time (it's on most tutorials on the web) and the one where you pass a query string contained in a text box into a web page.
    Here's the PHP file called "send.php":
    <?php
    if($_GET['username'] == "")
    {
        // no username entered
    
        echo "You did not enter a name.";
    }
    else
    {
        echo "Hello, " . $_GET['username'];
    }
    ?>
    

    This is the HTML:
    <HTML>
    <HEAD>
    <TITLE>Page</TITLE>
    
    </HEAD>
    <BODY>
    
    <form method="GET" action="page.php">
    
          Please enter your name: <input type="text" name="username" />
       
          <input type="submit" value="submit" />
      
          </form>
    </body>
    </html>
    

    However I am trying to insert a string into a table in MYSQL with no success.
    I want to connect to the MYSQL database from Apache Server and insert the data in PHP:
    <?
    if ($inputbox1 = "")
    {
    echo("You did not fill the input box correctly <br>");
    }
    else
    {
       
      @mysql_connect("localhost", "root", "fonzi");
    
      if ($dbcnx==0) {
    	echo( "<p>Unable to connect to the MYSQL " ."database server at this time.</p>" );
      exit(); }
    
    if (@mysql_select_db("phpcake")==0 ) {
    echo( "<p>Unable to locate the user" .
    "database at this time.</p>" );
    exit();
    }
    
      if ($Submitdetails == "SUBMIT") {
    
    $sql = "INSERT INTO toppings SET name='$inputbox1'";
    
          if (@mysql_query($sql)==0) 
          {
        echo("<p>Error : " . mysql_error() . 
        "</p>");
          }
          else
    	 {
         	echo("Thank you! <p><a href='Interactive.html'>Go Back</a>");
    	 }
     }
     }
    ?>
    
    This is the HTML:
    <HTML>
    <HEAD>
    <TITLE>Interactive Page</TITLE>
    
    </HEAD>
    <BODY>
    <FORM name=myform ACTION="send.php" method="post"> 
    
    <table border= 0 cellspacing=0 cellpadding=0>
    
    
    <tr><td>Enter song title: </td> 
    	<td><INPUT TYPE="text" NAME="inputbox1"></td></tr> 
    
    
    <INPUT TYPE="submit" NAME="Submitdetails" VALUE="SUBMIT">
    
     
          <P><P>
    </FORM>
    
    </body>
    </html>
    

    I presume I have something set incorrectly in the "php.ini" file.
    The problem is that there are loads of tutorials out there but they all tell you different things.
    I don't even know if I am connecting to the database, is there any way of debugging this where I can step through it to see exactly what's going on?


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Yeah, you want to look for your PHP.ini file.

    There's a directive called error_reporting. This can be set to show only errors at a certain level of severity.

    For production servers, this directive should be set to E_NONE. For test/development boxes, I would always recommend setting this to E_ALL.

    At the very least, if you're not connecting to MySQL then you should see this in the error output, so I'm guessing that the error_reporting directive is the problem.

    What version of PHP and Apache did you install and are you getting any error output?


  • Registered Users Posts: 912 ✭✭✭chakotha


    What output are you getting from each script pair?

    The ACTION of the first HTML form should be pointing at the first PHP file.

    You could rename the following script page.php
    <?php
    if($_GET['username'] == "")
    {
        // no username entered
    
        echo "You did not enter a name.";
    }
    else
    {
        echo "Hello, " . $_GET['username'];
    }
    ?>
    
    I think that should work.

    Rename the second PHP block send.php ie.
    <?
    if ($inputbox1 = "")
    {
    echo("You did not fill the input box correctly <br>");
    }
    else
    {
       
      @mysql_connect("localhost", "root", "fonzi");
    
      if ($dbcnx==0) {
    	echo( "<p>Unable to connect to the MYSQL " ."database server at this time.</p>" );
      exit(); }
    
    if (@mysql_select_db("phpcake")==0 ) {
    echo( "<p>Unable to locate the user" .
    "database at this time.</p>" );
    exit();
    }
    
      if ($Submitdetails == "SUBMIT") {
    
    $sql = "INSERT INTO toppings SET name='$inputbox1'";
    
          if (@mysql_query($sql)==0) 
          {
        echo("<p>Error : " . mysql_error() . 
        "</p>");
          }
          else
    	 {
         	echo("Thank you! <p><a href='Interactive.html'>Go Back</a>");
    	 }
     }
     }
    ?>
    
    At the top of this script you may want the lines
    <?
    if (isset($_POST["inputbox1"]) && isset($_POST["Submitdetails "])) {
    
        $inputbox1=$_POST["inputbox1"];
        $Submitdetails =$_POST["Submitdetails "];
    
    }
    ?>
    


  • Registered Users, Registered Users 2 Posts: 4,075 ✭✭✭lukin


    seamus wrote:
    Yeah, you want to look for your PHP.ini file.

    There's a directive called error_reporting. This can be set to show only errors at a certain level of severity.

    For production servers, this directive should be set to E_NONE. For test/development boxes, I would always recommend setting this to E_ALL.

    At the very least, if you're not connecting to MySQL then you should see this in the error output, so I'm guessing that the error_reporting directive is the problem.

    What version of PHP and Apache did you install and are you getting any error output?

    PHP is version 5.2.4. Apache is version 2.0.5.
    I'll have a look at the PHP.ini file.


  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    first thing I'm seeing here is ...

      @mysql_connect("localhost", "root", "fonzi");
    
      if ($dbcnx==0) {
    

    $dbcnx ... has never been defined so its going to be null / 0 ... unless something has changed :)


  • Registered Users, Registered Users 2 Posts: 4,075 ✭✭✭lukin


    seamus wrote:
    Yeah, you want to look for your PHP.ini file.

    There's a directive called error_reporting. This can be set to show only errors at a certain level of severity.

    For production servers, this directive should be set to E_NONE. For test/development boxes, I would always recommend setting this to E_ALL.

    I don't have that at all in my php.ini seamus, all I have that might be similar is this:

    #<VirtualHost *:80>
    # ServerAdmin webmaster@dummy-host.example.com
    # DocumentRoot /www/docs/dummy-host.example.com
    # ServerName dummy-host.example.com
    # ErrorLog logs/dummy-host.example.com-error_log
    # CustomLog logs/dummy-host.example.com-access_log common
    #</VirtualHost>
    seamus wrote:
    What version of PHP and Apache did you install and are you getting any error output?
    PHP is version 5.2.4. Apache is version 2.0.5.
    No I'm not getting any error output. After I hit "submit" it either goes to a blank page or just displays the php on the html page.


    OK, now I have completely changed the PHP to just insert a hard coded string instead of what's in the text box but it still doesn't work.
    <?
    if ($inputbox1 = "")
    {
    echo("You did not fill the input box correctly");
    }
    else
    
    {
       
      @mysql_connect("localhost", "root", "fonzi");
    
    
    @mysql_select_db("phpcake");
    
    
    
     if ($Submitdetails == "SUBMIT") {
    
    
    $sql = "INSERT INTO toppings VALUES ('cream');";
    
          if (@mysql_query($sql)==0) 
          {
        echo("Error ");
          }
          else
    	 {
         	echo("Thank you!");
    	 }
     				}
    
    
    }
    
    
    ?>
    


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    lukin wrote:
    I don't have that at all in my php.ini seamus, all I have that might be similar is this:

    #<VirtualHost *:80>
    # ServerAdmin webmaster@dummy-host.example.com
    # DocumentRoot /www/docs/dummy-host.example.com
    # ServerName dummy-host.example.com
    # ErrorLog logs/dummy-host.example.com-error_log
    # CustomLog logs/dummy-host.example.com-access_log common
    #</VirtualHost>

    that looks like you're editing your httpd.conf file not you php.ini file ...


  • Registered Users, Registered Users 2 Posts: 4,075 ✭✭✭lukin


    forbairt wrote:
    that looks like you're editing your httpd.conf file not you php.ini file ...

    S***e, sorry ,you are right. There's a lot of stuff in that php.ini file, the error_reporting variable is et to E_ALL as seamus advised but I don't know what it's for.


  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    fortunately / unfortunately you're going down the ... trying to learn by yourself route .... part of this involves having a route yourself and figuring things out sometimes

    take a read through ... http://www.php.net/error_reporting


  • Registered Users, Registered Users 2 Posts: 4,075 ✭✭✭lukin


    OK I've got it writing to an error log and this is what it said:

    18-Sep-2007 22:02:50] PHP Warning: PHP Startup: Unable to load dynamic library './ext\php_mysql.dll' - The specified module could not be found.

    This is the only mention of php_mysql.dll in php.ini:

    ;;;;;;;;;;;;;;;;;;;;;;
    ; Dynamic Extensions ;
    ;;;;;;;;;;;;;;;;;;;;;;
    ;
    ; If you wish to have an extension loaded automatically, use the following
    ; syntax:
    ;
    ; extension=modulename.extension
    ;
    ; For example, on Windows:
    ;
    extension=php_mysql.dll
    ;
    ; ... or under UNIX:
    ;
    ; extension=msql.so
    ;
    ; Note that it should be the name of the module only; no directory information
    ; needs to go here. Specify the location of the extension with the
    ; extension_dir directive above.


  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    Did you install wampserver the other day like I recommended ??


    Anyways check in your php directory and within the ext directory for a file php_mysql.dll if it doesn't exist there then you've got a problem


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    lukin wrote:
    18-Sep-2007 22:02:50] PHP Warning: PHP Startup: Unable to load dynamic library './ext\php_mysql.dll' - The specified module could not be found.
    OK, on windows this points to one of three possible problems:

    1. The "extension_dir" directive in your PHP.ini isn't set correctly. There are a number of php_extname.dll extensions that can be loaded in PHP, but you have to tell the PHP.ini where to find them. Usually this is <path_to_php_install>\ext\

    2. php_mysql.dll doesn't exist in the above directory. If you have the PHP binary files in a zip, you can just drop that DLL into the directory.

    3. The account that Apache is running under, doesn't have permission to access/read/execute in the above directory. If this is a development machine, there's not much harm in granting the "Everyone" group read & execute access to the PHP install directory and all subdirectories.


  • Registered Users, Registered Users 2 Posts: 4,075 ✭✭✭lukin


    forbairt wrote:
    Did you install wampserver the other day like I recommended ??

    No I've been trying to get this working instead. Can I get PHP working on that?
    forbairt wrote:
    Anyways check in your php directory and within the ext directory for a file php_mysql.dll if it doesn't exist there then you've got a problem


    Yeah it's there.


  • Registered Users, Registered Users 2 Posts: 4,075 ✭✭✭lukin


    seamus wrote:
    OK, on windows this points to one of three possible problems:

    1. The "extension_dir" directive in your PHP.ini isn't set correctly. There are a number of php_extname.dll extensions that can be loaded in PHP, but you have to tell the PHP.ini where to find them. Usually this is <path_to_php_install>\ext\

    2. php_mysql.dll doesn't exist in the above directory. If you have the PHP binary files in a zip, you can just drop that DLL into the directory.

    3. The account that Apache is running under, doesn't have permission to access/read/execute in the above directory. If this is a development machine, there's not much harm in granting the "Everyone" group read & execute access to the PHP install directory and all subdirectories.


    I've actually sorted that, there's no errors being written to my log file now but still there's nothing doing with the form I want to submit.


  • Registered Users, Registered Users 2 Posts: 15,065 ✭✭✭✭Malice


    forbairt wrote:
    Did you install wampserver the other day like I recommended ??


    Anyways check in your php directory and within the ext directory for a file php_mysql.dll if it doesn't exist there then you've got a problem
    I would also highly recommend installing WAMP Server. I had to setup PHP/Apache/MySQL on a test box last month and it was a real headache until I used WAMP Server to do all the configuration for me. I don't know if something has changed in recent versions of PHP or MySQL or what but I couldn't get them to talk to each other despite the fact that I have set them up many times in the past.


  • Registered Users, Registered Users 2 Posts: 4,075 ✭✭✭lukin


    seamus wrote:
    OK, on windows this points to one of three possible problems:

    1. The "extension_dir" directive in your PHP.ini isn't set correctly. There are a number of php_extname.dll extensions that can be loaded in PHP, but you have to tell the PHP.ini where to find them. Usually this is <path_to_php_install>\ext\

    2. php_mysql.dll doesn't exist in the above directory. If you have the PHP binary files in a zip, you can just drop that DLL into the directory.

    3. The account that Apache is running under, doesn't have permission to access/read/execute in the above directory. If this is a development machine, there's not much harm in granting the "Everyone" group read & execute access to the PHP install directory and all subdirectories.


    I've actually sorted that, there's no errors being written to my log file now but still there's nothing doing with the form I want to submit.

    There's this part of php.inf that I am not sure about :
    [MySQLi]
    
    ; Maximum number of links.  -1 means no limit.
    mysqli.max_links = -1
    
    ; Default port number for mysqli_connect().  If unset, mysqli_connect() will use
    ; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
    ; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
    ; at MYSQL_PORT.
    mysqli.default_port = 3306
    
    ; Default socket name for local MySQL connects.  If empty, uses the built-in
    ; MySQL defaults.
    mysqli.default_socket = localhost
    
    ; Default host for mysql_connect() (doesn't apply in safe mode).
    mysqli.default_host = 
    
    ; Default user for mysql_connect() (doesn't apply in safe mode).
    mysqli.default_user =
    
    ; Default password for mysqli_connect() (doesn't apply in safe mode).
    ; Note that this is generally a *bad* idea to store passwords in this file.
    ; *Any* user with PHP access can run 'echo get_cfg_var("mysqli.default_pw")
    ; and reveal this password!  And of course, any users with read access to this
    ; file will be able to reveal the password as well.
    mysqli.default_pw =
    
    ; Allow or prevent reconnect
    mysqli.reconnect = Off
    
    
    Should mysqli.default_socket, mysqli.default_host and mysqli.default_user be assigned values?
    Also, is it normally this difficult to set up PHP? I thought it would be a piece of piss and people on here would laugh at me for not being able to do it.


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    I have probably installed PHP around 30 times now. Different versions of PHP on different versions of IIS and Apache. The only thing that's certain is that the install will probably not go exactly the same way as it did the last time you did it :)

    Don't worry too much about those mysqli options. mysqli is a different library to mysql, but for the sake of eliminating all issues, I would delete the values in the port and socket directives.


  • Registered Users, Registered Users 2 Posts: 4,075 ✭✭✭lukin


    seamus wrote:
    I have probably installed PHP around 30 times now. Different versions of PHP on different versions of IIS and Apache. The only thing that's certain is that the install will probably not go exactly the same way as it did the last time you did it :)

    Don't worry too much about those mysqli options. mysqli is a different library to mysql, but for the sake of eliminating all issues, I would delete the values in the port and socket directives.

    Would using a debugger help?At least then I could step into the code and see what is going on. I googled it and found this:
    http://www.freedownloadscenter.com/Best/best-php-editor.html


  • Registered Users, Registered Users 2 Posts: 15,065 ✭✭✭✭Malice


    lukin wrote:
    Should mysqli.default_socket, mysqli.default_host and mysqli.default_user be assigned values?
    Also, is it normally this difficult to set up PHP? I thought it would be a piece of piss and people on here would laugh at me for not being able to do it.
    Those three values are blank in my php.ini (which works). Setting up PHP can be a pain in the posterior. As Seamus says, something different always seems to crop up.


  • Registered Users, Registered Users 2 Posts: 673 ✭✭✭Bananna man


    I had the exact same problem when i started up with php. After about a week of pulling my hair out i came across Easy PHP . Its only version 4.3.10 but its really easy to get going. Just follow the instructions for the php, apache and mysql and you will be up and running in about 5 - 10 mins max.


  • Registered Users, Registered Users 2 Posts: 4,075 ✭✭✭lukin


    I had the exact same problem when i started up with php. After about a week of pulling my hair out i came across Easy PHP . Its only version 4.3.10 but its really easy to get going. Just follow the instructions for the php, apache and mysql and you will be up and running in about 5 - 10 mins max.

    I'll give it a go. I presume I have to uninstall PHP, Apache and MYSQL before I use it?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,488 ✭✭✭AdrianII


    do a search for xammp

    i used it for my college project, it is the business


  • Registered Users, Registered Users 2 Posts: 673 ✭✭✭Bananna man


    lukin wrote:
    I'll give it a go. I presume I have to uninstall PHP, Apache and MYSQL before I use it?

    I cant remember now but its probably best to uninstall it first alright.


  • Registered Users, Registered Users 2 Posts: 4,075 ✭✭✭lukin


    I cant remember now but its probably best to uninstall it first alright.

    The instructions advised to uninstall IIS?!!
    http://www.canowhoopass.com/guides/easyphp/install.php
    No way am I doing that as I use it for ASP.


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    I always wondered what the @ symbol did in PHP. I've never used it :D

    lukin, remove all instances of the @ symbol in your code.

    When you call a function and precede it with the @ symbol, all errors generated by that function are ignored.

    When you remove this symbol, you should see a tonne of errors appear.


  • Registered Users, Registered Users 2 Posts: 4,075 ✭✭✭lukin


    I've got things working now thanks to that easyphp app.
    It explained things pretty well and loading the ini and conf files into an app called Crimson Editor helped a lot as it had color coding which helped me find things.
    I am still a little pissed off that I didn't get it going by installing PHP, MYSQL and Apache separately. I'd say what seamus said about that '@' sybol was the cause of my grief. I'll never know now anyway...


Advertisement