Convert Php/Symfony web app into a Windows Desktop App

Mohamed Amine Lejmi
4 min readAug 20, 2020

--

If you are a full stack javascript developer, you can use Electron.js framework to make desktop apps.

If you are a python developer, you can use PyQT, PyGUI, .. frameworks to create desktop apps.

If you are a PHP developer and you want / need to create a desktop app,

YOU ARE STUCK !!!

I was thinking about this while i was watching my wife learning python, and I decided to find a way to develop simple desktop apps without learning a new language, only with my actual stack.

After some researches and tests, I found a solution to convert a PHP/Symfony 5 web app into a Windows Desktop App.

For that we’ll use:

  • cztomczak/phpdesktop (well documented to convert php apps into desktop apps)
  • Symfony framework ^5 (But you can use the version you like)

You can’t use MySQL DB for that, you must use SQLite DB

The main purpose of this article is to show how I configured phpdesktop to run a PHP Symfony 5 app and to provide a solution for php devs to create desktop apps.

Step 1; Download phpDesktop

Go to this page to download the latest version of phpdesktop (as zip file) and extract it:

https://github.com/cztomczak/phpdesktop/releases/tag/chrome-v57.0-rc

phpdesktop contains all you need to run your php code as desktop applications. It’s structured like this:

phpdesktop folder structure

To run your desktop application, simply click on phpdesktop-chrome.exe

As you can see, it uses 7.1.3 php version, which is not suitable to run Symfony 5 as it needs PHP 7.2.5 or higher. (We’ll fix that later).

Main phpdesktop window

Step 2: Download Symfony

In the www directory, open a console and do as usual: (for example)

composer create-project symfony/website-skeleton myApp

Or you can just copy the project you need to convert inside the www folder then run composer install and yarn install (for example).

Step 3: Redirecting to index.php

Now, what we need is to open the symfony home page when lunching our exe file.

For that we’ll modify the www/index.php file to include the symfony one:

<?phpinclude “myApp/public/index.php”;

Now, when we open our .exe file, we have a php version error:

Php version error

EVERYTHING IS OK !!!

It means that we successfully accessed the symfony index but the actual php version is not supported.

The next step will save our lives.

Step 4: Update the PHP version

To do that, simply remove the php folder and put your php 7.2 folder instead (for my case, I just copied the php folder of XAMPP but you can download the php version you need)

AND NOW YOU HAVE IT !!!

Open your exe file and you’ll see your sf5 home page in a desktop application.

Step 5: Redirect the assets

If you use a real sf5 app, you’ll notice that all your assets are not found (404 error), this is happening because the server is looking for file in the www directory.

As the phpdesktop has a mongoose web server embedded in it, we can’t use a .htaccess file to rewrite urls and redirect assets,

SO HOW WE FIX THAT ???

In fact, it’s very simple, we’ll use symlinks

To do that, just:

  • Run cmd as administrator
  • Locate it in your www folder
  • Create symlinks to assets with this command mklink /D link target (for example and you do the same for all public subfolders)

And that’s all you need to do. Now your Symfony 5 application is running as Windows Desktop Application.

To configure your project (icon, sizes, …) you can explore and modify the file setting.json located in the main directory of your phpdesktop project.

To create an installer for your desktop application and for further configurations and uses and even for creating an installer for your app, the main documentation is well done: https://github.com/cztomczak/phpdesktop

I HOPE THAT WAS USEFUL FOR ALL PHP DEVS !!!

--

--