WebFaction
Community site: login faq

I'm looking for an easy way to install an Apache+PHP instance. I don't really need a full private LAMP stack, because I can use the server's MySQL instance instead of needing my own, but it would be nice to have both options.

The first logical option is a Private Instance of the Shared Apache. This works if the requirements for the application can be satisfied by the configuration of the shared Apache server, and I'm looking primarily for isolation.

In other cases, such as passing a PHP Authorization header, I'd like a more flexible, full featured private stack. For this, Bitnami's installers look good.

I'd like a fairly unified installation procedure that works for these installers, starting with a LAMP stack, add-on options (such as Varnish, Laraval, phpMyAdmin) included but not enabled (loaded) by default. In this way, I'd have a fairly minimal, lightweight Apache stack with several optional add-ons which I can enable easily at a later time as needed.

asked 15 Oct '15, 07:56

ryans ♦♦
5.0k103760
accept rate: 43%


The Bitnami stack comes with both Apache and MySQL, but initially you don't necessarily need the private MySQL instance. In this case, you need only one reserved port (for Apache), and don't need to run MySQL - but the binaries still exist if you need it later.

Therefore, you'll first need to create one Custom Application (listening on port) - take a note of the assigned port. Create a directory or empty application to hold your actual application code (this example will use a "$HOME/webapps/app1").

Then, set these environment variables and run the following script:

APACHE_PORT=77777
LAMP_PREFIX="$HOME/lamp"
WEBAPP_DIR="$HOME/webapps/app1"

mkdir -p $HOME/src
cd $HOME/src
wget 'https://bitnami.com/redirect/to/73070/bitnami-lampstack-5.5.30-0-linux-x64-installer.run'
chmod 755 bitnami-lampstack-5.5.30-0-linux-x64-installer.run

cat << EOF > 'wf_config'
prefix=__HOME__
base_user=__USERNAME__
base_password=__RANDPASS1__
apache_server_port=__APACHE_PORT__
apache_server_ssl_port=__APACHE_PORT__
web_server_domain=127.0.0.1
mysql_port=__APACHE_PORT__
mysql_password=__RANDPASS2__
mysql_database_name=mysql_db
mysql_database_username=mysql_user
mysql_database_password=__RANDPASS3__
phpmyadmin_password=__RANDPASS4__
EOF

function genpasswd() {
  local l=""
  [ -n "${1+x}" ] && l=$1
  [ "$l" == "" ] && l=12
  tr -dc ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789 < /dev/urandom 2> /dev/null | head -c $l | xargs
}

sed -i "s^__HOME__^$LAMP_PREFIX^g" wf_config
sed -i "s^__USERNAME__^$USER^g" wf_config
sed -i "s^__RANDPASS1__^$(genpasswd)^g" wf_config
sed -i "s^__RANDPASS2__^$(genpasswd)^g" wf_config
sed -i "s^__RANDPASS3__^$(genpasswd)^g" wf_config
sed -i "s^__RANDPASS4__^$(genpasswd)^g" wf_config
sed -i "s^__APACHE_PORT__^$APACHE_PORT^g" wf_config

./bitnami-lampstack-5.5.30-0-linux-x64-installer.run --mode unattended --optionfile wf_config
$LAMP_PREFIX/ctlscript.sh stop &> /dev/null

cat << EOF >> "$LAMP_PREFIX/apache2/conf/httpd.conf"
<VirtualHost _default_:__APACHE_PORT__>
  DocumentRoot "__WEBAPP_DIR__"
  <Directory "__WEBAPP_DIR__">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>
EOF

sed -i "s^LoadModule ssl_module modules/mod_ssl.so^#LoadModule ssl_module modules/mod_ssl.so^" "$LAMP_PREFIX/apache2/conf/httpd.conf"
sed -i "s^Include \"${LAMP_PREFIX}/apache2/conf/bitnami/bitnami.conf\"^#Include \"${LAMP_PREFIX}/apache2/conf/bitnami/bitnami.conf\"^" "$LAMP_PREFIX/apache2/conf/httpd.conf"
sed -i "s^__APACHE_PORT__^$APACHE_PORT^g" "$LAMP_PREFIX/apache2/conf/httpd.conf"
sed -i "s^__WEBAPP_DIR__^$WEBAPP_DIR^g" "$LAMP_PREFIX/apache2/conf/httpd.conf"

$LAMP_PREFIX/apache2/scripts/ctl.sh start

The above sets the Apache and MySQL ports to the same value (this way, you're not trying to use a non-reserved port), but only starts Apache, so it doesn't matter. That is, we assume you'll use the server-wide shared MySQL instance instead. If you want to use the included private MySQL, then create another Custom Application (listening on port) application to reserve another port and then configure mysql to use that port instead.

This command starts Apache:

LAMP_PREFIX="$HOME/lamp"
$LAMP_PREFIX/apache2/scripts/ctl.sh start

You could then extract the application into the configured WEBAPP_DIR and serve it. You could also have used one of the other Application-specific Bitnami stacks to install the application code within the stack -- either approach is fine.

A final note is that we've explicitly disabled the mod_ssl functionality as part of the configuration. This is because your stack runs behind the server's front-end Nginx server and Nginx handles HTTPS encryption and decryption. More information is available in the documentation here.

Hope that helps!

permanent link
This answer is marked "community wiki".

answered 15 Oct '15, 08:19

ryans ♦♦
5.0k103760
accept rate: 43%

edited 15 Oct '15, 08:23

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×225
×5

question asked: 15 Oct '15, 07:56

question was seen: 2,412 times

last updated: 15 Oct '15, 08:23

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM