Deploy your Bitnami Nginx Stack on Google Cloud Platform now! Launch Now

Bitnami Nginx for Google Cloud Platform

Description

Nginx is a popular web server that can also be used as a reverse proxy, load balancer, and http cache. Also included in this stack are MySQL, PHP, and other of components and libraries.

First steps with the Bitnami Nginx 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.

What is the administrator password?

What SSH username should I use for secure shell access to my application?

SSH username: bitnami

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.

Which components are installed with the Bitnami Nginx Stack?

The Bitnami Nginx 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 on the download page or in the stack installation directory. You can also find more information about each component using the links below.

Main components

Dependencies and additional components

  • Varnish proxy cache server
  • ImageMagick tool
  • SQLite database
  • XDebug module
  • Memcache module
  • APC module
  • GD library
  • OpenSSL library
  • CURL library
  • OpenLDAP library
  • PEAR and PECL package manager tools

How can I get started with Nginx?

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

To get started, we suggest the following steps:

Step 1. Deploy a custom PHP application.

The main directory to deploy your PHP application is */opt/bitnami/nginx/html/. 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.

Do you have issues trying to connect to your server? Check our FAQ.

Step 2. Create a virtual host for your application.

Nginx lets you configure virtual hosts for your applications, such that you can access them at (for example) http://APPNAME.example.com instead of http://example.com/APPNAME.

For information on how to do this, refer to these instructions.

Step 3. Access phpMyAdmin.

phpMyAdmin is a PHP-based application intended to handle the administration of MySQL over the Web. For security reasons, this application is not accessible via web by default. To access it from a remote system, we recommend creating a SSH tunnel that routes requests to the Apache Web server from 127.0.0.1.

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 to upload files to the server with SFTP?

NOTE: Bitnami applications can be found in /opt/bitnami/apps.
  • If you are using the Bitnami Launchpad for Google Cloud Platform, obtain your server SSH key by following these steps:

    • Browse to the Bitnami Launchpad for Google Cloud Platform dashboard and sign in if required using your Bitnami account.
    • Select the "Virtual Machines" menu item.
    • Select your cloud server from the resulting list.
    • Download the SSH key for your server in PPK or PEM format. Note the server IP address on the same page.

Server information

NOTE: Replace USERNAME in the commands below with your Google Cloud platform username.
	$ sudo su USERNAME
	$ ssh-keygen -t rsa -f ~/.ssh/my-ssh-key -C USERNAME
  • 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.

    FileZilla configuration

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

    FileZilla configuration

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

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

    WinSCP configuration

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

    WinSCP configuration

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

    WinSCP configuration

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

    Cyberduck configuration

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

    Cyberduck configuration

  • 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).

Learn more about VPC Network Peering.

How can I check the PHP configuration with phpinfo?

Some versions of the Bitnami Nginx Stack include a docs/ folder 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:

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

     $ cd /opt/bitnami
     $ cp docs/phpinfo.php nginx/html
    
  • Browse to http://SERVER-IP/phpinfo.php.

You should see something similar to this page:

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/nginx/html 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/nginx/conf/bitnami/bitnami-apps-prefix.conf file:

      include "/opt/bitnami/apps/demo/conf/nginx-prefix.conf";
      
    • Restart the Nginx server using the command-line tool.

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

    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/nginx-prefix.conf file and add the line below to it:

      location /myapp {
      alias "/opt/bitnami/apps/myapp/htdocs/";
      include "/opt/bitnami/apps/myapp/conf/nginx-app.conf";
      }
      
    • Create and edit the /opt/bitnami/apps/myapp/conf/nginx-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.

      index index.php index.html index.htm;
      location ~ \.php$ {
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_read_timeout 300;
      fastcgi_pass unix:/opt/bitnami/php/var/run/www.sock;
      fastcgi_index index.php;
      fastcgi_param  SCRIPT_FILENAME $request_filename;
      include fastcgi_params;
      }
      
    • Add the following line to the end of the /opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf file:

      include "/opt/bitnami/apps/myapp/conf/nginx-prefix.conf";
      
    • Restart the Nginx server:

      $ sudo /opt/bitnami/ctlscript.sh restart nginx
      
    • Access the application at http://SERVER-IP/myapp.

  • If you want to use a virtual host for an application located at /opt/bitnami/apps/myapp, edit the /opt/bitnami/apps/myapp/conf/nginx-vhosts.conf and add the content below to it:

    server {
        listen    80;
        root "/opt/bitnami/apps/myapp/htdocs/";
        server_name  myapp.example.com www.myapp.example.com;
        include "/opt/bitnami/apps/myapp/conf/nginx-app.conf";
    }
    server {
        listen    443 ssl;
        root   "/opt/bitnami/apps/myapp/htdocs/";
        server_name  myapp.example.com www.myapp.example.com;
        ssl_certificate  "/opt/bitnami/apps/myapp/conf/certs/server.crt";
        ssl_certificate_key  "/opt/bitnami/apps/myapp/conf/certs/server.key";
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        include "/opt/bitnami/apps/myapp/conf/nginx-app.conf";
    }
    
    • Add the following line to the end of the /opt/bitnami/nginx/conf/bitnami/bitnami-apps-vhosts.conf file:

      include "/opt/bitnami/apps/myapp/conf/nginx-vhosts.conf";
      
    • Restart the Nginx server:

      $ sudo /opt/bitnami/ctlscript.sh restart nginx
      
    • Access the application at http://myapp.example.com.

