A simplified open-source tool for encrypting and obfuscating PHP files for use with PHPDesktop. This project protects your PHP source code by encrypting and (optionally) obfuscating both pages and components, then generates a router file that decrypts and executes them at runtime.
Note: This version uses MSYS2 for compilation and expects the use of OpenSSL for encryption.
- Features
- Requirements
- Folder Structure
- Usage
- Compiling the Encrypter
- Integrating with PHPDesktop
- PHPDesktop Settings
- License
- Encryption/Obfuscation: Encrypts all PHP files (pages and components) and generates a JSON map for decryption.
- Router Generation: Produces a router file (
router.php
) that, in production mode, decrypts and evaluates the encrypted files. - Dual Mode:
- Development Mode: Loads PHP files directly for ease of testing.
- Production Mode: Loads encrypted/obfuscated files via decryption at runtime.
- Open Source & Simplified: Designed to be a starting point for anyone wanting to protect their PHP source in PHPDesktop.
- System: Windows 7/8.1/10/11
- MSYS2: For compiling the C source files.
Download and install MSYS2 from msys2.org.
For a tutorial on installing MSYS2 with VSCode, see this guide. - GCC: Available within MSYS2.
- OpenSSL: Ensure OpenSSL is installed and available in your MSYS2 environment.
Note: For OpenSSL to function properly, you must havelibssl-3-x64.dll
andlibcrypto-3-x64.dll
available. - Python 3: Used for running the encryption and router generation scripts.
- PHPDesktop: Download from phpdesktop to run your encrypted application.
The project is divided into two main parts:
phpdesktop-encrypter/ ├── .vscode/ | ├── c_cpp_properties.json | ├── settings.json │ └── task.json ├── input_docs/ │ ├── components/ | | ├── footer.php | | ├── header.php | | ├── navbar.php | | └── sidebar.php | ├── pages/ | | ├── home.php | | ├── contact.php | | └── license.php | └── public/ | └── index.php ├── output_docs/ │ ├── components/ | | ├── footer.php.enc | | ├── header.php.enc | | ├── navbar.php.enc | | └── sidebar.php.enc | ├── pages/ | | ├── home.php.enc | | ├── contact.php.enc | | └── license.php.enc | ├── public/ | | └── index.php.enc │ ├── router.php │ └── phpdesktop-encrypter.exe ├── scripts/ | ├── phpdesktop-encrypter.c | ├── generate_router.py | ├── generate_map.py | └── generate_router.php ├── compile.bat └── README.md
After compiling, the production version of your PHPDesktop application will have this structure:
PHP Version 7.1 phpdesktop/ ├── www/ │ ├── components/ | | ├── footer.php.enc | | ├── header.php.enc | | ├── navbar.php.enc | | └── sidebar.php.enc | ├── pages/ | | ├── home.php.enc | | ├── contact.php.enc | | └── license.php.enc | ├── public/ | | └── index.php.enc │ └── router.php ├── phpdesktop-chrome.exe ├── phpdesktop-encrypter.exe ├── libssl-3-x64.dll ├── libcrypto-3-x64.dll └── settings.json
PHP Version 8.3 phpdesktop/ ├── php/ | ├── libssl-3-x64.dll | └── libcrypto-3-x64.dll ├── www/ │ ├── components/ | | ├── footer.php.enc | | ├── header.php.enc | | ├── navbar.php.enc | | └── sidebar.php.enc | ├── pages/ | | ├── home.php.enc | | ├── contact.php.enc | | └── license.php.enc | ├── public/ | | └── index.php.enc │ └── router.php ├── phpdesktop-chrome.exe ├── phpdesktop-encrypter.exe └── settings.json
In production, all PHP files are encrypted/obfuscated (with the .enc
extension), and router.php
decrypts and evaluates them at runtime.
-
Prepare the Environment:
- Open MSYS2.
- Ensure you have Python 3 and GCC installed.
- Make sure OpenSSL (with
libssl-3-x64.dll
andlibcrypto-3-x64.dll
) is available in your PATH.
-
Run
compile.bat
:
Open a Command Prompt and run the providedcompile.bat
script from the root of thephpdesktop-encrypter
folder. This script will:- Encrypt and obfuscate all PHP files (both pages and components) from
input_docs
and generate a map (map.json
). - Copy the base router file (
generate_router.php
) tooutput_docs
. - Generate
router.php
using the embedded map. - Compile
phpdesktop-encrypter.c
intophpdesktop-encrypter.exe
.
- Encrypt and obfuscate all PHP files (both pages and components) from
-
Copy the Output Files:
After compilation, copy the entireoutput_docs
folder into thewww
folder of your PHPDesktop project (or set your PHPDesktop configuration to point towww
). -
PHPDesktop Settings:
Modify yoursettings.json
file in PHPDesktop to userouter.php
as the index file. For example:"web_server": { "listen_on": ["127.0.0.1", 0], "www_directory": "www", "index_files": ["router.php"], "cgi_interpreter": "php/php-cgi.exe", "cgi_extensions": ["php"], "cgi_temp_dir": "", "404_handler": "/pretty-urls.php", "hide_files": [] },
-
PHPDesktop Settings:
Modify yourphp.ini
file in PHPDesktop to useopcache
. For example:
; Load OPcache as a Zend Extension zend_extension=php_opcache.dll ; Opcache settings [opcache] ; Enables OPcache (1 to enable, 0 to disable) opcache.enable=1 ; If you want OPcache to also be enabled in CLI (useful for testing), change to 1 opcache.enable_cli=0 ; Shared memory size allocated to OPcache in megabytes (adjust according to your needs) opcache.memory_consumption=128 ; Buffer size for interned strings opcache.interned_strings_buffer=8 ; Maximum number of files that OPcache can cache. ; This value must be high enough to cover all your scripts. opcache.max_accelerated_files=4000 ; Interval in seconds to check if a file has changed. In production, a higher value may improve performance. opcache.revalidate_freq=60 ; Enables fast shutdown of OPcache opcache.fast_shutdown=1
- Run PHPDesktop:
Launch phpdesktop-chrome.exe (or your chosen PHPDesktop executable). The router (router.php) will decrypt and evaluate the encrypted PHP files at runtime.
Make sure to update your PHPDesktop settings.json as shown above to point to the correct www directory and index file (router.php). This ensures that all requests are routed through the decryption and evaluation layer.
This project is licensed under the MIT License.