---
title: "Deploy Typesense PHP"
description: "official PHP client against Railway"
category: "Analytics"
url: https://railway.com/deploy/typesense-php
---

# Deploy Typesense PHP

official PHP client against Railway

**[Deploy Typesense PHP on Railway](https://railway.com/template/typesense-php)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/typesense-php/manifest.json

- **Creator:** onepush
- **Category:** Analytics

## Template content

### typesense-railway

- **Source:** Shinyduo/typesense-railway
- **Public domain:** Yes

## Documentation

# Deploy and Host self hosted Typesense PHP (Open-Source Instant Search) on Railway

The Typesense PHP package is a Composer library that talks to a Typesense server over HTTP on port 8108. The server runs on Railway behind a persistent volume and an API key you must not lose. The PHP client only needs the node URL and that key.

A common gotcha is forgetting that every request must carry the `X-TYPESENSE-API-KEY` header, which the client handles once you pass the key. Collection schema drift also bites: changing a field type requires dropping and recreating the collection. Inside Railway, your PHP app can reach the service at `http://typesense:8108` without exposing the API port publicly.

## About Hosting Typesense PHP open-source software on Railway (self hosted Typesense template)

Railway’s Typesense template runs the official Docker image `typesense/typesense:30.2`, not a fork. The container starts with `--data-dir /data --api-key=$TYPESENSE_API_KEY --enable-cors`, and `/data` is mounted on a volume so indexes survive restarts. The PHP client isn’t a separate service; you add it to your app via Composer with `typesense/typesense-php`.

The client is just an HTTP wrapper, so it needs PHP 7.4+, Composer 2, and network access to the Railway service. The server is RAM-hungry because Typesense keeps the entire index in memory. A 50,000-record catalog fits in 512 MB; a million records with long text may need 2 GB or more.

## Why Deploy Typesense PHP, the Algolia alternative on Railway (Railway Free Trial)

Algolia has no self-hosted option; you pay per search request and stored record. Typesense is GPL-3.0 open source, and the PHP client is free. For a PHP shop on Laravel or Symfony, search can live inside the same infrastructure instead of a separate SaaS bill. The Railway free trial gives $5 in GitHub credits, enough to stand up a small node and test app. You won’t get Algolia’s dashboard, but you also won’t get a bill spike when a scraper hits your endpoint 50,000 times.

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Typesense PHP on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

### Railway vs Other Hosting Providers and VPS for Typesense PHP self hosting

| Provider | Setup | Volume persistence | Small-node cost | Burden |
|----------|-------|-------------------|-----------------|--------|
| Railway | Official template, one env var | Attached volume | Compute + volume, often single-digit to low-teens USD/month | Low; private networking between PHP app and Typesense |
| DigitalOcean | Droplet + Docker | Block storage volume | $6–12/month plus volume | Medium; you manage firewall and OS updates |
| AWS | EC2 or ECS | EBS snapshot | t3.small ~$15–20/month plus EBS | High; IAM, security groups, CloudWatch |
| Hetzner | Cloud server + Docker | Local NVMe or attached volume | CX22 ~€3.79/month | Medium; cheap, but you handle Docker and SSL |

Railway wins on iteration speed. DigitalOcean and Hetzner win on raw price per GB of RAM if you manage the server. AWS is overkill for a single node.

## Common Use Cases for hosted Typesense PHP

- **Laravel Scout integration** — Scout’s Typesense driver uses the same client. Define the schema in PHP and let Scout handle import/search.
- **E-commerce catalog search** — index name, description, price, stock. Use `filter_by` for category, `sort_by` for price, facets for brand.
- **Content site search** — WordPress or custom CMS posts with title, body, tags. Upsert on save, delete on unpublish.
- **Admin dashboards** — search users, orders, logs with role-based filters.

## Dependencies for Typesense PHP Docker hosted on Railway

Two layers: the Railway server needs the Docker image, a persistent volume, and one environment variable. The PHP app needs Composer and the `typesense/typesense-php` package. No special PHP extensions; the client uses PSR-18 HTTP discovery.

### Deployment Dependencies for Managed Typesense PHP Service (Instant Search)

- `TYPESENSE_API_KEY` — required, stored in Railway secrets. Losing it means recreating the volume because the key encrypts on-disk state.
- Persistent volume at `/data` — without it, deploys wipe indexes.
- Port `8108` open inside the project. Don’t expose publicly unless a browser client needs direct access.
- Enough RAM. Typesense is in-memory; a 100k index with facets often fits in 256–512 MB, but long text and many sortable fields increase that.

### Implementation Details for Typesense PHP (Using Typesense official docker image)

Railway service command: `typesense-server --data-dir /data --api-key=$TYPESENSE_API_KEY --enable-cors`. Health check hits `GET /health` on 8108. The volume must be attached before first start.

PHP client inside Railway uses host `typesense`, port 8108, and the API key from `getenv`. Outside Railway, use the public URL and keep the key out of client-facing code.

## How does Typesense PHP compare against other Instant Search platforms

The PHP client is just the official wrapper for a Typesense server. Comparisons focus on the whole stack versus Algolia, Elasticsearch, Meilisearch, and Typesense Cloud.

### Typesense PHP vs Algolia (Algolia Alternative)

Algolia wins on dashboard and relevance analytics, but it’s SaaS-only and bills per search request and stored record. Typesense on Railway has no per-search fee; you pay for RAM and CPU. A traffic spike on Algolia Grow can reset monthly limits; Railway throttles CPU instead.

### Typesense PHP vs Elasticsearch (Elasticsearch Alternative)

Elasticsearch is more general with aggregations and ingest pipelines, but needs a JVM and typically 2 GB heap minimum. Typesense is a single static binary with no JVM. For typo-tolerant search with filters and facets, Typesense is faster to stand up. Elasticsearch wins for custom analyzers and cross-cluster replication.

### Typesense PHP vs Meilisearch (Meilisearch Alternative)

Meilisearch is the closest competitor: open source, single binary, in-memory. Meilisearch’s PHP client is community-maintained; Typesense’s is official. Typesense has explicit collection schema and `filter_by` syntax. Meilisearch has a built-in web UI; Typesense leaves UI to your app or InstantSearch adapter.

### Typesense PHP vs Typesense Cloud (Typesense Cloud Alternative)

Typesense Cloud is the same server, managed. The PHP client code is identical. Cloud bills hourly per dedicated RAM/vCPU node plus bandwidth; a 0.5 GB burst node is about $21.60/month, 2 GB burst $43–51/month, no per-search fee. Self-hosting on Railway is often single-digit to low-teens USD, but you handle backups and upgrades.

## How to use Typesense PHP (the OSS Instant Search)?

`composer require typesense/typesense-php`

Create a client, define a schema, index a document. Search requires `query_by`; omitting it returns a 400 error. Wrap search calls in try/catch for malformed filters. No code blocks needed here; the client methods are straightforward.

## How to self host Typesense PHP on other VPS Services (Typesense PHP self hosting guide)

Any VPS with Docker works. The PHP client doesn’t need a special host, but the Typesense server does.

### Clone the Repository

Clone your PHP app repo, or `composer init` a new one. Don’t clone the Typesense server repo; pull the official image. Avoid copying large fixtures until you’ve sized RAM.

### Install Dependencies

Install Docker and Docker Compose on the VPS. Run `composer require typesense/typesense-php` in your PHP app. Create a `docker-compose.yml` with image `typesense/typesense:30.2`, volume for `/data`, port 8108 bound to localhost only.

### Configure Environment Variables

Set `TYPESENSE_API_KEY` to a long random string in `.env`. If PHP runs on the same host, point the client at `http://127.0.0.1:8108`. If remote, use the private IP and firewall port 8108 to that IP.

### Start the Typesense PHP Application

Start the container with `docker compose up -d`. Check `curl http://127.0.0.1:8108/health` returns `{"ok":true}`. Then start PHP with `php -S` or `php artisan serve`. First request should create a collection, upsert documents, and search.

## Official Pricing of Typesense PHP (Typesense PHP pricing)

The PHP client is free and open source. The server is GPL-3.0, so self-hosting costs only your infrastructure. Typesense Cloud bills hourly per RAM/vCPU node plus bandwidth, no per-search fee: 0.5 GB burst ~$21.60/month, 2 GB burst ~$43–51/month.

## Typesense PHP cloud vs self hosted comparison (Pricing, features, costs, and more)

Cloud gives TLS, backups, monitoring, and a public endpoint. Self-hosted on Railway gives you a fixed RAM ceiling and lower cost for small nodes. The PHP client works identically.

### Monthly cost of self hosting Typesense PHP on Railway

A 512 MB RAM / 0.5 vCPU service with 1 GB volume often costs $5–10/month. Add a PHP app and total may be $10–15. The $5 trial credit covers initial testing. Scale vertically if your dataset grows; still below comparable Cloud pricing.

### System Requirements for Hosting Typesense PHP on a VPS

RAM is the first constraint: 50k short documents fit in 256 MB; a million long-text documents may need 2–4 GB. Disk is secondary; a 1 GB index uses a few hundred MB after compaction. CPU matters during bulk imports and heavy concurrent search. For a PHP app on the same VPS, allocate at least 1 vCPU and 2 GB total RAM.

## Frequently Asked Questions (FAQs)

### Does the Typesense PHP client work with Laravel Scout?

Yes. Scout’s Typesense driver uses this package. Configure the driver with the same host and API key, then use Scout’s `search()`.

### Do I need to enable CORS for a PHP backend?

No.


## Similar templates

- [Typesense vs Meilisearch](https://railway.com/deploy/typesense-vs-meilisearch) — self-hosted Typesense vs Meilisearch
- [Betterlytics](https://railway.com/deploy/betterlytics) — Betterlytics is a cookieless analytics platform GDPR-compliant.
- [Finance Tracker](https://railway.com/deploy/finance-tracker-1) — Private multi-user household finance ledger with budgets and CSV import.

Open this page in a browser: https://railway.com/deploy/typesense-php
