Docs cipi.yml Web panel API MCP Guides Compare GitHub Telegram channel
  1. Home
  2. Guides
  3. Anonymize a Laravel database with Cipi Agent, step by step
Cipi Agent & AI

Anonymize a Laravel database with Cipi Agent, step by step

Give developers, QA, staging and AI assistants a realistic copy of production with every personal field replaced, explained from zero: install the agent, scan the schema, review the rules, request a dump from your laptop, import it, and keep it GDPR-safe.

By Updated 4 min read

Debugging with seed data misses the bugs real data causes. Copying production to laptops spreads personal data where it's least protected. The anonymizer in Cipi Agent gives you the middle ground: production's structure, volume and relations, with every name, e-mail, phone, address and note replaced by realistic fake values.

What you'll build#

Step 1 of 6You ask

You (or a script, or your AI assistant) ask for a dump. The most comfortable way is cipi-cli prod db anonymize shop --email you@example.com from your laptop: no SSH, no token typed by hand.

The request only asks: it returns at once with {"status":"queued"}. Nothing heavy happens inside a web request.

TermMeaning
AnonymizationReplacing personal values with fake ones, so the data no longer identifies people
TransformationThe rule for one column: fakeEmail, fakeName, mask:3,2, null…
ConsistentThe same original value always becomes the same fake value, across tables and runs
SeedA private value that makes consistent reproducible and not guessable
TruncateKeep the table, drop its rows (sessions, tokens, jobs)