How to install WordPress on top of the Bitnami Nginx Stack?

Follow the steps below:

  • Copy the demo/ directory from the /opt/bitnami/docs directory to the /opt/bitnami/apps directory and remove the htdocs/ directory from the demo application.

      $ cd /opt/bitnami
      $ sudo cp -r docs/demo apps/wordpress
      $ sudo rm -rf /opt/bitnami/apps/wordpress/htdocs/
    
  • Download the latest version of WordPress and extract the files to the /opt/bitnami/apps/wordpress/ directory, then rename the directory containing the extracted files to /opt/bitnami/apps/wordpress/htdocs/.

      $ cd /tmp
      $ wget https://wordpress.org/latest.tar.gz
      $ sudo tar xfvz latest.tar.gz -C /opt/bitnami/apps/wordpress/
      $ sudo mv /opt/bitnami/apps/wordpress/wordpress/ /opt/bitnami/apps/wordpress/htdocs/
    
  • Update the configuration files using the commands below:

      $ sudo sed -i 's/demo/wordpress/g' /opt/bitnami/apps/wordpress/conf/nginx-prefix.conf
      $ sudo sed -i 's/demo/wordpress/g' /opt/bitnami/apps/wordpress/conf/nginx-vhosts.conf
    
  • Add the following entry in the /opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf file:

      include "/opt/bitnami/apps/wordpress/conf/nginx-prefix.conf";
    
  • If you plan to use WordPress permalinks, add this configuration snippet to your /opt/bitnami/apps/wordpress/conf/nginx-app.conf file before the location directive.

      if (!-e $request_filename)
      {
       rewrite ^/wordpress/(.+)$ /wordpress/index.php?q=$1 last;
      }
    
  • Change ownership for the WordPress application by running the following command:

      $ sudo chown -R bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/
    
  • Change the permissions of the WordPress files by running the following commands:

      $ sudo find /opt/bitnami/apps/wordpress/htdocs/ -type d -exec chmod 775 {} \;
      $ sudo find /opt/bitnami/apps/wordpress/htdocs/ -type f -exec chmod 664 {} \;
    
  • Create a database for WordPress.

      $ /opt/bitnami/mysql/bin/mysql -u root -p
      mysql> create database bitnami_wordpress;
    
    NOTE: When you connect to the MySQL database server, you will be prompted to enter the root user password. This is the same as the application password.
  • Create a database user for WordPress.

      mysql> grant all privileges on bitnami_wordpress.* to 'bn_wordpress'@'localhost'
      identified by 'WORDPRESS-PASSWORD';
      mysql> exit
    

    Keep in mind that you must replace the WORDPRESS-PASSWORD placeholder with an user-defined password that you will use when installing WordPress.

  • Restart NGINX.

      $ sudo /opt/bitnami/ctlscript.sh restart nginx
    
  • Browse to http://SERVER-IP/wordpress to launch the WordPress Web configuration wizard. Simply follow the steps as prompted by the wizard. Click the "Let's go" button to start the wizard.

Start WordPress Database Configuration

  • Use the credentials specified earlier when asked for the database configuration and application credentials, as below:

      Database Name: bitnami_wordpress
      User Name: bn_wordpress
      Password:  WORDPRESS_PASSWORD
      Database Host: localhost
      Table Prefix: wp_
    

WordPress Database Configuration

  • Create the wp-config.php file manually in the htdocs/ directory by pasting the text indicated in the WordPress configuration file.

  • Return to the browser and click the "Run Install" button.

