Felt that the discussion is somehow over, but the information is still very cryptic and you have to gather bits and pieces all around to make things work properly. So i decided to drop here my case-study with all the lessons learned and highlighting important aspects.
My case is that i use Google Cloud Compute Engine set-up using Bitnami. The primary purpose of the VM is to host several websites for my clients. The main takeaway from this is that for the price of shared hosting you get great infrastructure, reliable speed, resources boost and main bonus - SEO boost for the clients. But this is just intro.
What you need for this to work is:
- deploy LAMP stack on your virtual machine. Basically it's the standard package with Apache, MySQL and PHP. Follow these instructions.
- after LAMP is up and running, you need to understand the Bitnami LAMP modules, which are installed atop the LAMP stack. Modules are basically "containers" that encapsulate the application itself with most of its settings. Here i'd like to explain a bit how things work (at least from what i managed to understand):
- there's the app instance. It resides in the /opt/bitnami/apps folder. The website files are located in the htdocs folder and most app configurations are done inside the conf folder (we'll get back to it in Step 1 & 2 of domain set-up).
- there are the app tie-ins with the stack configured inside the /opt/bitnami/apache2/conf/bitnami folder. Ideally you never need to touch it, but you will use it permanently as soon as you will start bundling several domains to your account (we'll get back to it in Step 3 of domain set-up).
- there are stack level configurations, most notable of which is the php.ini. It is located in the folder /opt/bitnami/php/etc. It's mostly needed to tweak your php params (why have memory_limit 256k when you have 3.7 GB RAM?) and enable php extensions (e.g. APCu or memcache)
- Download the necessary module from here and upload it to your /home/bitnami/htdocs folder.
- Now this is very important part - you need to run the install correctly, so you won't need a huuuge clean-up routine afterwards. You need to set correct permissions and run the install with correct parameters:
- run the chmod +x bitnami-wordpress-4.5.3-1-module-linux-x64-installer.run to make the module executable
- run the install sudo /home/bitnami/htdocs/bitnami-wordpress-*-module-linux-x64-installer.run --wordpress_instance_name [instance name]. Notice the --wordpress_instance_name [instance name] - it's very important. It's the naming of your project, that will be used throughout the settings everywhere. Name it the way your website is called, e.g. --wordpress_instance_name awesomeblog. For instance, Joomla module does not have this parameter and it's pain to rename everything
- during the install there'll be several questions. The 2 that matter is where bitnami folder is (/opt/bitnami) and what's the password (the application password that you get in the bitnami console)
- After module is all set, you can run a post-install routine. In my case it meant the following:
- download your wp-config.php from under /opt/bitnami/apps/[instance name]/htdocs
- access through ssh: ssh -i [bitnami pem/ppk key] bitnami@[VM IP address]. There's a whole set of instructions, but i'm cutting it short for you.
- clear the folder: sudo rm -rf /opt/bitnami/apps/[instance name]/htdocs/*
- upload your website archive to /opt/bitnami/apps/[instance name]/htdocs (i used cyberduck, more details here) and unarchive it (using e.g Cyberduck or ssh)
- just in case, correct ownership: sudo chown -R bitnami:daemon /opt/bitnami/apps/[instance name]/htdocs
- ... and permissions: sudo chmod -R g+w /opt/bitnami/apps/[instance name]/htdocs
- import the database. Here's how to access phpMyAdmin. You should use the standard migration routine (and i mean Search-Replace-DB-master)
- edit the wp-config.php file. I prefer to overwrite back the wp-config.php i've downloaded at the beginning, but there may be important parameters, so combine them carefully.
- if you did everything properly, you can now access the backend by browsing to http://[server IP]/[instance name]/wp-config. If you get an error, you may want to check wp-config.php against the original one you've downloaded. You may have skipped something.
- inside the backend you should set up email support. Here's what you need to do. At the same time, i suggest you go for sendgrid instead of gmail, so look for these instructions.
Now i know it may seem complicated, but with a few tries you should be able to do it all under 5 minutes! In order to set up another instance simply go back to step 4 and give it another instance name. But, if my guess is correct, you may want to bundle several domains corresponding to your instances. This part is a bit trickier, yet still simple:
- First of all, go to your app instance folder. Make changes only to the wp-config.php and httpd-app.conf files according to these instructions. You can leave httpd-prefix.conf alone.
- Modify httpd-vhosts.conf. You can use the example inside it, or you can read this.
- Now go into this folder /opt/bitnami/apache2/conf/bitnami. We need to unbind our app prefix config and enable vhosts config. You need to edit 2 files:
- in the bitnami-apps-prefix.conf comment out the file related to your instance
- in the bitnami-apps-vhosts.conf include your instance vhosts config: Include "/opt/bitnami/apps/[instance name]/conf/httpd-vhosts.conf"
- Restart the servers: sudo /opt/bitnami/ctlscript.sh restart
Now you may need to adjust your DB again (Search-Replace-DB-master). What i did when i migrated my websites is simply skip doing any DB adjustments in Step 5 of the module installation. I had the domain bundled instead, so it was no longer necessary to adjust the DB.
As a side note, i must say that most of this routine applies to any LAMP module (e.g. Joomla or Drupal) and any combination of these (e.g. 2 WP, 1 Joomla, 3 Drupal). This question seems to pop-out again and again. What is worth mentioning is that other modules may not have --wordpress_instance_name parameter, meaning that you will have a standard app instance name (e.g. joomla) and you will have to rename everything manually. Consult my other message to see how. Keep in mind that i haven't mentioned there how to rename the database and the user. You can rename the database from the phpMyAdmin, but you'll have to use a MySQL init file to rename the user and change password. Look through these instructions to see how (you don't need to reset the root password; write the query that works for you), e.g.:
UPDATE mysql.user SET Password=PASSWORD('mynewpassword') WHERE User='Joomla';
RENAME USER 'joomla'@'localhost' TO 'awesomeblog'@'localhost';
Best of luck!
Edit: please notice that there are several things which are important to emphasize:
- We're talking about LAMP and Linux environment in the cloud. This doesn't mean that the logic does not apply to a local set-up and other OSes like MacOS or Windows or other stacks WAMP / MAMP. This means that command line instructions may differ a bit, you may not need ssh (duh...) or that some steps are redundant. The underlying logic and settings are identical or very similar.
- Regardless of your environment and OS, it's good to get a better understanding of Bitnami stacks and modules by looking into Step 2 of the module installation.
- Migration routine from one server to another differs from app to app (e.g. WP and Joomla), so before applying the guide to your website infrastructure try looking into the details of each process.
Edit 2: Today i managed to edit DB users, DB name, adjust privileges directly from phpMyAdmin. So there is no need to use SQL queries for that.