How to Install Mysql on bpi-R3

Hi there,

after struggeling to get mysql working on my bpi-r3 for nearly a week, I will post this if someone also wants to use mysql on his device.

Before getting started make sure you heve enogh space on your device. If you are using a SD card you expand it following this tutorial hoto-resize-overlay-bpi-r3-on-sdcard (Note it delets every work on it).

Iam using lighttpd and php8 as well as mariadb.

1. Install Packages

First install lighttpd and php and because i am using nano also nano.

opkg update
opkg install lighttpd lighttpd-mod-cgi
opkg install php8 php8-cgi 
opkg install nano

Note: you may need additional php packages to use mysqli in php.

2. Next configure lighttpd

nano /etc/lighttpd/lighttpd.conf 

--> add server.port = here 8012 normal 80
--> edit server.document-root = “” here “/srv/www”

### Documentation
# https://wiki.lighttpd.net/
#
### Configuration Syntax
# https://wiki.lighttpd.net/Docs_Configuration
#
### Configuration Options
# https://wiki.lighttpd.net/Docs_ConfigurationOptions
#
### Configuration Variables (potentially used in /etc/lighttpd/conf.d/*.conf)
var.log_root    = "/var/log/lighttpd/"
var.server_root = "/www/"
var.state_dir   = "/var/run/"
var.home_dir    = "/var/lib/lighttpd/"
var.conf_dir    = "/etc/lighttpd"
var.vhosts_dir  = server_root + "/vhosts"
var.cache_dir   = "/var/cache/lighttpd"
var.socket_dir  = home_dir + "/sockets"

### OpenWRT lighttpd base configuration
server.document-root        = "/srv/www"
server.port                 = 8012
server.upload-dirs          = ( "/tmp" )
server.errorlog             = log_root + "error.log"
server.pid-file             = state_dir + "lighttpd.pid"
server.username             = "http"
server.groupname            = "www-data"

# historical; preserved for compatibility; should have been disabled by default
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm",
                              )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

include "/etc/lighttpd/mime.conf"
nano /etc/lighttpd/conf.d/30-cgi.conf

--> cgi-assign add “.php” => “/usr/bin/php8-cgi” (add , in the line before)

######################################################################
##
##  CGI modules
## ---------------
##
## See https://redmine.lighttpd.net/projects/lighttpd/wiki/docs_modcgi
##
server.modules += ( "mod_cgi" )

##
## Plain old CGI handling
##
## For PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini.
##
cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
                               ".cgi" => "/usr/bin/perl",
                               ".rb"  => "/usr/bin/ruby",
                               ".erb" => "/usr/bin/eruby",
                               ".py"  => "/usr/bin/python",
                               ".php" => "/usr/bin/php8-cgi" )

##
## to get the old cgi-bin behavior of apache
##
## Note: make sure that mod_alias is loaded if you uncomment the
##       next line. (see modules.conf)
##
#alias.url += ( "/cgi-bin" => server_root + "/cgi-bin" )
#$HTTP["url"] =~ "^/cgi-bin" {
#   cgi.assign = ( "" => "" )
#}

##
## require execute permission (+x) on files for CGI scripts
## default: disable
##

3. next configure php

nano /etc/php.ini
--> edit doc_root to “/srv/www” or leave it blank

4. Test PHP

mkdir -p /srv/www
nano /srv/www/test.php

write this into the file

<?php
phpinfo();
?>

Start lighttpd

/etc/init.d/lighttpd start
/etc/init.d/lighttpd enable

open Website with (your ip):(your port)/test.php (eg 192.168.1.1:8012/test.php)
should look like this:

Note: scroll down to see if mysqli is enabled (is not installed in the packeges above)

5. Install mariaDB

opkg install mariadb-server mariadb-server-extra mariadb-client
mysql_install_db --force

try starting
/etc/init.d/mysqld start

you may have to enable mysqld first

Test if it is runnig with
/etc/init.d/mysqld status

Now Create mysql database
/usr/bin/mysql_secure_installation -u root

Answer the question how you like

6. Test Database

Login into mysql with
mysql -u root

now type SHWO DATABASES;
it should look like this

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.001 sec)

I hope I can help someone with this.
Note: again you may need to install php8-mod-mysqli to get it running under php. Also rember you have to add it to autostart to have it running on boot time.