Setting up a Magento VM (maintenance purpose)

A client recently asked me to move their Magento to another host. A problem arise since the new host do not provide shell access thus maintaining Magento patches became an issue.

I found and forked this from
Credit where credit is due.
https://www.nerdoncoffee.com/uncategorized/setting-up-a-magento-vm-and-allowing-remote-access/

Grab the VMDK from here

https://bitnami.com/stack/magento/virtual-machine
  • Convert to a qcow2 image

    qemu-img convert -f vmdk -O qcow2 bitnami-magento-1.9.1.0-0-ubuntu-14.04.vmdk magento.qcow2

  • Create a vm and set that is the hard disk image

  • Change all interfaces to virtio 14.04 has paravirtual drivers already installed so is good to go. Why ? Because it will speed up slow as Magento
  • Create a bridge
  • Follow the wiki

    https://wiki.archlinux.org/index.php/Bridge_with_netctl

  • Add your interfaces as appropriate e.g

    Description=”Example Bridge connection”
    Interface=br0
    Connection=bridge
    BindsToInterfaces=(eth0 eth1 tap0 enp2s0)
    IP=dhcp

  • Start it and enable it at boot

    sudo netctl start bridge
    sudo netctl enable bridge

  • Change the Nic to use the new bridge (br0) as the Network source

  • Start the VM
  • Configure whatever you like on your vm
    you could use port forwarding, port triggering, dmz, vpn, ssh etc…

As I don’t really care about this little vm (its just for dev purposes) I threw it in the DMZ zone (make sure it has a static IP – I just did a dhcp reservation and set the mac of the vnic)

  • Adding a DNS A record so you don’t have to remember the ip
    log in to your dns registrar (look up terminology) – I use cloudflare so I just added it in there for this blog as magento.nerdoncoffee.com)

  • Modify your vm
    in /opt/bitnami/apps/magento/conf/htaccess.conf php_value memory_limit 512M

  • Update Apache2 on your vm
    [text] #

ServerName magento.example.com

ServerAlias www.magento.example.com

DocumentRoot “/opt/bitnami/apps/magento/htdocs”

#

Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”

#
ServerName magento.nerdoncoffee.com
ServerAlias magento.nerdoncoffee.com www.magento.nerdoncoffee.com
DocumentRoot “/opt/bitnami/apps/magento/htdocs”
Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”

#

ServerName magento.example.com

ServerAlias www.magento.example.com

DocumentRoot “/opt/bitnami/apps/magento/htdocs”

SSLEngine on

SSLCertificateFile “/opt/bitnami/apps/magento/conf/certs/server.crt”

SSLCertificateKeyFile “/opt/bitnami/apps/magento/conf/certs/server.key”

#

Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”

#

ServerName magento.nerdoncoffee.com
ServerAlias magento.nerdoncoffee.com www.magento.nerdoncoffee.com
DocumentRoot “/opt/bitnami/apps/magento/htdocs”
SSLEngine on
SSLCertificateFile “/opt/bitnami/apps/magento/conf/certs/server.crt”
SSLCertificateKeyFile “/opt/bitnami/apps/magento/conf/certs/server.key”

Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”
[/text] OR
[text] ServerName magento.nerdoncoffee.com
ServerAlias magento.nerdoncoffee.com
DocumentRoot “/opt/bitnami/apps/magento/htdocs”
Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”

#

ServerName magento.example.com

ServerAlias www.magento.example.com

DocumentRoot “/opt/bitnami/apps/magento/htdocs”

SSLEngine on

SSLCertificateFile “/opt/bitnami/apps/magento/conf/certs/server.crt”

SSLCertificateKeyFile “/opt/bitnami/apps/magento/conf/certs/server.key”

#

Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”

#
ServerName magento.nerdoncoffee.com
ServerAlias magento.nerdoncoffee.com
DocumentRoot “/opt/bitnami/apps/magento/htdocs”
SSLEngine on
SSLCertificateFile “/opt/bitnami/apps/magento/conf/certs/server.crt”
SSLCertificateKeyFile “/opt/bitnami/apps/magento/conf/certs/server.key”

Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”
[/text]

nano /opt/bitnami/apps/magento/conf/htaccess.conf

at the bottom in the directories node

[text] SetEnvIf Host www.magento.nerdoncoffee.com MAGE_RUN_CODE=magento.nerdoncoffee.com
SetEnvIf Host www.magento.nerdoncoffee.com MAGE_RUN_TYPE=website
SetEnvIf Host ^magento.nerdoncoffee.com MAGE_RUN_CODE=magento.nerdoncoffee.com
SetEnvIf Host ^magento.nerdoncoffee.com MAGE_RUN_TYPE=website
[/text] Now uncomment the following file in /opt/bitnami/apps/magento/conf/htaccess.conf
[text]

you can put here your magento root folder

path relative to web root

RewriteBase /magento/
[/text] Restart apache in your vm

