Create a custom PHP application

Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and MacOS) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). On OS X VMs, the installation directory is /opt/bitnami and OS X VM users can click the “Open Terminal” button to run commands. Learn more about the Bitnami stack environment and about OS X VMs.

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, you have two options:

  • 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:

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

      $ sudo cp -r 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 command-line tool.

      $ sudo installdir/ restart apache

    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:

    • Run the following commands to create the directories and assign the necessary permissions:

      $ sudo mkdir installdir/apps/myapp
      $ sudo mkdir installdir/apps/myapp/htdocs/
      $ sudo mkdir installdir/apps/myapp/conf
      $ sudo chown -R bitnami:daemon installdir/apps/myapp/htdocs/
      $ sudo chmod -R g+w installdir/apps/myapp/htdocs/
    • Create and edit the installdir/apps/myapp/conf/httpd-prefix.conf file and add the line below to it:

      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 >= 2.3>
          Require all granted

      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.

    • 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:

      $ sudo installdir/ restart apache

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

    If you prefer to have the application available at the server root, perform these additional steps:

    • Edit the installdir/apps/myapp/conf/httpd-prefix.conf file and modify it so that it looks like this:

      DocumentRoot "installdir/apps/myapp/htdocs/"
      Include "installdir/apps/myapp/conf/httpd-app.conf"
    • Restart the Apache server:

      $ sudo installdir/ restart apache

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

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 January 15, 2020