Content

Bitnami LAMP for Google Cloud Platform

Description

Bitnami LAMP Stack provides a complete PHP, MySQL and Apache development environment for Linux that can be launched in one click.

First steps with the Bitnami LAMP Stack

Welcome to your new Bitnami application running on Google Cloud Platform! Here are a few questions (and answers!) you might need when first starting with your application.

What credentials do I need?

You need two sets of credentials:

The application password. This will allow you to log in to the services of the Bitnami stack.

The server credentials, consisting of an SSH username and key. These credentials allow you to log in to your Google Cloud Platform server using an SSH client and execute commands on the server using the command line.

How do I get my SSH key or password?

What are the default ports?

A port is an endpoint of communication in an operating system that identifies a specific process or a type of service. Bitnami stacks include several services or servers that require a port.

Remember that if you need to open some ports you can follow the instructions given in the FAQ to learn how to open the server ports for remote access.

Port 22 is the default port for SSH connections.

Bitnami opens some ports for the main servers. These are the ports opened by default: 80, 443.

How can I get started with LAMP?

Once the deployment finishes, you can access the welcome page from your browser: http://SERVER-IP/.

Regardless of how you access it, you should see a page similar to the examples below:

To get started with Bitnami AMP stacks, we suggest the following steps:

Step 1. Deploy your 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. If you do not have a PHP application yet, we suggest deploying the PHP info example.

Step 2. Add a Bitnami application on top of the AMP stack.

You can install additional Bitnami applications on top of an AMP stack using module installers. You can download WordPress, Drupal, Magento, Moodle among other applications from the Bitnami website and extend the functionality of your server.

Step 3. Access phpMyAdmin.

phpMyAdmin is a PHP-based application intended to handle the administration of MySQL over the Web. Find more information on how to access phpMyAdmin.

How to start or stop the services?

Each Bitnami stack includes a control script that lets you easily stop, start and restart services. The script is located at /opt/bitnami/ctlscript.sh. Call it without any service name arguments to start all services:

$ sudo /opt/bitnami/ctlscript.sh start

Or use it to restart a single service, such as Apache only, by passing the service name as argument:

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

Use this script to stop all services:

$ sudo /opt/bitnami/ctlscript.sh stop

Restart the services by running the script without any arguments:

$ sudo /opt/bitnami/ctlscript.sh restart

Obtain a list of available services and operations by running the script without any arguments:

$ sudo /opt/bitnami/ctlscript.sh

How can I run a command in the Bitnami LAMP Stack?

Bitnami cloud images have been already configured to run any command in the server directly. You can run the following ones to check the versions of the components that are already installed:

Enter the passphrase twice. The SSH key pair will be generated and saved in /home/USERNAME/.ssh/my-ssh-key and /home/USERNAME/.ssh/my-ssh-key.pub.

Although you can use any SFTP/SCP client to transfer files to your server, this guide documents FileZilla (Windows, Linux and Mac OS X), WinSCP (Windows) and Cyberduck (Mac OS X).

Using an SSH Key

Once you have your server's SSH key, choose your preferred application and follow the steps below to connect to the server using SFTP.

FileZilla

IMPORTANT: To use FileZilla, your server private key should be in PPK format.

Follow these steps:

Download and install FileZilla.

Launch FileZilla and use the "Edit -> Settings" command to bring up FileZilla's configuration settings.

Within the "Connection -> SFTP" section, use the "Add keyfile" command to select the private key file for the server. FileZilla will use this private key to log in to the server.

Use the "File -> Site Manager -> New Site" command to bring up the FileZilla Site Manager, where you can set up a connection to your server.

Enter your server host name and specify bitnami as the user name.

Select "SFTP" as the protocol and "Ask for password" as the logon type.

Use the "Connect" button to connect to the server and begin an SFTP session. You might need to accept the server key, by clicking "Yes" or "OK" to proceed.

You should now be logged into the /home/bitnami directory on the server. You can now transfer files by dragging and dropping them from the local server window to the remote server window.

If you have problems accessing your server, get extra information by use the "Edit -> Settings -> Debug" menu to activate FileZilla's debug log.

WinSCP

IMPORTANT: To use WinSCP, your server private key should be in PPK format.

Follow these steps:

Download and install WinSCP.

Launch WinSCP and in the "Session" panel, select "SFTP" as the file protocol.

Enter your server host name and specify bitnami as the user name.

Click the "Advanced…" button and within the "SSH -> Authentication -> Authentication parameters" section, select the private key file for the server. WinSCP will use this private key to log in to the server.

