help-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

httpd can not connect mysql with pdo/php


From: Yoshinori Arai
Subject: httpd can not connect mysql with pdo/php
Date: Thu, 21 Feb 2019 13:08:51 +0900
User-agent: NeoMutt/20180716

Hello,

I have tried to build web development environment like as XAMPP.

At first, I have done system reconfigure to add httpd, mysql and
php-fpm service.  My system configuration that followed guix manual
was as follows,

(operating-system
  ...
  (packages (cons* fluxbox cwm                    ;window managers
                   nss-certs                      ;for HTTPS access
                   ;;httpd mysql php                ;for web develpment
                   %base-packages))

  ;; Use the "desktop" services, which include the X11
  ;; log-in service, networking with NetworkManager, and more.
  (services (cons* (service httpd-service-type
                            (httpd-configuration
                             (config
                              (httpd-config-file
                               (server-name "www.waratonora.org")
                               (document-root "/srv/www")
                               (modules (cons*
                                         (httpd-module
                                          (name "proxy_module")
                                          (file "modules/mod_proxy.so"))
                                         (httpd-module
                                          (name "proxy_fcgi_module")
                                          (file "modules/mod_proxy_fcgi.so"))
                                         %default-httpd-modules))
                               (extra-config (list "\
<FilesMatch \\.php$>
    SetHandler \"proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/\"
</FilesMatch>"))))))
                   (service php-fpm-service-type
                            (php-fpm-configuration
                             (socket "/var/run/php-fpm.sock")
                             (socket-group "httpd")))
                   (mysql-service)
                   %desktop-services))

And I put my script into /srv/www. My script is as follows,

<?php
  $servername = 'localhost';
  $username = 'yoshi';
  $password = 'kumagusuM18';

  try {
      $conn = new PDO("mysql:host=$servername", $username, $password);
      // set the PDO error mode to exception
      $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $sql = "CREATE DATABASE myDBPDO";
      // use exec() because no results are returned
      $conn->exec($sql);
      echo "Database created successfully<br>";
  }
  catch(PDOException $e)
  {
      echo $sql."<br>".$e->getMessage();
  }

$conn = null;
?>

But httpd said 'SQLSTATE[HY000] [2002] No such file or directory' I
thank its cause was wrong configuration of mysql.socket location in
php.ini but I can't edit it easily.

$ php -i | grep socket
pdo_mysql.default_socket => /tmp/mysql.sock => /tmp/mysql.sock

or above configuration of httpd.conf was wrong.

<FilesMatch \\.php$>
    SetHandler \"proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/\"
</FilesMatch>

Its correct configuration will be

<FileMatch \\.php$>
     SetHandler \"proxy:fcgi:127.0.0.1:9000\"
</FileMatch>

At second, I have tried to build its environment without system
reconfigure. My system went back previous generation, and installed
httpd and php personally.  Sqlite was installed instead of mysql.

And configuration files was copyed from
/gnu/store/...-httpd-2.4.38/etc/httpd/* to ~/.config/httpd/
/gnu/store/...-php-7.3.1/etc/php-fpm.conf to ~/.config/php-fpm.conf
                        php-fpm.d/* to ~/.config/php-fpm.d/www.conf

copy sysvinit file from php-7.3.1 source
sapi/fpm/init.d.php-fpm.in to ~/bin/php-fpm

I edited those files adequately after made those writable.

httpd, php-fpm daemon were invoked,
sudo apachectl -f ~/.config/httpd/httpd.conf -k start
sudo bin/php-fpm start

Now httpd and php-fpm conbination is correct when try with below php script in
/srv/www/hello.php.

<?php phpinfo();?>

It was hard to me a little.
Please tell me more easy way.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]