nativeInstallerwapp

Create a custom PHP application

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "installdir/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

Many users run a Bitnami stack as a development environment for their own PHP projects (as opposed to running third-party applications such as Joomla! or WordPress). To deploy your PHP application in this environment, follow these steps.

Approach A: Bitnami installations using system packages

Create the same structure used by Bitnami when installing Bitnami PHP applications. To do this, follow these steps:

  • If you installed the stack using an administrator account, run the following commands to create the directories and assign the necessary directory permissions:

    $ sudo mkdir installdir/myapp
    $ sudo chown -R $USER:daemon installdir/myapp
    $ sudo chmod -R g+w installdir/myapp
    

    If you installed the stack using an unprivileged user account, run the following commands instead:

    $ mkdir installdir/myapp
    $ chown -R $USER:$USER installdir/myapp
    $ chmod -R g+w installdir/myapp
    
  • Create and edit the installdir/apache2/conf/vhosts/myapp-vhost.conf file and add the configuration block shown below:

    <VirtualHost 127.0.0.1:80 _default_:80>
      ServerAlias *
      DocumentRoot installdir/myapp
      <Directory "installdir/myapp">
        Options -Indexes +FollowSymLinks -MultiViews
        AllowOverride All
        Require all granted
      </Directory>
    </VirtualHost>
    

    NOTE: If your application uses .htaccess files, you should change the AllowOverride None option to AllowOverride All. Find out how to move the .htaccess file content to the main server configuration file.

  • Create and edit the installdir/apache2/conf/vhosts/myapp-https-vhost.conf file and add the configuration block shown below:

    <VirtualHost 127.0.0.1:443 _default_:443>
      ServerAlias *
      DocumentRoot installdir/myapp
      SSLEngine on
      SSLCertificateFile "installdir/apache2/conf/bitnami/certs/server.crt"
      SSLCertificateKeyFile "installdir/apache2/conf/bitnami/certs/server.key"
      <Directory "installdir/myapp">
        Options -Indexes +FollowSymLinks -MultiViews
        AllowOverride All
        Require all granted
      </Directory>
    </VirtualHost>
    

    NOTE: If your application uses .htaccess files, you should change the AllowOverride None option to AllowOverride All. Find out how to move the .htaccess file content to the main server configuration file.

  • Restart the Apache server:

    $ sudo installdir/ctlscript.sh restart apache
    

    You should now be able to access the application at http://localhost/.

Approach B: Self-contained Bitnami installations

  • To make a single PHP application accessible at the root URL of the Web server (for example, http://localhost), simply copy the PHP files into the installdir/apache2/htdocs folder. For an example, take a look at the phpinfo example.

  • To have several applications running, create the same structure used by Bitnami when installing Bitnami PHP applications. Recent versions of Bitnami stacks ship a demo application with this structure to help you get started. To use this, follow the steps below:

    • Launch an elevated Windows command prompt.

    • Copy the installdir/docs/demo folder into the installdir/apps directory.

      $ copy installdir/docs/demo installdir/apps
      
    • Add the following line to the end of the installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf file:

      Include "installdir/apps/demo/conf/httpd-prefix.conf"
      
    • Restart the Apache server using the graphical manager tool.

      Server control

    You should now be able to access the demo application at http://localhost/demo. You should see a “Hello world” message in your browser.

  • If your stack does not include a demo application, or if you prefer to create a custom PHP application from scratch, follow the steps below. These steps assume that your application will live in the installdir/apps/myapp/ directory:

    • Launch an elevated Windows command prompt.

    • Run the following commands to create the directories:

      $ mkdir installdir/apps/myapp
      $ mkdir installdir/apps/myapp/htdocs/
      $ mkdir installdir/apps/myapp/conf
      
    • Create and edit the installdir/apps/myapp/conf/httpd-prefix.conf file and add the configuration block shown below:

      Alias /myapp/ "installdir/apps/myapp/htdocs/"
      Alias /myapp "installdir/apps/myapp/htdocs/"
      Include "installdir/apps/myapp/conf/httpd-app.conf"
      
    • Create and edit the installdir/apps/myapp/conf/httpd-app.conf file and add the content below to it. This is the main configuration file for your application, so modify it further depending on your application’s requirements.

      <Directory installdir/apps/myapp/htdocs/>
          Options +FollowSymLinks
          AllowOverride None
          <IfVersion < 2.3 >
          Order allow,deny
          Allow from all
          </IfVersion>
          <IfVersion >= 2.3>
          Require all granted
          </IfVersion>
      </Directory>
      

      NOTE: If your application uses .htaccess files, you should move the configuration in the .htaccess files to the main application configuration files and set the AllowOverride option to None. Find out how to move the .htaccess file content to the main server configuration file and refer to this Apache note for more information.

    • Once you have created the files and directories above, add the following line to the end of the main Apache configuration file at installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf, as shown below:

      Include "installdir/apps/myapp/conf/httpd-prefix.conf"
      
    • Restart the Apache server using the graphical manager tool.

      [![Server control](/images/img/platforms/installer/manager-windows.png)](/images/img/platforms/installer/manager-windows.png)
      

    You should now be able to access the application at http://localhost/myapp.

Once you have created and deployed your custom PHP application, you can also proceed to create and integrate a MySQL/MariaDB database with your application.

Check out the following tutorial if you want to learn more about configuring a custom PHP application.

Last modification October 1, 2020