Bitnami Custom PHP Application

    Find out how to add a custom PHP application on top of the Bitnami LAMP/MAMP/WAMP Stack.

    How to create the basic application structure?

    All PHP applications follow similar conventions in Bitnami stacks. The directories and files shown below should be placed under /opt/bitnami/ for cloud servers and virtual machines, or under the installation directory for native installers.

    This is the basic directory structure:

    apps/myapp
            |- htdocs
            |- conf
            |- data (optional)
    

    The important files and directories are described below:

    apps: This is the folder where all PHP applications are stored (for example, phpMyAdmin is in apps/phpmyadmin, WordPress is in apps/wordpress, etc). Assuming that your app will live in the myapp/ folder, you should create the directory structure above:

    Follow the steps below for your platform.

    Cloud Server

    Run the following commands to create the folders:

    $ sudo mkdir /opt/bitnami/apps/myapp
    $ sudo mkdir /opt/bitnami/apps/myapp/htdocs
    $ sudo mkdir /opt/bitnami/apps/myapp/conf
    

    Virtual Machine

    Run the following commands to create the folders:

    $ sudo mkdir /opt/bitnami/apps/myapp
    $ sudo mkdir /opt/bitnami/apps/myapp/htdocs
    $ sudo mkdir /opt/bitnami/apps/myapp/conf
    

    Native Installer

    • On Windows, create the folders using the Windows Explorer.
    • On OS X and Linux, run the following commands to create the folders:
    $ mkdir /installdir/apps/myapp
    $ mkdir /installdir/apps/myapp/htdocs
    $ mkdir /installdir/apps/myapp/conf
    

    Tabs end

    apps/myapp/htdocs: This folder should contain your PHP application's files.

    apps/myapp/conf/httpd-prefix.conf: This is the Apache configuration file to configure your application at http://example.com/myapp. It should contain the following directives:

    Alias /myapp/ "/installdir/apps/myapp/htdocs/"
    Alias /myapp "/installdir/apps/myapp/htdocs"
    Include "/installdir/apps/myapp/conf/httpd-app.conf"
    

    apps/myapp/conf/httpd-app.conf: This is the main configuration file for your application. It should contain the following, although you can modify it further depending on your application's requirements.

    Cloud Server

    <Directory /opt/bitnami/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>
    

    Virtual Machine

    <Directory /opt/bitnami/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>
    

    Native Installer

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

    Tabs end

    NOTE: If your application uses .htaccess files, you should change the "AllowOverride None" option with "AllowOverride All". Check this note to move the .htaccess file to the main configuration.

    Once you have created the files and directories above, add the following line to the end of the main Apache configuration file, as shown below:

    Cloud Server

    The Apache configuration file is at /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf. Add the following line to the end of the file:

    Include "/opt/bitnami/apps/myapp/conf/httpd-prefix.conf"
    

    Virtual Machines

    The Apache configuration file is at /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf. Add the following line to the end of the file:

    Include "/opt/bitnami/apps/myapp/conf/httpd-prefix.conf"
    

    Native Installer

    The Apache configuration file is at /installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf. Add the following line to the end of the file:

    Include "/installdir/apps/myapp/conf/httpd-prefix.conf"
    

    Tabs end

    Restart the Apache server and you should be able to access your application at http://example.com/myapp.

    How to deploy a demo app?

    PHP-based stacks (LAMP/MAMP/WAMP and LAPP/MAPP/WAPP) ship a docs/ folder containing a demo app. This demo application includes all the configuration files mentioned in the previous section. You can use this demo app to quickly bootstrap your custom application, by following these steps:

    NOTE: If you are using a virtual machine or cloud server, replace installdir with /opt/bitnami in the following steps. If you are using a native installer, replace installdir with the actual stack installation directory.
    • Copy the demo/ folder from the installdir/docs directory to the installdir/apps directory. For example, on Linux and Mac OS X, you could run these commands:
      $ cd installdir    
      $ cp -r docs/demo apps
      
    • Add the following entry in the installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf file:
      Include "/installdir/apps/demo/conf/httpd-prefix.conf"
      
    • Restart the Apache server.

    You should now be able to access the application at http://localhost:8080/demo (Linux and Mac OS X native installers) or http://localhost/demo (cloud servers, virtual machines and Windows native installer).

    How to enable PHP-FPM in your custom application?

    PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for heavy-loaded sites. The recommended configuration is to configure Apache to serve the static files requests (images, css, javascripts and more) and use PHP_FPM with Apache "mod_proxy" module to handle the PHP requests.

    Take into account that PHP-FPM won't work on Windows systems.

    The first thing you need to do is to enable PHP-FPM in your Apache server. To do it, you can follow the steps in this wiki entry.

    Once it is done, you need to configure your application properly to use PHP-FPM. You have to modify some files

    apps/myapp/conf/httpd-app.conf

    Insert the following lines at the beginning

    <IfDefine USE_PHP_FPM>
        <Proxy "unix:/installdir/php/var/run/myapp.sock|fcgi://myapp-fpm" timeout=300>
        </Proxy>
    </IfDefine>
    


    And then these ones inside the Directory

    <Directory "/installdir/apps/myapp/htdocs">
    
    ....
    
    <IfDefine USE_PHP_FPM>
           <FilesMatch \.php$>
             SetHandler "proxy:fcgi://myapp-fpm/"
           </FilesMatch>
        </IfDefine>
    
    </Directory
    

     

    Now, create the folder php-fpm inside the conf directory, so that the structure is like this

    apps/myapp
                |- htdocs
                |- conf
                    |- php-fpm
                |- data (optional)
    

     

    and create a file called pool.conf inside with the following content

    apps/myapp/conf/php-fpm/pool.conf

    [myapp]
    listen=/installdir/php/var/run/myapp.sock
    include=/installdir/php/etc/common-dynamic.conf
    include=/installdir/apps/myapp/conf/php-fpm/php-settings.conf
    include=/installdir/php/etc/environment.conf
    pm=dynamic
    

     

    Now you need to include the following line in the php-fpm.conf conf

    /installdir/php/etc/php-fpm.conf

    include=/installdir/apps/myapp/conf/php-fpm/pool.conf
    

     

    Finally restart Apache

    /installdir/ctlscript.sh restart apache
    

    Permissions

    If are using a virtual machine or cloud image, or in the case that you installed as root a native installer for Mac OS X or Linux, you need to give read permissions to the the apache user or group. In these installations apache is running as the daemon user.

    sudo chgrp daemon /opt/bitnami/apps/demo/htdocs
    

    Note

    NOTE: This guide uses "/opt/bitnami" to refer to the installation directory. This is the default installation directory for Virtual Machines and Cloud Images. If you have installed your Bitnami stack in a different folder, replace "/opt/bitnami" with your installation directory in the examples.
    Tag page (Edit tags)
    • No tags
    Pages that link here
    Page statistics
    66683 view(s), 43 edit(s) and 11103 character(s)

    Comments

    You must login to post a comment.

    Attach file

    Attachments