Before you start#

  • A Laravel app (12 or 13) deployed with Cipi, on MySQL, MariaDB or PostgreSQL.
  • A queue worker running (Cipi creates one with every Laravel app).
  • Working Laravel mail (MAIL_* in the app's .env): the download link is sent by e-mail.

1. Install the agent and turn the anonymizer on#

On your laptop:

bash
composer require cipi/agent
git commit -am "Add Cipi Agent" && git push       # deploys

On the server, as the app user (or remotely with cipi-cli apps artisan shop …):

bash
ssh shop@203.0.113.10
cd ~/current
php artisan cipi:service anonymize --enable
php artisan cipi:generate-token anonymize

The service answers 404 until it's enabled, and every feature of the agent has its own token.

2. Let it propose the rules#

bash
php artisan cipi:init-anonymize --scan

The agent reads your schema and proposes a transformation for each column that looks personal, plus tables to empty. It writes ~/.db/anonymization.json, outside the repository (mode 0640): the file maps your schema and never ships with your code.

3. Review the rules#

Open the file and check it. A typical result:

json
{
  "transformations": {
    "users": {
      "name": "fakeName",
      "email": { "type": "fakeEmail", "consistent": true },
      "password": "password",
      "remember_token": "null",
      "phone": "mask:3,2",
      "date_of_birth": "fakeDate"
    },
    "orders": {
      "customer_email": { "type": "fakeEmail", "consistent": true },
      "shipping_address": "fakeAddress",
      "notes": "fakeParagraph",
      "ip_address": "fakeIpv4"
    },
    "invoices": { "vat_number": "fakeIdentifier" }
  },
  "truncate": ["sessions", "jobs", "failed_jobs", "password_reset_tokens", "personal_access_tokens"],
  "options": { "faker_locale": "it_IT", "consistent": true, "seed": "a-private-random-string" }
}
RuleEffect
fakeName, fakeEmail, fakeAddress, fakePhoneNumberRealistic values in the chosen locale
consistent: trueusers.email and orders.customer_email stay joinable
passwordEvery password becomes the hash of options.password (default password), so developers can log in as any user
mask:3,2Keeps the first 3 and last 2 characters: +39*******56
null, redact, fixed:valueRemove or replace entirely
truncateEmpties tables with tokens and sessions
Columns not listedCopied unchanged: ids, prices, statuses, timestamps

Then check the rules against the real database (php artisan cipi:anonymize --check does the same plus validation, without dumping):

bash
php artisan cipi:anonymize-audit

The audit fails on tables or columns that don't exist and lists personal-looking columns you haven't covered, with a suggestion. Run it after every migration that adds a column.

4. Request a dump from your laptop#

With cipi-cli and an API token (abilities apps-view and apps-env), no SSH and no token in your shell history:

bash
cipi-cli prod db anonymize shop --email you@example.com
→ Requesting anonymized dump of 'shop' via https://shop.example.com/cipi/db
✓ Anonymization job queued for 'shop'

Within minutes you get an e-mail with a link valid for 15 minutes.

Other ways to requestWhen
POST https://shop.example.com/cipi/db with the anonymizer tokenFrom a script or CI
php artisan cipi:anonymize on the serverNo e-mail; writes the file to storage/cipi/
The MCP anonymizer toolFrom Claude, Cursor or VS Code

5. Import it locally#

bash
cipi-cli db anonymize download "<signed url from the e-mail>" -o shop.sql
mysql -u root -e "CREATE DATABASE shop_local"
mysql -u root shop_local < shop.sql
# PostgreSQL:
createdb shop_local && psql shop_local < shop.sql

Or stream it straight in: cipi-cli db anonymize download "<url>" -o - | mysql -u root shop_local.

6. Check it#

bash
grep -c "real.customer@gmail.com" shop.sql        # must print 0
mysql shop_local -e "SELECT name, email FROM users LIMIT 5"

Keep it safe#

PracticeWhy
Private seed, never committedFakes can't be mapped back to people
Audit after every migrationNew personal columns are copied verbatim until listed
Rotate the token when people leavephp artisan cipi:generate-token anonymize
Disable when unusedphp artisan cipi:service anonymize --disable (endpoints answer 404)
Tell people the shared passwordEvery user's password is options.password
Document the rulesFor your records of processing and DPA

Common uses#

UseHow
Staging with realistic dataRestore the dump into the staging app (staging guide)
Reproduce a customer's bugFind the user id first with POST /cipi/db/user (ids survive anonymization), then look it up in the dump
AI assistantsLet them query the anonymized copy, not production (MCP guide)
ContractorsShare a file instead of production access

Troubleshooting#

ProblemFix
queued but no e-mailLaravel mail isn't working: test with php artisan tinker --execute="Mail::raw('t', fn(\$m)=>\$m->to('you@example.com')->subject('t'));"; the file may already be in storage/cipi/
404 from /cipi/dbService disabled or no config: cipi:service anonymize --enable, cipi:init-anonymize
400 with a list of errorsFix anonymization.json; cipi:anonymize-audit prints the same list
410 on downloadThe 15-minute link expired: request a new dump
Job never runsNo queue worker: sudo cipi worker list shop

Questions

Does the anonymizer touch the production database?

No. It reads it with mysqldump or pg_dump, rewrites the dump as a stream, deletes the raw dump immediately and keeps only the anonymized file.

Will relations and foreign keys still work?

Yes. Ids and foreign keys are never changed. With consistent the same original e-mail becomes the same fake e-mail in every table, so joins on e-mail still match.

Can someone reverse the fake values?

Not from the fake values alone: they come from Faker, seeded by your private seed. Without the seed and the original data there's nothing to map back. Keep the seed out of the repository.

What about personal data inside JSON columns?

Columns you don't list are copied unchanged. Use redact, null or fixed:{} on JSON columns that may hold personal data, and run the audit after every migration.

How big can the database be?

The work runs in a queue job, not in the web request, so the request returns at once. Large databases take minutes; the e-mail arrives when the file is ready. Add "gzip": true to get a smaller .sql.gz.

Which databases?

MySQL, MariaDB and PostgreSQL.

Can my AI assistant use it?

Yes. The agent's MCP server has an anonymizer tool to audit, scan or start a dump. Giving an assistant anonymized data instead of production is the safest way to let it experiment.

Is this enough for GDPR?

It's a strong technical measure (data minimisation and pseudonymisation), not legal advice. Document which columns you transform in your records of processing, and keep the config reviewed.

Try it on your own server

Free and open source. One command on a fresh Ubuntu 24.04 or 26.04 VPS.

wget -O - https://cipi.sh/setup.sh | bash
Read the quickstart