<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ramy Lien</title>
    <description>The latest articles on DEV Community by Ramy Lien (@boxmarked).</description>
    <link>https://dev.to/boxmarked</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4258659%2F75afb8eb-7fa5-4870-917e-995e3f980fc6.png</url>
      <title>DEV Community: Ramy Lien</title>
      <link>https://dev.to/boxmarked</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/boxmarked"/>
    <language>en</language>
    <item>
      <title>5 Lessons Learned Building and Licensing Self-Hosted PHP Software</title>
      <dc:creator>Ramy Lien</dc:creator>
      <pubDate>Sun, 22 Nov 2026 11:42:50 +0000</pubDate>
      <link>https://dev.to/boxmarked/5-lessons-learned-building-and-licensing-self-hosted-php-software-4n84</link>
      <guid>https://dev.to/boxmarked/5-lessons-learned-building-and-licensing-self-hosted-php-software-4n84</guid>
      <description>&lt;p&gt;Building a PHP application is one thing. Packaging it so another person can install it on their own hosting environment is something entirely different.&lt;/p&gt;

&lt;p&gt;While preparing several self-hosted PHP applications for commercial distribution, I encountered issues that were easy to overlook during development but became important when testing the actual customer installation packages.&lt;/p&gt;

&lt;p&gt;Here are five practical lessons from that process.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Never Assume Your Application Will Be Installed at the Domain Root
&lt;/h2&gt;

&lt;p&gt;One of the most frustrating installation issues involved applications that worked perfectly at:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://example.com/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But behaved incorrectly when installed at:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://example.com/myapp/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The installation might complete successfully, yet the browser would show missing CSS, broken links, or a 404 error after login.&lt;/p&gt;

&lt;p&gt;The cause was often a hardcoded URL or a redirect that assumed the application lived at &lt;code&gt;/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Location: /login'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sends the browser to:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://example.com/login&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Even when the application is installed inside &lt;code&gt;/myapp&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A better approach is to establish the application's base URL during installation and consistently use it when generating links.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'app_url'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'https://example.com/myapp'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;app_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;rtrim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'app_url'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;ltrim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Location: '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;app_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'login'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This is a simplified example; production code should validate the configured base URL and handle URL generation consistently throughout the application.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson:&lt;/strong&gt; Test both domain-root and subfolder installations before releasing a customer ZIP.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Required Directories Must Actually Exist in the ZIP
&lt;/h2&gt;

&lt;p&gt;Another problem came from missing directories.&lt;/p&gt;

&lt;p&gt;An installer expected folders such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;config/
storage/
storage/cache/
storage/logs/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But ZIP files do not always retain empty directories.&lt;/p&gt;

&lt;p&gt;As a result, an installation check could report that a required folder was missing or not writable.&lt;/p&gt;

&lt;p&gt;The solution was to include placeholder files such as &lt;code&gt;.gitkeep&lt;/code&gt; where necessary.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;storage/
    cache/
        .gitkeep
    logs/
        .gitkeep
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The installer should also check whether the application can create the required files.&lt;/p&gt;

&lt;p&gt;A basic check might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$directory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;__DIR__&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/storage/cache'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;is_dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$directory&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RuntimeException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s1"&gt;'Required storage directory is missing.'&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;is_writable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$directory&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RuntimeException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s1"&gt;'Storage directory is not writable.'&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This check should be performed before creating application configuration or activating a license.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson:&lt;/strong&gt; Test the extracted ZIP package, not only the development directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. License Activation and Verification Are Different Operations
&lt;/h2&gt;

&lt;p&gt;For commercial self-hosted software, a licensing system generally needs to answer two different questions:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Activation:&lt;/strong&gt; Is this purchase authorized to register this installation?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verification:&lt;/strong&gt; Is the installation still authorized after activation?&lt;/p&gt;

&lt;p&gt;Activation typically happens during installation.&lt;/p&gt;

&lt;p&gt;Verification happens periodically after installation.&lt;/p&gt;

&lt;p&gt;An example activation request might include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"purchase_code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"CUSTOMER-PURCHASE-CODE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"software_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"EXAMPLE-SOFTWARE-ID"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"activation_type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"domain"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"activation_identifier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"example.com"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are illustrative values, not real credentials.&lt;/p&gt;

&lt;p&gt;For a domain-based license, the server can enforce an installation limit and associate the purchase with an authorized domain.&lt;/p&gt;

