Bitnami PHP for Amazon Web Services

PHP is a popular open source scripting language that is commonly used in Web application development.

How to change the date or timezone?

The default timezone is "America/Los_Angeles" but you can change it in the php.ini file, as shown below:

[Date]
date.timezone = "America/Los_Angeles"

You can see all available timezones at http://php.net/manual/en/timezones.php.

How to create a custom PHP application?

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 /opt/bitnami/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 /opt/bitnami/docs/demo folder into the /opt/bitnami/apps directory.

      $ sudo cp -r /opt/bitnami/docs/demo /opt/bitnami/apps
      
    • Add the following line to the end of the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf file:

      Include "/opt/bitnami/apps/demo/conf/httpd-prefix.conf"
      
    • Restart the Apache server using the command-line tool.

      $ sudo /opt/bitnami/ctlscript.sh restart apache
      

    You should now be able to access the demo application at http://SERVER-IP/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 /opt/bitnami/apps/myapp/ directory:

    • Run the following commands to create the directories:

      $ sudo mkdir /opt/bitnami/apps/myapp
      $ sudo mkdir /opt/bitnami/apps/myapp/htdocs/
      $ sudo mkdir /opt/bitnami/apps/myapp/conf
      
    • Create and edit the /opt/bitnami/apps/myapp/conf/httpd-prefix.conf file and add the line below to it:

      Alias /myapp/ "/opt/bitnami/apps/myapp/htdocs/"
      Alias /myapp "/opt/bitnami/apps/myapp/htdocs/"
      Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
      
    • Create and edit the /opt/bitnami/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 /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>
      
      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 /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf, as shown below:

      Include "/opt/bitnami/apps/myapp/conf/httpd-prefix.conf"
      
    • Restart the Apache server:

      $ sudo /opt/bitnami/ctlscript.sh restart apache
      

      You should now be able to access the application at http://SERVER-IP/myapp.

How can I deploy my PHP application?

The main directory to deploy your PHP application is /opt/bitnami/apache2/htdocs. You can copy your PHP application files to that directory and access the application via your browser at http://SERVER-IP/.

How to install the APCu module?

NOTE: The APCu module is only compatible with PHP 7.x.

APCu is the APC User Cache module. Install it manually following the steps below:

  • Install the following packages:

     $ sudo apt-get update
     $ sudo apt-get install build-essential libtool autoconf unzip wget 
    
  • Download the latest source package from the web page, uncompress it and compile the module.

     $ wget https://pecl.php.net/get/apcu-X.Y.Z.tgz
     $ tar xzf apcu-X.Y.Z.tgz
     $ cd apcu-X.Y.Z
     $ phpize
     $ ./configure --with-php-config=/opt/bitnami/php/bin/php-config
     $ make
     $ sudo make install
    
  • Enable the module by adding the following line in the php.ini file:

     ...
     extension = apcu.so
     ...
    

How to install the eAccelerator module?

eAccelerator is a free open-source PHP accelerator and optimizer. It increases the performance of PHP scripts by caching them in their compiled state, so that the overhead of compiling is almost completely eliminated. It also optimizes scripts to speed up their execution.

Follow the steps below to install this module:

  • Install the following packages:

     $ sudo apt-get update
     $ sudo apt-get install build-essential libtool autoconf unzip
    
  • Download the latest source code from the eAccelerator web page, copy to the server, uncompress it and compile the module:

     $ unzip eaccelerator-*.zip
     $ export PHP_AUTOCONF=/usr/bin/autoconf
     $ export PHP_PREFIX=/opt/bitnami/php
     $ cd eaccelerator-0.9.6.1
     $ /opt/bitnami/php/bin/phpize
     $ ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config
     $ make
     $ sudo make install
    
  • Enable the module in the php.ini file:

     ...
     extension=eaccelerator.so
     ...
    
  • Check it and verify that the output looks similar:

     $ php -version
    
     Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
         with eAccelerator v0.9.5-beta2, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
    

Now, configure this module in the php.ini file. For more information, refer to http://eaccelerator.net/wiki/InstallFromSource.

