how to connect to mysql using php on chrooted apache - BSD

This is a discussion on how to connect to mysql using php on chrooted apache - BSD ; Hi, I am trying to setup a test web server with php + mysql + apache (default chroot and configured to use virtualhost) on OpenBSD 3.8 but I have the notorious socket problem. I installed all through packages (php 5.0.4, ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: how to connect to mysql using php on chrooted apache

  1. how to connect to mysql using php on chrooted apache

    Hi,
    I am trying to setup a test web server with php + mysql + apache (default
    chroot and configured to use virtualhost) on OpenBSD 3.8 but I have the
    notorious socket problem. I installed all through packages (php 5.0.4,
    Apache 1.3.29 and mysql 4.0.24). The /var and /var/www are on the same
    partition.
    If a run a test php to mysql connection script

    $connessione = mysql_connect("localhost", "blog", "mypassword") or
    die("Connessione non riuscita: " . mysql_error());
    print ("Connesso con successo");
    mysql_close($connessione);
    ?>

    I receive this error

    Warning: mysql_connect() [function.mysql-connect]: Can't connect to local
    MySQL server through socket '/var/www/var/run/mysql/mysql.sock' (2)
    in /blog/htdocs/test.php on line 5
    Connessione non riuscita: Can't connect to local MySQL server through socket
    '/var/www/var/run/mysql/mysql.sock' (2)

    I start mysql using this on rc.local

    if [ X"${mysql}" == X"YES" -a -x /usr/local/bin/mysqld_safe ]; then

    echo -n " mysqld \n"; /usr/local/bin/mysqld_safe --user=_mysql --log
    --open-files-limit=256 &

    for i in 1 2 3 4 5 6; do
    if [ -S /var/run/mysql/mysql.sock ]; then
    break
    else
    sleep 1
    echo -n "."
    fi
    done
    #
    # Apache chroot Settings

    mkdir -p /var/www/var/run/mysql
    sleep 2
    rm -f /var/www/var/run/mysql/mysql.sock
    ln /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock
    fi

    Actually I connect php using the 3306 port but I want to use the
    skip-networking option for increase security.
    Anyone can help me?
    Thanks
    dat


  2. Re: how to connect to mysql using php on chrooted apache

    dat wrote in
    news:Zx17g.111416$PR2.1727623@twister2.libero.it:

    > ...
    > Warning: mysql_connect() [function.mysql-connect]: Can't connect to
    > local MySQL server through socket '/var/www/var/run/mysql/mysql.sock'
    > (2) in /blog/htdocs/test.php on line 5
    > Connessione non riuscita: Can't connect to local MySQL server through
    > socket '/var/www/var/run/mysql/mysql.sock' (2)


    Hmm, this should have been /var/run/mysql/mysql.sock (as it is in the
    chroot ...)

    Do you have a /etc/my.cnf or a /var/www/etc/my.cnf ?

  3. Re: how to connect to mysql using php on chrooted apache

    Peter Strömberg non potendone piu ha scritto...

    > dat wrote in
    > news:Zx17g.111416$PR2.1727623@twister2.libero.it:
    >
    >> ...
    >> Warning: mysql_connect() [function.mysql-connect]: Can't connect to
    >> local MySQL server through socket '/var/www/var/run/mysql/mysql.sock'
    >> (2) in /blog/htdocs/test.php on line 5
    >> Connessione non riuscita: Can't connect to local MySQL server through
    >> socket '/var/www/var/run/mysql/mysql.sock' (2)

    >
    > Hmm, this should have been /var/run/mysql/mysql.sock (as it is in the
    > chroot ...)
    >
    > Do you have a /etc/my.cnf or a /var/www/etc/my.cnf ?


    You have right, /var/www/var/run/mysql/mysql.sock was setted on php.ini, I
    have removed it and now all works fine. Also, before this, I have done
    other things that I don't remeber so I actually don't know were was the
    problem , I am pretty sure that even when the default socket
    was /var/run/mysql/mysql.sock it did not worked (maybe this can have solved
    shlib_dirs="$shlib_dirs /usr/local/lib/mysql"??).
    However Thank you
    dat

  4. Re: how to connect to mysql using php on chrooted apache

    dat wrote:
    > Connessione non riuscita: Can't connect to local MySQL server through socket
    > '/var/www/var/run/mysql/mysql.sock' (2)
    >

    check the mysql section of php.ini, there should be a setting for mysql.sock location.
    Gio'

  5. Re: how to connect to mysql using php on chrooted apache

    dat wrote:
    > Peter Str?mberg non potendone piu ha scritto...
    >
    >> dat wrote in
    >> news:Zx17g.111416$PR2.1727623@twister2.libero.it:
    >>
    >>> ...
    >>> Warning: mysql_connect() [function.mysql-connect]: Can't connect to
    >>> local MySQL server through socket '/var/www/var/run/mysql/mysql.sock'
    >>> (2) in /blog/htdocs/test.php on line 5
    >>> Connessione non riuscita: Can't connect to local MySQL server through
    >>> socket '/var/www/var/run/mysql/mysql.sock' (2)

    >>
    >> Hmm, this should have been /var/run/mysql/mysql.sock (as it is in the
    >> chroot ...)
    >>
    >> Do you have a /etc/my.cnf or a /var/www/etc/my.cnf ?

    >
    > You have right, /var/www/var/run/mysql/mysql.sock was setted on php.ini, I
    > have removed it and now all works fine. Also, before this, I have done
    > other things that I don't remeber so I actually don't know were was the
    > problem , I am pretty sure that even when the default socket
    > was /var/run/mysql/mysql.sock it did not worked (maybe this can have solved
    > shlib_dirs="$shlib_dirs /usr/local/lib/mysql"??).
    > However Thank you


    Since MySQL is not an entirely safe daemon, especially with its
    filesystem-level commands (something with 'FROM/TO file', but I forgot
    the exact command), chrooting it may be a wise course of action. In this
    case, I'd advise a separate chroot and communication via internet-domain
    sockets (i.e., IP via lo0).

    Joachim

+ Reply to Thread