Integrate ZKTeco SenseFace 7A with Laravel App on cPanel server

Updated: Mar 04, 2025

Integrate ZKTeco SenseFace 7A with Laravel App on cPanel server

To integrate ZKTeco SenseFace 7A with a Laravel app on a cPanel server, you'll need to follow these steps:

  1. Install the necessary dependencies:

    • Install the PHP ZKTeco library using Composer: composer require zkteco/zkteco-php
    • Install the cURL extension for PHP if it's not already installed.
  2. Create a new API key for your ZKTeco device:

    • Log in to the ZKTeco web interface (http://[IP_ADDRESS]:8001) using your administrator account.
    • Go to "Device Management" > "API Key" > "Add New".
    • Enter a name for the API key and save it. Note down the generated API key.
  3. Configure the ZKTeco library:

    • Create a new file named .env in the root directory of your Laravel app and add the following variables:
      ZKTECO_API_KEY=<your_api_key>
      ZKTECO_HOST=<your_device_ip_address>
      ZKTECO_PORT=<your_device_port>
      
    • Replace <your_api_key> with the API key generated in step 2, and replace <your_device_ip_address> and <your_device_port> with the IP address and port number of your ZKTeco device.
  4. Create a new service provider:

    • Run the following command to create a new service provider: php artisan make:provider ZktecoServiceProvider.
    • Register the service provider in the app/Providers/AppServiceProvider.php file by adding the following line to the boot() method: $this->app->register(App\Providers\ZktecoServiceProvider::class);.
    • Create the new service provider file app/Providers/ZktecoServiceProvider.php and add the following code:
      namespace App\Providers;
      
      use Illuminate\Support\ServiceProvider;
      use Zkteco\Zkteco;
      
      class ZktecoServiceProvider extends ServiceProvider
      {
          /**
           * Register services.
           *
           * @return void
           */
          public function register()
          {
              $this->app->singleton(Zkteco::class, function () {
                  return new Zkteco(
                      config('app.zkteco_api_key'),
                      config('app.zkteco_host'),
                      config('app.zkteco_port')
                  );
              });
          });
      }
      
  5. Create a new Facade:

    • Run the following command to create a new Facade: php artisan make:facade ZktecoFacade.
    • Register the Facade in the app/Providers/AppServiceProvider.php file by adding the following line to the register() method: Facade::register('Zkteco', App\Facades\ZktecoFacade::class);.
  6. Use the ZKTeco Facade in your Laravel app:

    • Now you can use the Zkteco Facade in your Laravel app to interact with the ZKTeco device. For example, to get the list of attendance records, you can use the following code:
      use App\Facades\ZktecoFacade as Zkteco;
      
      $attendanceRecords = Zkteco::getAttendanceRecords();
      dd($attendanceRecords);
      

That's it! You have successfully integrated the ZKTeco SenseFace 7A with your Laravel app on a cPanel server.