From the "Session" panel, use the "Login" button to connect to the server and begin an SCP session.

You should now be logged into the /home/bitnami directory on the server. You can now transfer files by dragging and dropping them from the local server window to the remote server window.

If you need to upload files to a location where the bitnami user doesn't have write permissions, you have two options:

Once you have configured WinSCP as described above, click the "Advanced…" button and within the "Environment -> Shell" panel, select sudo su - as your shell. This will allow you to upload files using the administrator account.

Upload the files to the /home/bitnami directory as usual. Then, connect via SSH and move the files to the desired location with the sudo command, as shown below:

$ sudo mv /home/bitnami/uploaded-file /path/to/desired/location/

Cyberduck

IMPORTANT: To use Cyberduck, your server private key should be in PEM format.

Follow these steps:

Select the "Open Connection" command and specify "SFTP" as the connection protocol.

In the connection details panel, under the "More Options" section, enable the "Use Public Key Authentication" option and specify the path to the private key file for the server.

Use the "Connect" button to connect to the server and begin an SFTP session.

You should now be logged into the /home/bitnami directory on the server. You can now transfer files by dragging and dropping them from the local server window to the remote server window.

How to connect instances hosted in separate virtual networks or VPCs?

The Google Cloud Platform makes it possible to connect instances hosted in separate Virtual Private Clouds (VPCs), even if those instances belong to different projects or are hosted in different regions. This feature, known as VPC Network Peering, can result in better security (as services do not need to be exposed on public IP addresses) and performance (due to use of private, rather than public, networks and IP addresses).

Which components are included in LAMP?

The Bitnami LAMP Stack ships the components listed below. If you want to know which specific version of each component is bundled in the stack you are downloading, check the README.txt file in the download page or in the /opt/bitnami directory. You can also find more information about each component using the links below.

Main components:

PHP scripting language

Apache Web server

MySQL/MariaDB database server

phpMyAdmin web application management tool for MySQL database

Frameworks for development (included in stacks with PHP 5.6 and lower):

Zend Framework

Symfony

CodeIgniter

CakePHP

Smarty

Laravel

Dependencies and additional components:

Varnish proxy cache server

ImageMagick tool

SQLite database

ModSecurity module

XDebug module

Xcache module

OAuth module

Memcache module

FastCGI module

APC module

GD library

OpenSSL library

CURL library

OpenLDAP library

PEAR and PECL package manager tools

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 can I check the PHP configuration with phpinfo?

Some versions of the Bitnami LAMP Stack include a docs/ folder in the installation directory that contains some PHP examples. Among these is a phpinfo.php script that shows the current PHP configuration and is typically used to check that PHP was installed correctly. In order to be able to access it, follow these steps below:

Copy the phpinfo.php script from the installation directory to a publicly accessible location under the Web server document root.

$ cp /opt/bitnami/docs/phpinfo.php /opt/bitnami/apache2/htdocs

Browse to http://SERVER-IP/phpinfo.php.

You should see something like the page below, which contains detailed information on your PHP deployment.

How can I add applications on top of LAMP?

You can install several application modules on top of LAMP. That way, all of the Bitnami-packaged applications you want to run will share a single instance of Apache, MySQL or PostgreSQL (depending on the stack) and PHP, which will save space and improve performance.

NOTE: You can only install PHP-based application modules on Bitnami LAMP Stack.

Once you have selected the application module you want to add, follow the steps below to install it:

Change to a temporary folder, download the module and make it executable. Then, execute the installation script. For example, if you're installing WordPress, you would use commands similar to the following:

NOTE: Both the URL for downloading the module and the name of the installer may vary depending on the application and version you are trying to install. Make sure that you are using the correct URL link and the installer name.

During the installation process, you will need to specify the installation directory of your Bitnami LAMP Stack. By default, the installation directory is /opt/bitnami.

During the installation process, you will also need to specify the current database administrator's password (the password for user root for MySQL databases and user postgres for PostgreSQL databases). This password is part of the application credentials. Find out how to obtain credentials in the FAQ.

During the installation process, you will also be prompted to create an administrator account for the application, by providing a user name and/or an email address. Some application modules may also ask you to specify a password.

NOTE: If not specifically prompted for a password, the default administrator password for the application is automatically set to the same value as the database administrator's password provided in the previous step. This default administrator password can be changed at any time through the application's Web administration panel or Web dashboard, after the module has been successfully installed.

