How to integrate online editors into your own web site on PHP

Introduction

To integrate ONLYOFFICE online editors into your own website on PHP you need to download and install ONLYOFFICE editors on your local server and use the PHP Example for their integration. We will show you how to run the PHP example on Windows OS and Linux OS.

The integration examples are used to demonstrate document editors functions and the ways to connect Document Server to your own application. DO NOT USE these examples on your own server without PROPER CODE MODIFICATIONS!

This guide will show you the sequence of actions to integrate the editors successfully.

First, download the ONLYOFFICE Editors (the ONLYOFFICE Document Server).

See the detailed guide to learn how to install Document Server for Windows.

Download the PHP Example from our site.

You need to connnect the editors to your web site. For that specify the path to the editors installation in the config.php file:

$GLOBALS['DOC_SERV_STORAGE_URL'] = "http://documentserver/FileUploader.ashx";
$GLOBALS['DOC_SERV_CONVERTER_URL'] = "http://documentserver/ConvertService.ashx";
$GLOBALS['DOC_SERV_API_URL'] = "http://documentserver/web-apps/apps/api/documents/api.js";
$GLOBALS['DOC_SERV_PRELOADER_URL'] = "http://documentserver/web-apps/apps/api/documents/cache-scripts.html";

where the documentserver is the name of the server with the ONLYOFFICE Document Server installed.

If you want to experiment with the editor configuration, modify the parameters it the doceditor.php file.

You can use any web server capable of runnig PHP code to run the sample. We will demonstrate how to run the PHP sample using Internet Information Services (IIS) web server. To set up and configure PHP on IIS PHP Manager for IIS will be used.

  1. PHP Manager for IIS configuration:

    After PHP Manager for IIS installation is complete launch the IIS Manager:

    Start -> ControlPanel -> System and Security -> Administrative Tools -> Internet Information Services (IIS) Manager

    and find the PHP Manager feature in the Features View in IIS.

    You need to register the installed PHP version in IIS using PHP Manager.

    Double-click PHP Manager to open it, click the Register new PHP version task and specify the full path to the main PHP executable file location. For example: C:\Program Files\PHP\php-cgi.exe.

    After clicking OK the new PHP version will be registered with IIS and will become active.

  2. Configure IIS to handle PHP requests:

    For IIS to host PHP applications, you must add handler mapping that tells IIS to pass all PHP-specific requests to the PHP application framework by using the FastCGI protocol.

    Double-click the Handler Mappings feature:

    In the Action panel, click Add Module Mapping. In the Add Module Mapping dialog box, specify the configuration settings as follows:

    • Request path: *.php,
    • Module: FastCgiModule,
    • Executable: "C:\[Path to your PHP installation]\php-cgi.exe",
    • Name: PHP via FastCGI,

      click OK.

After IIS manager configuration is complete everything is ready for running the PHP example.

  1. Add your web site in the IIS Manager:

    On the Connections panel right-click the Sites node in the tree, then click Add Website.

  2. In the Add Website dialog box specify the name of the folder with the PHP project in the Site name box.

    Specify the path to the folder with your project in the Physical Path box.

    Specify the unique value used only for this website in the Port box.

  3. Browse your web site with the IIS manager:

    Right-click the site -> Manage Website -> Browse

In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of documentserver in the configuration files. And you must also make sure that the Document Server in its turn has access to the server with the example installed with the address which you specify instead of example.com in the configuration files.

First, download the ONLYOFFICE Editors (the ONLYOFFICE Document Server).

See the detailed guide to learn how to install Document Server for Linux.

  1. Install Apache and PHP:
    apt-get install apache2 php7.0 libapache2-mod-php7.0
  2. Download the archive with the PHP Example and unpack the archive:
    cd /var/www/html
    wget http://api.onlyoffice.com/app_data/editor/PHP%20Example.zip
    unzip PHP\ Example.zip
  3. Edit the config.php configuration file. Specify the name of your local server with the ONLYOFFICE Document Server installed.
    nano config.php

    Edit the following lines:

    $GLOBALS['DOC_SERV_STORAGE_URL'] = "http://documentserver/FileUploader.ashx";
    $GLOBALS['DOC_SERV_CONVERTER_URL'] = "http://documentserver/ConvertService.ashx";
    $GLOBALS['DOC_SERV_API_URL'] = "http://documentserver/web-apps/apps/api/documents/api.js";
    $GLOBALS['DOC_SERV_PRELOADER_URL'] = "http://documentserver/web-apps/apps/api/documents/cache-scripts.html";
    

    Where the documentserver is the name of the server with the ONLYOFFICE Document Server installed.

  4. Set permission for site:
    chown -R www-data:www-data /var/www/html
  5. Restart apache:
    service apache2 restart
  6. See the result in your browser using the address:
    http://localhost

In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of documentserver in the configuration files. And you must also make sure that the Document Server in its turn has access to the server with the example installed with the address which you specify instead of example.com in the configuration files.

If you integrated the editors successfully the result should look like the demo preview on our site.