Skip to main content

PHP (Laravel) example

Overview

This is an example application written on PHP with Laravel Framework that integrates ONLYOFFICE Docs.

It is intended for testing purposes and demonstrating functionality of the editors. DO NOT use this integration example on your own server without proper code modifications. In case you enabled the test example, disable it before going for production.

Important security info

Please keep in mind the following security aspects when you are using test examples:

  • There is no protection of the storage from unauthorized access since there is no need for authorization.
  • There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
  • There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Docs.
  • There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Docs from another domain.

Step 1. Configure an environment

The root directory of the example application will contain the .env.example file that defines many common environment variables. You should copy the contents of the file to the .env file inside your project directory.

You can find the full list of environment variables here.

Step 2. Install the prerequisites and run the website with the editors

The PHP (Laravel) example offers various installation options, but we highly recommend using Docker for this purpose.

Option 1. Using Docker

To get started, you need to install Docker Desktop. The application provides you with Docker files out-of-the-box, so you will just need to run a couple of shell commands to start the project. You can also change these files to your preferences.

  1. Download and extract the release archive in a directory:
cd /my/php-laravel/project
curl --output PHP.Laravel.Example.zip --location https://github.com/ONLYOFFICE/document-server-integration/releases/latest/download/PHP.Laravel.Example.zip
unzip PHP.Laravel.Example.zip
cd "PHP Laravel Example"

You should modify the DOCUMENT_SERVER_JWT_SECRET environment variable in your .env file as the docker-compose.yml uses it to set a JWT secret in ONLYOFFICE Docs.

  1. To run the containers, you can either run the make compose-start command that builds and starts the project, or you can execute the following commands manually:

    • Build and start Docker Compose:

      docker compose build && docker compose up -d
    • Install the dependencies:

      docker compose exec example composer install
      && docker compose exec node npm install
      && docker compose exec node npm run build
    • Generate an application key for the Laravel instance:

      docker compose exec example php artisan key:generate

    To stop the Docker containers, you should run the make compose-stop or docker compose down commands.

    If the installation and configuration process has been successful, you can now visit localhost:80 and try the example application.

    You can always change the configuration of the nginx web-server and the port at which the application will run.

Option 2. On local machine

Before diving into the example, you will need to install ONLYOFFICE Docs. Check the detailed guide to learn how to install it on Windows, Linux, or Docker.

  1. Install the prerequisites:

  2. Download the release archive and extract it in your preferred directory:

cd /path/to/my/projects
curl --output PHP.Laravel.Example.zip --location https://github.com/ONLYOFFICE/document-server-integration/releases/latest/download/PHP.Laravel.Example.zip
unzip PHP.Laravel.Example.zip
cd "PHP Laravel Example"
  1. Run make install or execute the following commands manually:

    • Install the Composer dependencies:

      composer install
    • Install the application's frontend dependencies and build the assets:

      npm install && npm run build
    • Generate an application key for the Laravel instance:

      php artisan key:generate

    If the installation and configuration process has been successful, you can now visit your server's address and try the example application.

Step 3. Configure the PHP (Laravel) example

The PHP (Laravel) example is configured by changing environment variables.

NameDescriptionExample
USERThe user name in the system.user
UIDThe user ID number (UID) in the system.1000
DOCUMENT_STORAGE_PUBLIC_URLThe URL address used by the client to communicate with the server.http://localhost
DOCUMENT_STORAGE_PRIVATE_URLThe URL address used by the ONLYOFFICE Docs to communicate with the server.http://proxy
DOCUMENT_SERVER_PUBLIC_URLThe URL address used by the client to communicate with the ONLYOFFICE Docs.http://localhost:8080
DOCUMENT_SERVER_PRIVATE_URLThe URL address used by the server to communicate with the ONLYOFFICE Docs.http://proxy:8080
DOCUMENT_SERVER_JWT_SECRETThe JWT authorization secret.your-256-bit-secret

Step 4. Check accessibility

In case the example and ONLYOFFICE Docs are installed on different computers, make sure that your server with the example installed has access to the ONLYOFFICE Docs with the address which you specify instead of documentserver in the configuration files.

Make sure that the ONLYOFFICE Docs has access to the server with the example installed with the address which you specify instead of example.com in the configuration files.

Troubleshooting

Check out the Laravel documentation page in case you are having installation or configuration problems with the framework.