sudo /opt/bitnami/ctlscript.sh restart apache

References
* https://bitnami.com/stack/magento/virtual-machine
* https://wiki.archlinux.org/index.php/Bridge_with_netctl
* https://wiki.bitnami.com/Virtual_Appliances_Quick_Start_Guide
* https://wiki.bitnami.com/Virtual_Appliances_Quick_Start_Guide#How_to_enable_sshd.3f

Magento development instance

I had to help a customer setting up a local instance of their Magento webshop.

Credit where credit is due.
Forked from http://wrightcreativelabs.com/create-a-test-instance-of-a-magento-store/

When the production site is in a state that is ready to copy, here are the steps to take:

  1. Decide on the location for the development instance files.  In this case, we have a separate domain, mytestserver.net, and a subdirectory for each test instance.
    [bash] cd /home/mytestserver/public_html/
    mkdir newtestsite
    [/bash]
  2. Copy the production server Magento files to the new test server subdirectory.
    [bash] cp -r /home/myprodserver/public_html/* /home/mytestserver/public_html/newtestsite/
    cp /home/myprodserver/public_html/.htaccess /home/mytestserver/public_html/newtestsite/
    [/bash]
  3. Create a new empty database on the testserver.
  4. Create a data dump from the production database. The mySQL command is noted below. Replace the all caps items with your information.
    [bash]mysqldump -h DBHOST -u DBUSER -pDBPASS DBNAME > /home/backup/data.sql[/bash]
  5. Import the data dump previously created into the empty database on the test server. Replace the all caps items with the credentials for your new test server database.
    [bash]mysql -h DBHOST -u DBUSER -pDBPASS DBNAME < /home/backup/data.sql[/bash]
  6. Next you’ll need to make some edits. In the test database, go to the core_config_data table and change the values of web/unsecure/base_url and web/secure/base_url to the test server url. E.g. http://mytestserver.us/newtestsite/. If you do not use an SSL certificate on the development servers, then the value for the unsecure and secure urls are the same. You can make the edits using phpMyAdmin. Below is example SQL for the updates.
    [sql]UPDATE core_config_data SET value="http://mytestserver.us/newtestsite/" WHERE path=’web/secure/base_url’;
    UPDATE core_config_data SET value="http://mytestserver.us/newtestsite/" WHERE path=’web/unsecure/base_url’;[/sql]
  7. Clear cache files that were copied over from the production site.
    [bash]cd /home/mytestserver/public_html/newtestsite
    rm -rf var/*[/bash]
  8. Edit the local.xml file (app/etc/local.xml). Change the database values to point to the new test database host, database name, user, and password.  If you are using a php cache such as apc, also remove or comment out the lines that use it. It is preferable not to have caching turned on in a development environment so all changes are reflected immediately.
  9. You should now be able to navigate to the new test instance’s frontend and backend.
  10. Go to the backend to make some further changes to the settings (e.g. http://mytestserver.net/newtestsite/admin/).  The login is the same as the production instance. Below are some of the items you may want to set differently for the development version of the site.
    • Turn on the store demo notice.  System > Configuration > Design > HTML Head > Display Demo Store Notice.
    • Change email addresses used.  For testing, you probably want emails to go to you or other developer, rather than the store owner.
      System > Configuration > Store Email Addresses and Sales Emails.
    • Turn off production payment methods.  For example, you may want to either disable Paypal entirely, or put it in Sandbox mode.  Likewise, you may want to turn on Check / Money Order, or other quick and easy payment method for testing order functionality.
    • Turn off SSL.
      System > Configuration > General > Web > Secure > Use Secure URLs in Frontend.
    • Turn off Google Analytics. 
      System > Configuration > Google API > Google Analytics.
    • Turn off Javascript file merging. 
      System > Configuration > Advanced > Developer > Javascript Settings.
    • Also turn off CSS file merging if it was used.
      System > Configuration > Advanced > Developer >
    • Turn off Caching. 
      System > Cache > Select All, then Disable.  Also Flush Javascript/CSS Cache.
    • Rebuild indices. 
      System > Index Management > Select all, then Rebuild.
    • You may also want to change the admin login or other accounts. 
      System > Permissions > Users.
  11. Also check your .htaccess file on the test instance to make sure that any production-only rewrite rules are removed or commented out.  Its also a good idea to password protect the directory so that only allowed users have access.  Below is an example of the code to add to your .htaccess file after you have set up the password (this is usually an option in your hosting control panel).
    [plain title=”.htaccess”] AuthName "Protected Area"
    AuthType Basic
    AuthUserFile /home/mytestserver/.htpasswds/public_html/newtestsite/passwd
    Require valid-user
    [/plain]
  12. Edit your robots.txt file to keep search engine robots away.
    [plain title=”robots.txt”] User-agent: *
    Disallow: /
    [/plain]
  13. That’s it!  You now have a copy of your production Magento store ready for development and testing.