all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yoshinori Arai <kumagusu08@gmail.com>
To: help-guix <help-guix@gnu.org>
Subject: httpd can not connect mysql with pdo/php
Date: Thu, 21 Feb 2019 13:08:51 +0900	[thread overview]
Message-ID: <20190221040851.cy5b53hkxhlzbouu@WaraToNora> (raw)

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	other threads:[~2019-02-21  4:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190221040851.cy5b53hkxhlzbouu@WaraToNora \
    --to=kumagusu08@gmail.com \
    --cc=help-guix@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.