Create wp-config.php file

  • End the WordPress installation process filling the information needed. Click the "Install WordPress" button.

    IMPORTANT: Use the credentials specified earlier when creating the database user for WordPress. Remember that you must replace the WORDPRESS-PASSWORD placeholder with the same password you defined when creating the database user for WordPress.

WordPress site information

  • Run the following command to disable FTP authentication for plugins installation:

      $ sudo echo "define ( 'FS_METHOD', 'direct' );" >> /opt/bitnami/apps/wordpress/htdocs/wp-config.php
    
  • Change the permissions of the wp-config.file file. Run the following commands:

      $ sudo chmod 640 wp-config.php /opt/bitnami/apps/wordpress/htdocs/wp-config.php
      $ sudo chown bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/wp-config.php
    
  • Access the Administration panel of your application by clicking the "Log In" button.

    WordPress

  • Check the application has been installed. You should see the screen below:

WordPress Administration Dashboard

Visit your WordPress site

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:

In order to access phpMyAdmin via SSH tunnel you need an SSH client. In the instructions below we have selected PuTTY, a free SSH client for Windows and UNIX platforms. The first step is having PuTTY configured. Please, check how to configure it in the section how to connect to the server through SSH using an SSH client on Windows.

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").

    PuTTY configuration

  • 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.
  • Log in to phpMyAdmin by using the following credentials:

    • Username: root
    • Password: application password. (Refer to our FAQ to learn how to find your application credentials).

Here is an example of what you should see:

Access phpMyAdmin

If you are unable to access phpMyAdmin, verify that the SSH tunnel was created by checking the PuTTY event log (accessible via the "Event Log" menu):

PuTTY configuration

Accessing phpMyAdmin on Linux and Mac OS X

To access the application using your Web browser, create an SSH tunnel, as described below.

  • Open a new terminal window on your local system (for example, using "Finder -> Applications -> Utilities -> Terminal" in Mac OS X or the Dash in Ubuntu).
  • Make sure that you have your SSH credentials (.pem key file) in hand.
  • Run the following command to configure the SSH tunnel. Remember to replace KEYFILE with the path to your private key and SERVER-IP with the public IP address or hostname of your server:

       $ ssh -N -L 8888:127.0.0.1:80 -i KEYFILE bitnami@SERVER-IP
    
NOTE: If successful, the above command will create an SSH tunnel but will not display any output on the server console.
  • Access the phpMyAdmin console through the secure SSH tunnel you created, by browsing to http://127.0.0.1:8888/phpmyadmin.
  • Log in to phpMyAdmin by using the following credentials:

    • Username: root
    • Password: application password. (Refer to our FAQ to learn how to find your application credentials).

Here is an example of what you should see:

Access phpMyAdmin

How to increase the upload size limit in the Bitnami Nginx Stack?

Add the client_max_body_size directive inside the http { } section of the /opt/bitnami/nginx/conf/nginx.conf file. For instance, to increase your upload size to 20MB, add the following line:

client_max_body_size 20m;

Remember to restart the Nginx server for your changes to take effect.

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

To increase the upload file size limit for PHP, follow the steps described here.

How to create a Virtual Host in the Bitnami Nginx Stack?

Nginx lets you configure virtual hosts for your applications, such that you can access them at (for example) http://APPNAME.example.com instead of http://example.com/APPNAME.

NOTE: Replace APPNAME in the instructions below with the actual name/path to your application.
  • Edit the /opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf file and comment out the line below so that it looks like this:

    #include "/opt/bitnami/apps/APPNAME/conf/nginx-prefix.conf";
    
  • Include the virtual host configuration file for your application in the /opt/bitnami/nginx/conf/bitnami/bitnami-apps-vhosts.conf file:

     include "/opt/bitnami/apps/APPNAME/conf/nginx-vhosts.conf";
    
  • Update the application's nginx-app.conf file at /opt/bitnami/apps/APPNAME/conf/nginx-app.conf with the revised application URL if necessary. For example, you might replace the line

     rewrite ^/wordpress/(.+)$ /wordpress/index.php?q=$1 last;
    

    with

     rewrite ^/(.+)$ /index.php?q=$1 last;
    
  • Update the application configuration to reflect the revised URL if necessary. This is an application-specific step and different applications will require different changes. For example, if you are using WordPress, you would need to edit the /opt/bitnami/apps/wordpress/htdocs/wp-config.php file and add the following lines:

     define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
     define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/');
    
  • Restart the Nginx server:

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

How to install a Let's Encrypt certificate in your Web server?

To learn more about this topic, read our guide on generating and installing Let's Encrypt certificates for Bitnami applications.

google