J.Doe
Posts: 5
Joined: Wed Sep 13, 2017 9:16 am

MySQL on RPI

Wed Sep 13, 2017 9:30 am

Hi,

I'm trying to install apache2+php+mysql on my RPI 3 with Raspbian. Apache2 and php works, but mysql gives me only pain. Mostly there are no more repesitories.

SQLite works on my RPI but mysql doesn't (phpinfo() shows, that there is no PDO driver). But SQLite is not I want, because I want to transfer webpage from one device to rpi and changing code would be painfull.

I was googling a lot. Every tutorial I saw was a failure for me.

DirkS
Posts: 7616
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: MySQL on RPI

Wed Sep 13, 2017 4:51 pm

J.Doe wrote:
Wed Sep 13, 2017 9:30 am
I was googling a lot. Every tutorial I saw was a failure for me.
So you did not get any references to MariaDB?
It's basically a slot-in replacement for MySQL.
And IIRC in Debian / Raspbian Stretch MariaDB completely replaces MySQL

Try searching the forum for MariaDB: https://www.google.co.uk/search?dcr=0&q ... SHPqI5Pwos

J.Doe
Posts: 5
Joined: Wed Sep 13, 2017 9:16 am

Re: MySQL on RPI

Thu Sep 14, 2017 7:48 am

Ok, it seems like MariaDB needs PHP7, and I had php5. I have apache2 and php7 on rpi, but apache2 is not using php7 at all.

I've done

Code: Select all

apt-get install apache2 php7.0 php7.0-curl php7.0-gd php7.0-imap php7.0-json php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-xmlrpc libapache2-mod-php7.0
and checked with

Code: Select all

php -v
where the answer was

Code: Select all

PHP 7.0.19-1 (cli) (built: May 11 2017 14:04:47) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.19-1, Copyright (c) 1999-2017, by Zend Technologies

Code: Select all

phpinfo()
is not working (just plain text is displayed)

What is wrong?

User avatar
rpdom
Posts: 11698
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: MySQL on RPI

Thu Sep 14, 2017 7:59 am

I use php7.0-fpm with Apache on my Ubuntu PC. I assume it would work the same on a Pi (I haven't tried it yet).

J.Doe
Posts: 5
Joined: Wed Sep 13, 2017 9:16 am

Re: MySQL on RPI

Thu Sep 14, 2017 8:02 am

Installed, apache2 restarted... nothing changes

User avatar
rpdom
Posts: 11698
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: MySQL on RPI

Thu Sep 14, 2017 8:11 am

Ok, I've got a few minutes and a Pi 3B that isn't currently in use. I'll install the latest Stretch Lite and test Apache + Mariadb + PHP to test this.

J.Doe
Posts: 5
Joined: Wed Sep 13, 2017 9:16 am

Re: MySQL on RPI

Thu Sep 14, 2017 8:13 am

I appreciate that.

User avatar
rpdom
Posts: 11698
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: MySQL on RPI

Thu Sep 14, 2017 8:31 am

Installed Raspbian Stretch Lite, and made sure that everything was up to date.

Code: Select all

sudo apt-get update
sudo apt-get upgrade (only upgraded dhcpcd5)
sudo apt-get install apache2 php7.0-mysql mariadb-server php7.0-fpm
Create a test file /var/www/html/fred.php

Code: Select all

<?php
phpinfo();
?>
enabled php-fpm as per the instructions
NOTICE: Not enabling PHP 7.0 FPM by default.
NOTICE: To enable PHP 7.0 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php7.0-fpm
NOTICE: You are seeing this message because you have apache2 package installed.

Code: Select all

a2enmod proxy_fcgi setenvif
a2enconf php7.0-fpm
(Ok, it turned out that setenvif was already enabled, but that doesn't matter)
Restart apache as instructed

Code: Select all

systemctl reload apache2
navigate to http ://IP_address_of_Pi/fred.php in a browser
PHP Version 7.0.19-1 and all the info is displayed.

There may be other ways, but this worked for me.

J.Doe
Posts: 5
Joined: Wed Sep 13, 2017 9:16 am

Re: MySQL on RPI

Thu Sep 14, 2017 8:46 am

It worked. phpinfo() shows information and PDO driver is MySQL. Now I have to fight with

Code: Select all

SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'

EDIT: It was solved by making new user in MariaDB and using this user by website

Return to “Networking and servers”

Who is online

Users browsing this forum: Burngate and 20 guests