Skip to content
joetm edited this page Mar 4, 2016 · 4 revisions

Here we describe how to set up the database to power a small sample data store.

Create a sample data store

Adjust the install/mysql_db.sql with your chosen username and password. By default, it will create a user testuser with password testpass.

Execute this statement to create the database:

$ mysql -u root -p < ./install/create_mysql_db.sql

Populate the MySQL database with sample data

Import the file install/create_mysql_table.sql:

$ mysql -u root -p < ./install/create_mysql_table.sql 

Populate SQLite with sample data

Create a file, create_sqlite_table.sql, with SQL commands to create a table of sample data:

If using a version of SQLite older than 3.8.2 then remove the WITHOUT ROWID from the first statement.

Create a new directory:

$ mkdir /var/databases

Adjust the permissions of the folder to be web-accessible. The user may differ from your setup. For Apache, a common user/usergroup is "www-data":

$ sudo chown www-data:www-data /var/databases

Execute these SQL statements in SQLite. If necessary, replace /var/databases/sameasdb.sq3 with a path and file name that is consistent with your file system.

$ sqlite3 /var/databases/sameasdb.sq3 < ./install/create_sqlite_table.sql 

Exposing data stores

The stores are configured in the config.ini. Multiple stores can be added. Each store must start with the store name in square brackets.

Here are two sample configurations from the config.ini to get you started:

SQLite Store

    [teststore] ;the name of the datastore (used for tables)
type = "SQLiteStore"
location = "./db/sameaslite-store.db"
; The string to use in a WebApp URL for this store (alphanumeric characters)
slug = "test"
; The short name for the store
shortName = "Test Store"
; The long, unabbreviated name, will be set to 'shortName' if not defined
fullName  = "Test store used for SameAs Lite development"
; Store Description (optional)
description = "There is lots of great info in here about the things you can do. Learn about places, cheese and crips and how these all relate!"
; Contact information
contact[name] = "Joe Bloggs"
contact[email] = "Joe.Bloggs@acme.org"
contact[telephone] = "0123456789"

MySQL Store

    [mysqlstore] ;the name of the datastore (used for tables)
type = "MySQLStore"
; mysql server details
mysql[host] = "127.0.0.1"
mysql[port] = 3306
mysql[charset] = "utf8"
mysql[db] = "testdb"
mysql[table] = "table1"
mysql[user] = "testuser"
mysql[pass] = "testpass"
; The string to use in a WebApp URL for this store (alphanumeric characters)
slug = "test"
; The short name for the store
shortName = "Test Store"
; The long, unabbreviated name, will be set to 'shortName' if not defined
fullName  = "Test store used for SameAs Lite development"
; Store Description (optional)
description = "There is lots of great info in here about the things you can do. Learn about places, cheese and crips and how these all relate!"
; Contact information
contact[name] = "Joe Bloggs"
contact[email] = "Joe.Bloggs@acme.org"
contact[telephone] = "0123456789"

Update all the values to be consistent with your MySQL deployment.

Make sure the slug is unique. There should be no other data stores in index.php with the same slug.


Check a data store has been deployed

Visit http://127.0.0.1/sameas-lite/.

Click DATASETS. You should see the short name of your data store listed.

Visit http://127.0.0.1/sameas-lite/datasets/SLUG/status?_METHOD=GET&store=test, where SLUG is the slug associated with your data store. You should see a summary page like:

Statistics for sameAs store TABLE:
N    symbols
M    bundles

For example, if using the MySQL or SQLite sample data stores then visit:

You should see:

Statistics for sameAs store table1:
15   symbols
3    bundles

Troubleshooting - Can't connect to MySQL server on '127.0.0.1'

If the user interface shows a message like:

SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)

then check:

  • Database management system is running.
  • index.php specifies a valid connection URL, database, username and password.
  • For Scientific Linux 7 / Fedora 21 Apache services are allowed to connect to networked databases - you have run setsebool. See StackOverflow, php can't connect to mysql with error 13 (but command line can).

Troubleshooting - Unable to to connect to mysql could not find driver

If the user interface shows a message like:

Unable to to connect to mysql
 could not find driver

then you need to install php5-mysql or php-mysql and also restart Apache.

Troubleshooting - Unable to to connect to sqlite

If the user interface shows a message like:

SQLSTATE[HY000] [14] unable to open database file

then check that:

  • Apache user, www-data or apache, has read/write access to the directory holding the database file.
  • For Fedora 21 and Scientific Linux 7, you set the security configuration using setcon.
  • index.php specifies a valid directory and file path.

Check the REST API

List the canons

Run the following, where SLUG is the slug associated with your data store:

$ curl -X GET http://127.0.0.1/sameas-lite/datasets/SLUG/canons

You should see a list of the canons in your data store. For example, for the MySQL and SQLite sample data stores:

$ curl -X GET http://127.0.0.1/sameas-lite/datasets/test/canons
["http:\/\/www.wikidata.org\/entity\/Q220966","http:\/\/www.wikidata.org\/entity\/Q23436","http:\/\/www.wikidata.org\/entity\/Q6940372"]

$ curl -X GET http://127.0.0.1/sameas-lite/datasets/testsqlite/canons
...

List the URI pairs