&lt;p&gt;The application must also store enough local information to recognize an already activated installation.&lt;/p&gt;

&lt;p&gt;One important implementation decision is to avoid storing a purchase code in plain text unnecessarily.&lt;/p&gt;

&lt;p&gt;Depending on the architecture, an encrypted local credential or server-issued verification token can be used.&lt;/p&gt;

&lt;p&gt;If storing encrypted credentials locally, encryption keys should be generated securely and kept separate from the encrypted data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson:&lt;/strong&gt; Activation registers an installation. Verification maintains its licensing state. Both need a clearly defined security model.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. A Temporary License Server Outage Should Not Disable Legitimate Customers
&lt;/h2&gt;

&lt;p&gt;Imagine a customer has purchased and activated an application successfully.&lt;/p&gt;

&lt;p&gt;A few weeks later, the licensing server experiences a short network interruption.&lt;/p&gt;

&lt;p&gt;Should the customer immediately lose access to their software?&lt;/p&gt;

&lt;p&gt;Usually, that would create an unnecessarily poor experience.&lt;/p&gt;

&lt;p&gt;A more resilient licensing design distinguishes between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An explicitly revoked or suspended license.&lt;/li&gt;
&lt;li&gt;A license that has been successfully verified.&lt;/li&gt;
&lt;li&gt;A temporary network failure that prevents verification.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A temporary connection error should not automatically be treated as license revocation.&lt;/p&gt;

&lt;p&gt;One approach is to maintain a last-known-valid license state and allow an appropriately limited verification grace period.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$verificationSucceeded&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Update the last verified timestamp.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$temporaryNetworkFailure&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Apply the documented offline grace policy.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$licenseExplicitlyRevoked&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Enforce the license restriction.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is conceptual pseudocode, not a complete license implementation.&lt;/p&gt;

&lt;p&gt;The grace-period duration and enforcement behavior should match the application's licensing terms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson:&lt;/strong&gt; Network failures and explicit license rejection are fundamentally different events.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. The Final Customer ZIP Is the Product
&lt;/h2&gt;

&lt;p&gt;Perhaps the biggest lesson is that successful development tests are not enough.&lt;/p&gt;

&lt;p&gt;An application may work correctly on the developer's server because that server already contains configuration files, folders, database tables, or environment settings created during development.&lt;/p&gt;

&lt;p&gt;The customer receives only the ZIP.&lt;/p&gt;

&lt;p&gt;That is what must be tested.&lt;/p&gt;

&lt;p&gt;Before releasing a PHP application, I now prefer to check:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Extract the ZIP into a completely fresh folder.&lt;/li&gt;
&lt;li&gt;Confirm the required directories are present.&lt;/li&gt;
&lt;li&gt;Create a new empty database.&lt;/li&gt;
&lt;li&gt;Run the installer using the same instructions customers receive.&lt;/li&gt;
&lt;li&gt;Test the application at both a domain root and a subfolder.&lt;/li&gt;
&lt;li&gt;Verify that CSS, JavaScript, redirects, and login work.&lt;/li&gt;
&lt;li&gt;Test license activation with a valid purchase code.&lt;/li&gt;
&lt;li&gt;Confirm the application's licensing state after installation.&lt;/li&gt;
&lt;li&gt;Remove the installer when instructed.&lt;/li&gt;
&lt;li&gt;Confirm the application still works after logging out and signing in again.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;PHP syntax validation and ZIP integrity checks are also useful, but they cannot replace a real installation test.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson:&lt;/strong&gt; Don't only test your source code. Test the exact package your customer will download.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Self-hosted software has an advantage: customers can run applications on their own hosting infrastructure and maintain more direct control over their installation.&lt;/p&gt;

&lt;p&gt;But that flexibility creates additional responsibilities for developers.&lt;/p&gt;

&lt;p&gt;Different PHP versions, hosting configurations, URL structures, filesystem permissions, and database environments can expose problems that never appeared during development.&lt;/p&gt;

&lt;p&gt;I've found that treating installation, licensing, documentation, and packaging as core parts of the product makes the entire development process more reliable.&lt;/p&gt;

&lt;p&gt;The next time I develop a PHP application, I'll test its installation experience much earlier instead of leaving it until the end.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What has been your most frustrating issue when deploying a self-hosted PHP application?&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;AI assistance disclosure: This article was drafted with AI assistance and reviewed against real development and installation experiences. The code examples are illustrative and should be adapted and tested before production use.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>webdev</category>
      <category>selfhosted</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
