all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* httpd can not connect mysql with pdo/php
@ 2019-02-21  4:08 Yoshinori Arai
  0 siblings, 0 replies; only message in thread
From: Yoshinori Arai @ 2019-02-21  4:08 UTC (permalink / raw)
  To: help-guix

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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-02-21  4:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-21  4:08 httpd can not connect mysql with pdo/php Yoshinori Arai

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.