Adding Typesense to an existing Laravel Forge server is relatively straightforward. Laravel Forge allows you to run custom shell commands on your server, which you can use to install Typesense. Here's a step-by-step guide to get you started:
-
SSH into Your Server: First, you need to SSH into your server managed by Laravel Forge. You can do this from your terminal:
ssh forge@your-server-ip -
Install Typesense: Once you're logged in, you can install Typesense. Typesense provides an installation script that you can use:
curl -s https://install.typesense.org | bashThis command downloads and runs the Typesense installation script.
-
Configure Typesense: After installation, you'll need to configure Typesense. You can find the configuration file typically at
/etc/typesense/typesense-server.ini. You can edit this file to set up your API key and other settings:nano /etc/typesense/typesense-server.iniMake sure to configure the
api-keyand other relevant settings according to your needs. -
Start Typesense Service: You can start the Typesense service with the following command:
systemctl start typesense-serverTo ensure Typesense starts on boot, enable it with:
systemctl enable typesense-server -
Configure Your Laravel Application: In your Laravel application, you will need to configure the client to connect to Typesense. If you're using Laravel Sail for your local development, you can add Typesense to your
docker-compose.ymlfile to run it as a service alongside your application.For your production environment on Forge, you'll need to add the Typesense service provider and configure the
.envfile with your Typesense server details:TYPESENSE_HOST=your-server-ip TYPESENSE_PORT=8108 TYPESENSE_API_KEY=your-api-key -
Install Typesense PHP Client: You will need to install the Typesense PHP client in your Laravel project to interact with Typesense:
composer require typesense/typesense-php -
Index Your Data: With the client installed and configured, you can now index your data to Typesense. You'll need to write the logic to push your data to Typesense, which typically involves creating a command or job that reads from your database and indexes the data in Typesense.
-
Test Your Setup: Finally, test your setup to ensure that your Laravel application can communicate with Typesense and that your data is being indexed and searched correctly.
Remember to check the official Typesense documentation for the most up-to-date installation instructions and configurations. Also, ensure that your server's firewall rules allow traffic on the port that Typesense is configured to use (default is 8108).
Please note that while Laravel Forge allows you to run these commands, you should always ensure that any additional services you install do not conflict with the existing setup and that you have the necessary resources (CPU, memory) to support running additional services on your server.