How to install the FreeTDS and MSSQL modules?

FreeTDS is a set of libraries for Unix and Linux that allow your programs to natively talk to Microsoft SQL Server and Sybase databases.

NOTE: Since LAMP stack v5.4.25, this module is already included so it is only necessary to enable the module in the php.ini file.

Follow these steps:

  • Load the build environment and add -liconv to the LDFLAGS:

     $ .  /opt/bitnami/scripts/build-setenv.sh
     $ export LDFLAGS="$LDFLAGS -liconv"
    
  • Install FreeTDS:

     $ wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz
     $ tar zxf freetds-patched.tgz
     $ cd freetds-0.95.21/
     $ ./configure --enable-msdblib --prefix=/usr/local/freetds
     $ make
     $ sudo make install
     $ cd ..
    
  • Compile and install the MSSQL module for PHP. Note that you should download the module that matches the PHP version in use. Check the current PHP version with the php -v command.

     $ wget http://us.php.net/distributions/php-5.4.45.tar.bz2
     $ tar jxf php-5.4.45.tar.bz2
     $ cd php-5.4.45/ext/mssql/
     $ phpize
     $ ./configure --with-mssql=/usr/local/freetds
     $ make
     $ sudo make install
    
  • Confirm that the mssql.so library has been copied to the /opt/bitnami/php/lib/php/extensions/ directory.

  • Edit the /opt/bitnami/php/etc/php.ini file and add the line below to it:

     extension=mssql.so
    
  • Restart the server:

     $ sudo /opt/bitnami/ctlscript.sh restart apache
    

How to install the mod_geoip2 module?

The mod_geoip2 module embeds GeoIP database lookups into the Apache web server. It is only capable of looking up the IP address of a client that connects to the web server, as opposed to looking up arbitrary addresses.

If this module is not in your stack, you can install it manually following the steps below.

  • Install the following packages if necessary:

     $ sudo apt-get update
     $ sudo apt-get install build-essential libtool autoconf unzip wget 
    
  • Install the development files for libgeoip:

     $ sudo apt-get install libgeoip-dev
    
  • Download the latest source code from the web page, uncompress it and compile the module.

     $ wget http://www.maxmind.com/download/geoip/api/mod_geoip2/mod_geoip2-latest.tar.gz
    
  • Uncompress it and build the libraries

     $ tar -xzvf mod_geoip2-latest.tar.gz
     $ cd mod_geoip2_*
     $ sudo apxs -i -a -lGeoIP -c mod_geoip.c
    

    The module should now be available at /opt/bitnami/apache2/modules/mod_geoip.so. It is also automatically included in your Apache configuration.

  • Enable GeoIP in the Apache configuration by adding the line GeoIPEnable On in the /opt/bitnami/apache2/conf/httpd.conf file. Find other specific configuration settings at http://dev.maxmind.com/geoip/mod_geoip2#Configuration-2.

  • Restart the Apache server:

     $ sudo /opt/bitnami/ctlscript.sh restart apache
    

How to enable the Imagick extension?

The Imagick module is installed in Bitnami stacks, but is not enabled by default. To enable it, follow these steps:

  • Uncomment or add the following line to the /opt/bitnami/php/etc/php.ini file:

     ...
     extension=imagick.so
     ...
    
  • Restart the Apache server and/or the PHP-FPM service (if available):

     $ sudo /opt/bitnami/ctlscript.sh restart apache
     $ sudo /opt/bitnami/ctlscript.sh restart php-fpm
    

How to install the IonCube extension?

Follow these steps:

  • Download the pre-compiled version and copy the .so file to the PHP extensions directory.

     $ wget http://downloads3.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
     $ tar xvzf ioncube_loaders_lin_x86-64.tar.gz
     $ sudo cp ioncube/ioncube_loader_lin_5.4.so /opt/bitnami/php/lib/php/extensions/
    
  • Add the following line to the php.ini file:

     zend_extension = /opt/bitnami/php/lib/php/extensions/ioncube_loader_lin_5.4.so
    
  • Restart PHP-FPM and Apache.

How to install the memcache module?

The memcache module provides a handy procedural and object-oriented interface to memcached, the highly effective caching daemon, which was especially designed to decrease database load in dynamic web applications.

If this module is not in your stack, you can install it manually following these steps:

  • Install the following packages:

     $ sudo apt-get update
     $ sudo apt-get install build-essential libtool autoconf unzip wget 
    
  • Download the latest source code from the web page, uncompress it and compile the module.

     $ wget http://pecl.php.net/get/memcache-2.2.7.tgz
     $ tar -zxf memcache-2.2.7.tgz
     $ export PHP_AUTOCONF=/usr/bin/autoconf
     $ export PHP_PREFIX=/opt/bitnami/php
     $ cd memcache-2.2.7
     $ /opt/bitnami/php/bin/phpize
     $ ./configure --enable-memcache --with-zlib-dir=/opt/bitnami/common
     $ make
     $ sudo make install
    
  • Enable the module in the php.ini file:

     ...
     extension=memcache.so
     ...
    

How to install the memcached module using the libmemcached library?

Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. This extension uses the libmemcached library to provide an API for communicating with memcached servers.

If this module is not in your stack, you can install it manually following these steps. The steps differ for PHP5 and PHP7, so choose the appropriate section below depending on the PHP version bundled with your stack. To obtain the PHP version, use the command php -v at your console prompt.

Installation

PHP7
  • Install development tools:

     $ sudo apt-get update
     $ sudo apt-get install build-essential libtool autoconf unzip wget git
    
  • Download the latest source code from the web page, uncompress it and compile the library:

     $ wget https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached-1.0.16.tar.gz
     $ tar -zxf libmemcached-1.0.16.tar.gz
     $ cd libmemcached-1.0.16
     $ ./configure --prefix=/opt/bitnami/common
     $ make
     $ sudo make install
    
  • Download and compile the PHP7 version of the PHP memcached module

     $ export PHP_AUTOCONF=/usr/bin/autoconf
     $ export PHP_PREFIX=/opt/bitnami/php
     $ cd ~/
     $ git clone https://github.com/php-memcached-dev/php-memcached.git
     $ cd php-memcached
     $ git checkout php7
     $ /opt/bitnami/php/bin/phpize
     $ ./configure --enable-memcached --with-zlib-dir=/opt/bitnami/common --with-libmemcached-dir=/opt/bitnami/common --with-php-config=/opt/bitnami/php/bin/php-config --disable-memcached-sasl
     $ make
     $ sudo make install
    
  • Enable the module in the php.ini file:

     ...
     extension=memcached.so
     ...
    
  • Start the memcached server by running these commands:

     $ mv /opt/bitnami/memcached/scripts/ctl.sh.disabled /opt/bitnami/memcached/scripts/ctl.sh
    
     $ sudo /opt/bitnami/ctlscript.sh start memcached
    

    If you get an error, check that your stack includes the memcached server:

     $ sudo /opt/bitnami/ctlscript.sh status memcached
    

    Usually, if you don't see the status, it is because you are using a stack that doesn't bundle the memcached server. To install and start it, run:

     $ sudo apt-get install memcached
     $ sudo /etc/init.d/memcached start
     $ sudo /opt/bitnami/ctlscript.sh restart apache
    
PHP5
  • Install development tools:

     $ sudo apt-get update
     $ sudo apt-get install build-essential libtool autoconf unzip wget
    
  • Download the latest source code from the web page, uncompress it and compile the module:

     $ wget https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached-1.0.16.tar.gz
     $ tar -zxf libmemcached-1.0.16.tar.gz
     $ cd libmemcached-1.0.16
     $ ./configure --prefix=/opt/bitnami/common
     $ make
     $ sudo make install
     $ cd ~/
     $ wget http://pecl.php.net/get/memcached-2.1.0.tgz
     $ tar -zxf memcached-2.1.0.tgz
     $ export PHP_AUTOCONF=/usr/bin/autoconf
     $ export PHP_PREFIX=/opt/bitnami/php
     $ cd memcached-2.1.0
     $ /opt/bitnami/php/bin/phpize
     $ ./configure --enable-memcached --with-zlib-dir=/opt/bitnami/common --with-libmemcached-dir=/opt/bitnami/common --with-php-config=/opt/bitnami/php/bin/php-config
     $ make
     $ sudo make install
    
  • Enable the module in the php.ini file:

     ...
     extension=memcached.so
     ...
    
  • Start the memcached server by running these commands:

     $ mv /opt/bitnami/memcached/scripts/ctl.sh.disabled /opt/bitnami/memcached/scripts/ctl.sh
    
     $ sudo /opt/bitnami/ctlscript.sh start memcached
    

    If you get an error, check that your stack includes the memcached server:

     $ sudo /opt/bitnami/ctlscript.sh status memcached
    

    Usually, if you don't see the status, it is because you are using a stack that doesn't bundle the memcached server. To install and start it, run:

     $ sudo apt-get install memcached
     $ sudo /etc/init.d/memcached start
     $ sudo /opt/bitnami/ctlscript.sh restart apache
    

Testing

Once installed, check if the PHP memcached extension is working properly. To do this, create a PHP script file in your htdocs/ directory with the code below and access it using your Web browser:

    <?php
    $mc = new Memcached();
    $mc->addServer("127.0.0.1", 11211);

    $result = $mc->get("test_key");

    if($result) {
        echo $result;
    } else {
        echo "No data in cache. Please refresh page.";
        $mc->set("test_key", "test data pulled from cache!") or die ("Failed to save data in memcached server");
    }
    ?>

How to install the Mongo module?

The Mongo PHP module is a MongoDB driver.

If this module is not in your stack, you can install it manually following these steps:

  • Compile and install the module:

     $ sudo pecl install mongo
     ...
     Build process completed successfully
     Installing '/opt/bitnami/php/lib/php/extensions/<wbr>mongo.so'
     install ok: channel://pecl.php.net/mongo-<wbr>1.4.5</wbr><wbr>
     configuration option "php_ini" is not set to php.ini location
     You should add "extension=mongo.so" to php.ini</wbr></wbr>
    
  • Enable the module in the php.ini file:

     ...
     extension=mongo.so
     ...
    
  • Restart Apache:

     $ /opt/bitnami/ctlscript.sh restart 
    

How to install the OAuth module?

OAuth is an authorization protocol built on top of HTTP which allows applications to securely access data without having to store usernames and passwords.

Follow these steps:

  • Install the following packages:

     $ sudo apt-get update
     $ sudo apt-get install build-essential libtool autoconf unzip wget 
    
  • Download the latest source code from the web page, uncompress it and compile the module.

     $ wget http://pecl.php.net/get/oauth-1.2.2.tgz
     $ tar -zxf oauth*
     $ export PHP_AUTOCONF=/usr/bin/autoconf
     $ export PHP_PREFIX=/opt/bitnami/php
     $ cd oauth-*
     $ /opt/bitnami/php/bin/phpize
     $ ./configure
     $ make
     $ sudo make install
    
  • Enable the module by adding the following line in the php.ini file:

     ...
     extension = '/opt/bitnami/php/lib/php/extensions/oauth.so'
     ... 
    
  • Check if the extension is loaded with the following command:

     $ php -i | grep -i oauth
    

How to install the OCI8 module?

Since LAMP/MAMP/WAMP stacks v5.4.34, 5.5.18 and 5.6.2, Bitnami stacks ship the oci8 module already compiled for each platform. This module requires users to download and install the InstantClient libraries from Oracle.

Follow these steps:

  • Enable the oci8 module in the /opt/bitnami/php/etc/php.ini file.

  • Check if the module is active:

     $ /opt/bitnami/php/bin/php -m
    
  • In case you see an error, download the InstantClient Basic package v11.2.0.4 for your platform from the Oracle website.

  • Extract the package contents in your home folder.

  • Add the following environment variable to the end of your /opt/bitnami/scripts/setenv.sh file:

     LD_LIBRARY_PATH=/home/bitnami/instantclient_11_2:$LD_LIBRARY_PATH
     export LD_LIBRARY_PATH
    
  • Restart the server:

     $ sudo /opt/bitnami/ctlscript.sh restart apache
    
  • Check again if the module is active:

     $ /opt/bitnami/php/bin/php -m
    

How to enable the OpenSSL extension?

The OpenSSL module for PHP is already enabled and no additional configuration is required.

How to install the PDO_IBM module?

The Bitnami LAMP Stack includes the PDO_IBM module but it is necessary to activate it. To do this, follow the steps below:

  • Enable the PDO_IBM module in the /opt/bitnami/php/etc/php.ini file by adding the following line:

     extension=pdo_ibm.so
    
  • Check if the module is enabled with the following command:

     $ /opt/bitnami/php/bin/php -m
    
  • In case you see a PHP warning, download the Data Server Driver Package for your platform from the IBM website.

  • Extract the package contents to your home folder and install it by running the following commands:

     $ cd /home/bitnami/dsdriver
     $ bash installDSDriver 
    
  • Add the following environment variable at the end of your /opt/bitnami/scripts/setenv.sh* file:

     LD_LIBRARY_PATH=/home/bitnami/dsdriver/lib:$LD_LIBRARY_PATH
     export LD_LIBRARY_PATH
    
  • Restart the server:

     $ sudo /opt/bitnami/ctlscript.sh restart apache
    
  • Check again if the module is active. If it is, no warning will be displayed.

     $ /opt/bitnami/php/bin/php -m | grep ibm
    

How to install the pdo_pgsql module?

Install the pdo_pgsql module by following these steps:

  • Download the module source code and extract it:

     $ pecl download pdo_pgsql
     $ tar xzf PDO_PGSQL-1.0.2.tgz
    
  • Compile the code:

     $ cd PDO_PGSQL-1.0.2
     $ phpize
     $ ./configure --with-pdo-pgsql=/path/to/your/PostgreSQL/installation
     $ make && sudo make install
    
  • Confirm that the pdo_pgsql.so extension is available at /opt/bitnami/php/lib/php/extensions.

  • Enable the module by adding the following line to the /opt/bitnami/php/etc/php.ini file inside the "Dynamic Extensions" section:

     extension=pdo_pgsql.so
    

How to install the Redis extension?

The phpredis extension provides an API for communicating with the Redis key-value store. Follow these steps to install it:

  • Install the following packages:

     $ sudo apt-get update
     $ sudo apt-get install autoconf
    
  • Download the latest source code from the web page, uncompress it and compile the module:

     $ wget https://pecl.php.net/get/redis-2.2.7.tgz
     $ tar -xvf redis-2.2.7.tgz
     $ cd redis-2.2.7
     $ phpize
     $ ./configure
     $ make
     $ make install
    
  • Enable the module in the php.ini file by adding this line to the end:

     extension=redis.so
    
  • Check that the module was correctly installed with the following command:

     $ php -m | grep redis
    

More information can be found in the official documentation at https://github.com/phpredis/phpredis.

How to install the Solr module?

The Apache Solr PHP extension is an extremely fast, light-weight, feature-rich library that allows PHP applications to communicate easily and efficiently with Apache Solr server instances using an object-oriented API.

If this module is not in your stack, install it manually following these steps:

  • Install the following packages:

     $ sudo apt-get update
     $ sudo apt-get install build-essential libtool autoconf unzip wget 
    
  • Download the latest source code from the web page, uncompress it and compile the module:

     $ wget http://pecl.php.net/get/solr-1.0.2.tgz
     $ tar -zxf solr-1.0.2.tgz
     $ export PHP_AUTOCONF=/usr/bin/autoconf
     $ export PHP_PREFIX=/opt/bitnami/php
     $ cd solr-1.0.2
     $ /opt/bitnami/php/bin/phpize
     $ ./configure --enable-solr --with-curl=/opt/bitnami/common --with-libxml-dir=/opt/bitnami/common
     $ make
     $ sudo make install
    
  • Enable the module in the php.ini file:

     ...
     extension=solr.so
     ...
    
  • Restart the server:

     $ sudo /opt/bitnami/ctlscript.sh restart apache
    

How to install the SSH2 module for PHP?

Install and enable the SSH2 module for PHP by following these steps:

  • Install the libssl-dev package:

     $ sudo apt-get update
     $ sudo apt-get install libssl-dev
    
  • Download and compile libssh2 and ssh2:

     $ cd /tmp
     $ wget http://www.libssh2.org/download/libssh2-1.4.3.tar.gz
     $ tar vxzf libssh2-1.4.3.tar.gz
     $ cd libssh2-1.4.3
     $ ./configure
     $ make
     $ make install
     $ cd /tmp
     $ wget http://pecl.php.net/get/ssh2-0.12.tgz
     $ tar vxzf ssh2-0.12.tgz
     $ cd ssh2-0.12
     $ phpize
     $ ./configure --with-ssh2
     $ make
     $ make install
    
  • Copy the ssh2.so file into the shared extensions folder at /opt/bitnami/php/lib/php/extensions/ and modify the /opt/bitnami/php/etc/php.ini file to add the following line:

     ...
     extension=ssh2.so
     ...
    
  • Restart the server and you will now have the ability to run SSH2 commands.

Thanks to @Chris_James for posting this guide!

How to install the Tidy module?

Tidy is a binding for the Tidy HTML clean and repair utility which allows you to not only clean and otherwise manipulate HTML documents, but also traverse the document tree.

If this module is not in your stack, you can install it manually following these steps:

  • Install the following packages (they are already in the machine in recent versions):

     $ sudo apt-get update
     $ sudo apt-get install build-essential libtool autoconf unzip wget 
    
  • Download the latest source code from the web page, uncompress it and compile the module:

     $ wget http://tidy.cvs.sourceforge.net/viewvc/tidy/tidy/?view=tar
    
  • Uncompress it and build the libraries:

     $ cd /home/bitnami
     $ tar -xzvf tidy-tidy.tar.gz
     $ cd tidy/build/gmake
     $ make
    
  • Download the PHP source code version that you are currently using and uncompress it. Then, build the shared module for tidy:

     $ tar -xzvf php-VERSION.tar.gz
     $ cd php/ext/tidy
     $ ./phpize
     $ ./configure --with-tidy=/home/bitnami/tidy
     $ make
     $ sudo make install
    

How to enable the XCache extension?

The XCache module is installed in Bitnami stacks, but is not enabled by default. To enable it, follow these steps:

  • Add the following lines to the /opt/bitnami/php/etc/php.ini file:

     ...
     [xcache-common]
     extension=xcache.so
     ...
    
  • Restart the Apache server to include the new configuration:

     $ sudo /opt/bitnami/ctlscript.sh restart apache
    

How to install the XCache administration page?

Once XCache is installed, add the XCache administration page to obtain information on cache operations. This is not included by default, so follow the steps below:

  • Download the complete tarball containing the XCache Administration Page for the XCache version included in the Bitnami stack. Find XCache versions at http://xcache.lighttpd.net. To check your current XCache version, use the command php -v.

  • Extract the tarball content and use the htdocs folder to enable the XCache administration page.

  • Generate and save your authentication password. The XCache administration page is protected with HTTP authentication. Edit your php.ini file and add these lines to include your user and password.

     xcache.admin.user = "user"
     xcache.admin.pass = "6a4dc9133d5f3b6d9fff778aff361961"
    

    The password must be specified in MD5 format. Here is a simple PHP script that returns the encrypted MD5 version of a plaintext password:

     <?php
     echo md5("password");
     ?>
    
  • Create a new xcache directory and add the Apache configuration files to it. Find out how to create a custom application.

  • Access your XCache administration page through your browser.

How to install the Zend Guard Loader extension?

Zend Guard is a free runtime application that enables PHP to run scripts encoded by Zend Guard. It can be freely used by anyone looking to run encoded applications. Follow these steps:

  • Download the binary version of the extension from the Zend Guard site.

  • Run the following commands:

     $ tar -xzvf  ZendGuardLoader-*-PHP-5.4-linux-glibc23-x86_64.tar.gz
     $ sudo cp ZendGuard*/php-5.4.x/ZendGuardLoader.so /opt/bitnami/php/lib/php/extensions/
    
  • Add the following entry to the end of the php.ini file:

     zend_extension = /opt/bitnami/php/lib/php/extensions/ZendGuardLoader.so
    
  • Check that the module was correctly installed with the following command:

     $ php -m | grep Zend
    