Run the following, where SLUG is the slug associated with your data store:

$ curl -H "Accept: text/csv" -X GET http://127.0.0.1/sameas-lite/datasets/SLUG/pairs

You should see a list of all the URI pairs in your data store. For example, for the MySQL and SQLite sample data stores:

$ curl -H "Accept: text/csv" -X GET http://127.0.0.1/sameas-lite/datasets/test/pairs
canon,symbol
http://www.wikidata.org/entity/Q220966,http://data.nytimes.com/southampton_england_geo
http://www.wikidata.org/entity/Q220966,http://data.ordnancesurvey.co.uk/id/50kGazetteer/218013
http://www.wikidata.org/entity/Q220966,http://dbpedia.org/resource/Soton
http://www.wikidata.org/entity/Q220966,http://sws.geonames.org/1831142/
http://www.wikidata.org/entity/Q220966,http://www.wikidata.org/entity/Q220966
http://www.wikidata.org/entity/Q23436,http://data.nytimes.com/edinburgh_scotland_geo
...

$ curl -H "Accept: text/csv" -X GET http://127.0.0.1/sameas-lite/datasets/testsqlite/pairs
...

Search for URI pairs

Run the following, where SLUG is the slug associated with your data store, and PATTERN is a text fragment you know at least one of your URIs in your data store matches:

$ curl -X GET http://127.0.0.1/sameas-lite/datasets/SLUG/canons

You should see an HTML page with a list of the matching URIs in your data store. For example, for the MySQL and SQLite sample data stores:

$ curl -X GET http://127.0.0.1/sameas-lite/datasets/test/search/embra

<ul>
    <li><a href="http://data.nytimes.com/edinburgh_scotland_geo">http://data.nytimes.com/edinburgh_scotland_geo</a></li>
    <li><a href="http://data.ordnancesurvey.co.uk/id/50kGazetteer/81482">http://data.ordnancesurvey.co.uk/id/50kGazetteer/81482</a></li>
    <li><a href="http://dbpedia.org/resource/Embra">http://dbpedia.org/resource/Embra</a></li>
    <li><a href="http://sws.geonames.org/2650225/">http://sws.geonames.org/2650225/</a></li>
    <li><a href="http://www.wikidata.org/entity/Q23436">http://www.wikidata.org/entity/Q23436</a></li>
</ul>

$ curl -X GET http://127.0.0.1/sameas-lite/datasets/testsqlite/search/embra
...

Insert a URI pair

Run the following, where SLUG is the slug associated with your data store:

$ curl -X PUT --user username:password http://127.0.0.1/sameas-lite/datasets/SLUG/pairs/a/b

Then list the canons:

$ curl -X GET http://127.0.0.1/sameas-lite/datasets/SLUG/canons

You should see 'a' listed in the canons. For example, for the MySQL and SQLite sample data stores:

$ curl -X PUT --user username:password http://127.0.0.1/sameas-lite/datasets/test/pairs/a/b
{"ok":"The pair (a, b) has been asserted"}
$ curl -X GET http://127.0.0.1/sameas-lite/datasets/test/canons
["a","http:\/\/www.wikidata.org\/entity\/Q23436","http:\/\/www.wikidata.org\/entity\/Q6940372","http:\/\/www.wikidata.org\/entity\/Q220966"]

$ curl -X PUT --user username:password http://127.0.0.1/sameas-lite/datasets/testsqlite/pairs/a/b
...
$ curl -X GET http://127.0.0.1/sameas-lite/datasets/testsqlite/canons
...

Troubleshooting - General error: 8 attempt to write a readonly database

If curl returns a document with a message like:

<p>SQLSTATE[HY000]: General error: 8 attempt to write a readonly
database</p><p><strong>/var/www/html/sameas-lite/src/Store.php</strong>
&nbsp; +994</p><p>Please try returning to <a
href="http://127.0.0.1/sameas-lite">the homepage</a>.</p> 

Or the user interface shows a message like:

Failed to create Store with name table1
sqlite: CREATE TABLE IF NOT EXISTS table1 (canon TEXT, symbol TEXT
PRIMARY KEY); CREATE INDEX IF NOT EXISTS table1_idx ON table1
(canon);SQLSTATE[HY000]: General error: 8 attempt to write a readonly
database 

then check that:

  • Apache user, www-data or apache, has read/write access to the directory holding the database file.
  • For Fedora 21 and Scientific Linux 7, you set the security configuration using setcon.
  • index.php specifies a valid directory and file path.
  1. SameAs-Lite
  2. Concepts
  3. Server Requirements
    1. Requirements
    2. Dependency Installation
  4. Installation & Configuration
    1. Environment Configuration
    2. SameAs Configuration
    3. Sample Data
  5. [Data Stores](Data Stores)
  6. Usage
    1. Web Usage
    2. API
    3. [API Examples](API Examples)
    4. Scripting
  7. Contributing to SameAs-Lite
    1. [Setting up a development environment](Setting up a development environment)
    2. [Coding Standards](Coding Standards)
    3. [Day-to-Day Development](Day-to-Day Development)
  8. [Open Source Governance](Open Source Governance)
  9. Support
  10. [Getting In Touch](Getting In Touch)
  11. [Legal Information](Legal Information)

Clone this wiki locally