After the installation process is complete, access the installed application by browsing to http://SERVER-IP/APPNAME. For example, if you have installed WordPress, you can access it at http://SERVER-IP/wordpress. To access the application's administration panel or Web dashboard, use the application administrator account credentials set during the module installation process.

How to create a full backup of LAMP?

Backup

The Bitnami LAMP Stack is self-contained and the simplest option for performing a backup is to copy or compress the Bitnami stack installation directory. To do so in a safe manner, you will need to stop all servers, so this method may not be appropriate if you have people accessing the application continuously.

Follow these steps:

Change to the directory in which you wish to save your backup:

$ cd /your/directory

Stop all servers:

$ sudo /opt/bitnami/ctlscript.sh stop

Create a compressed file with the stack contents:

$ sudo tar -pczvf application-backup.tar.gz /opt/bitnami

Restart all servers:

$ sudo /opt/bitnami/ctlscript.sh start

You should now download or transfer the application-backup.tar.gz file to a safe location.

Restore

Follow these steps:

Change to the directory containing your backup:

$ cd /your/directory

Stop all servers:

$ sudo /opt/bitnami/ctlscript.sh stop

Move the current stack to a different location:

$ sudo mv /opt/bitnami /tmp/bitnami-backup

Uncompress the backup file to the original directoryv

$ sudo tar -pxzvf application-backup.tar.gz -C /

Start all servers:

$ sudo /opt/bitnami/ctlscript.sh start

If you want to create only a database backup, refer to these instructions for MySQL and PostgreSQL.

How can I run a custom PHP script?

Add your PHP script to the /opt/bitnami/apache2/htdocs/ directory, then browse to it via the URL http://SERVER-IP/FILENAME.php, where FILENAME is the name of the PHP script.

NOTE: If your script file is named index.php, then you must access it using the URL http://SERVER-IP/index.php and not http://SERVER-IP. This is because the Apache server included in the AMP stack is configured to recognize both index.html and index.php files by default, but to give the included index.html file priority. To alter this behaviour, simply move the /opt/bitnami/apache2/htdocs/index.html file to a different location.

What are the "development" and "production" modes for applications?

Applications are configured using production mode on cloud servers by default.

How to access phpMyAdmin?

For security reasons, phpMyAdmin is accessible only when using 127.0.0.1 as the hostname. To access it from a remote system, you must create an SSH tunnel that routes requests to the Web server from 127.0.0.1. This implies that you must be able to connect to your server over SSH in order to access these applications remotely.

IMPORTANT: Before following the steps below, ensure that your Web and database servers are running.

NOTE: The steps below suggest using port 8888 for the SSH tunnel. If this port is already in use by another application on your local machine, replace it with any other port number greater than 1024 and modify the steps below accordingly. Similarly, if you have enabled Varnish, your stack's Web server might be running on port 81. In this case, modify the steps below to use port 81 instead of port 80 for the tunnel endpoint.

Accessing phpMyAdmin on Windows

Watch the following video to learn how to easily access phpMyAdmin on Windows through an SSH tunnel:

Once you have your SSH client correctly configured and you tested that you can successfully access to your instance via SSH, you need to create an SSH tunnel in order to access phpMyAdmin. For doing so, follow these steps:

In the "Connection -> SSH -> Tunnels" section, add a new forwarded port by introducing the following values:

Source port: 8888

Destination: localhost:80

This will create a secure tunnel by forwarding a port (the "destination port") on the remote server to a port (the "source port") on the local host (127.0.0.1 or localhost).

Click the "Add" button to add the secure tunnel configuration to the session. (You'll see the added port in the list of "Forwarded ports").

In the "Session" section, save your changes by clicking the "Save" button.

Click the "Open" button to open an SSH session to the server. The SSH session will now include a secure SSH tunnel between the two specified ports.

Access the phpMyAdmin console through the secure SSH tunnel you created, by browsing to http://127.0.0.1:8888/phpmyadmin.

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:

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.

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 to disable the cache in the server?

If you are developing on top of an AMP Stack or customizing any Bitnami Stack, your files (like JavaScript files) may be cached by the server and even you modify them your changes will not appear to be applied.

In order to disable the cache in the server and let the files be served each time, disable PageSpeed for Apache and OPCache, enabled by default in PHP.

To disable PageSpeed, comment out the following lines in your httpd.conf (/opt/bitnami/apache2/conf/httpd.conf)

#Include conf/pagespeed.conf
#Include conf/pagespeed_libraries.conf

To disable OPCache, change opcache.enable in your php.ini file and set it to 0 (/opt/bitnami/php/etc/php.ini)