How to enable the ZipArchive extension?

ZipArchive is a class of the zip PHP module. This module is enabled by default. Check it with the following command:

$ sudo /opt/bitnami/php/bin/php -m | grep zip
zip

Here is a script named sample.php that lists the content of a zip file named sample.zip:

<?php
$za = new ZipArchive();
$za->open('sample.zip');
for( $i = 0; $i < $za->numFiles; $i++ ){
    $stat = $za->statIndex( $i );
    print_r( basename( $stat['name'] ) . PHP_EOL );
}
?>

To use this script, create a sample.zip file and run this script at the server console, as below:

$ /opt/bitnami/php/bin/php sample.php

How to install New Relic for PHP?

To install New Relic for PHP, refer to this page.

How to modify the allowed limit for uploaded files?

Modify the following options in the /opt/bitnami/php/etc/php.ini file to increase the allowed size for uploads:

; Maximum size of POST data that PHP will accept.
post_max_size = 16M

; Maximum allowed size for uploaded files.
upload_max_filesize = 16M

Restart PHP-FPM and Apache for the changes to take effect.

$ sudo /opt/bitnami/ctlscript.sh restart apache
$ sudo /opt/bitnami/ctlscript.sh restart php-fpm    

How to modify the execution time?

This parameter sets the timeout for Apache to run a script. Modify it in the php.ini file.

max_execution_time = 120     ; Maximum execution time of each script, in seconds 

How to check the PHP modules installed?

The easiest way to test your PHP installation is to create a test script using the phpinfo() function. Open your favorite text editor and type:

<?php phpinfo(); ?>

Save the file as phptest.php in /opt/bitnami/apache2/htdocs/. Make sure Apache is up and running, open a browser and type http://SERVER-IP/phptest.php. You should then see a screen showing detailed information about the PHP version you are using.

You can also run the following command:

$ /opt/bitnami/php/bin/php -m

How to send email via an external SMTP account?

To make sure your emails are delivered properly, configure your PHP script or PHP application to use an external SMTP account. The following example shows how to do this using a Gmail account.

  • Install the Mail and Net_SMTP PEAR modules:

     $ sudo /opt/bitnami/php/bin/pear install pear/Net_SMTP pear/Mail-1.2.0
    

    Note that if these packages are already installed in your system you see the messages below when executing that command:

     Ignoring installed package pear/Net_SMTP
     Ignoring installed package pear/Mail
     Nothing to install
    
  • Use the script below to send an email. Place it in your pear directory and execute it with the PHP CLI:

     <?php
     require_once "Mail.php";
    
     $from = "myaccount@gmail.com";
     $to = 'test@mytest.com';
    
     $host = "ssl://smtp.gmail.com";
     $port = "465";
     $username = 'myaccount@gmail.com';
     $password = 'mypassword';
    
     $subject = "test";
     $body = "test";
    
     $headers = array ('From' => $from, 'To' => $to,'Subject' => $subject);
     $smtp = Mail::factory('smtp',
       array ('host' => $host,
         'port' => $port,
         'auth' => true,
         'username' => $username,
         'password' => $password));
    
     $mail = $smtp->send($to, $headers, $body);
    
     if (PEAR::isError($mail)) {
       echo($mail->getMessage());
     } else {
       echo("Message successfully sent!\n");
     }
     ?>
    

How to send email using sendmail?

To use sendmail instead of an external SMTP server, configure it by uncommenting this line in the PHP configuration file at /opt/bitnami/php/etc/php.ini:

    sendmail_path = "env -i /usr/sbin/sendmail -t -i"

Where is the PHP configuration file?

The PHP configuration file allows you to configure the modules enabled, the email settings or the size of the upload files. It is located at /opt/bitnami/php/etc/php.ini.