Engine23
blogBannerImage
By Engine23

Setting up Amazon EC2 Ubuntu 12.10 server for Magneto using NFS

This is all the steps and details i used to create an instance of a web server to be used for a Magento Website.

1 - Start a m3.xlarge instance

2 - Make sure its part of a security group that has Ports 80, 443 open to all 0.0.0.0/0

3 - Add a SSH port execption for your IP

4 - Assign an Elastic IP to each new instance

5 - Get the ssh details from Connect Instance in the Amazon control panel and ssh into the device(s)

6- Change the date/time of the server

sudo dpkg-reconfigure tzdata

7 - Setup postfix

sudo apt-get install postfix

8 - Add all the packages needed to have magento run via command line

  1. sudo apt-get upgrade
  2. sudo apt-get install php5 php5-curl php5-gd php5-mcrypt php5-mysql -y
  3. Get the folder that will be our site root ready
    sudo mkdir /var/www/somename
    Since we are going to be using NFS we need to make the owner ubuntu
    sudo chown -R ubuntu /var/www/somename/
    Change the group to ubuntu
    sudo chgrp -R ubuntu /var/www/somename/
  4. Install mysql just to test the connection to the remote database
    sudo apt-get install mysql-server -y
    Once its installed check to see if you can get to the database via command line
    mysql -h 10.10.10.10 -u yourUserName -p'YourPassWordGoesHere'
  5. Mod Rewrite is required to make Magento work the way its supposed to
    sudo a2enmod rewrite
    Restart Apache
    sudo service apache2 restart
  6. Install Apc
    sudo apt-get install php-apc
    Restart Apache to begin using Apc
    sudo apache2ctl graceful
    
  7. Get Memcached
    sudo apt-get install mysql-server php5-mysql php5 php5-memcache -y
    Install Memcached
    sudo apt-get install memcached
  8. Setup the main site configuration
    sudo vim /etc/apache2/sites-enabled/000-default
    Here is what the file might look like

    <VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/somename
    <Directory />
      Options All
      AllowOverride All
    </Directory>
    <Directory /var/www/somename/>
      Options All
      AllowOverride All
      Order allow,deny
      allow from all
    </Directory>

      ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
      AllowOverride None
      Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
      Order allow,deny
      Allow from all
    </Directory>

      ErrorLog ${APACHE_LOG_DIR}/somename-error.log

      # Possible values include: debug, info, notice, warn, error, crit,
      # alert, emerg.
      LogLevel warn

      CustomLog ${APACHE_LOG_DIR}/somename-access.log combined
    </VirtualHost>

  9. Allow for SSL
    sudo a2enmod ssl
    Now Restart Apache
    service apache2 restart
    Now configure Apache2 for ssl
    sudo a2ensite default-ssl
    You have to reload apache to get things ready
    service apache2 reload
    You should now be ready to edit/modify the default file. There is 4 ( 3 certs and one private key ) files you need to be on the server and in the right place Certs
    1. intermediate.crt
    2. naturehills.com.ca
    3. naturehills.com.crt
    Private Key
    1. naturehills.com.key
    These need to go into some specific places to make the code updates easier. The certs need to go into /etc/ssl/certs/ The Private key goes into /etc/ssl/private/ You should use rsync to get them into the right location. Once thats done you can edit the file needed that is looking for these files. Lets get started by editing the /etc/apache2/sites-enabled/default-ssl
    sudo vim /etc/apache2/sites-enabled/default-ssl
    This is what the file /etc/apache2/sites-enabled/default-ssl may look like

    <IfModule mod_ssl.c>
    <VirtualHost _default_:443>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/somename
    <Directory />
    Options All
    AllowOverride All
    </Directory>
    <Directory /var/www/somename/>
    Options All
    AllowOverride All
    Order allow,deny
    allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/somename-ssl-error.log
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/somename-ssl_access.log combined

    SSLEngine on

    SSLCertificateKeyFile /etc/ssl/private/somename.com.key
    SSLCertificateFile /etc/ssl/certs/somename.com.crt
    SSLCACertificateFile /etc/ssl/certs/somename.com.ca
    SSLCACertificateFile /etc/ssl/certs/intermediate.crt

    <Directory /usr/lib/cgi-bin>
    SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-6]" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0
    # MSIE 7 and newer should be able to use keepalive
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

    </VirtualHost>
    </IfModule>

    Now restart apache to see if there are any errors
    sudo service apache2 restart
  10. Install PHP Pear
    sudo apt-get install php-pear
  11. Get the build essential to install memcached
    sudo apt-get install build-essential -y
  12. We need this to install memcached
    sudo apt-get install php5-dev -y
  13. Now we can use PECL to install memcached
    sudo pecl install memcache
  14. This will add the memcached ini First change to root
    sudo -i
    Now add the line to a new ini file
    echo "extension=memcache.so" > /etc/php5/conf.d/memcache.ini
    
  15. Now reload apache, yet a different way
    /etc/init.d/apache2 reload 
  16. Confirm that memcached is running/working
    ps aux | grep memcache
    Or you can view the details this way
    echo "stats settings" | nc localhost 11211
  17. Now lets get the NFS loaded You will have to adjust the NFS server etc/export and add another entry
     /var/nfs 59.299.199.198(rw,sync,no_subtree_check) 59.299.199.199(rw,sync,no_subtree_check)
    Client setup:
    sudo apt-get install nfs-common -y
    The client needs the same changes to /etc/default/nfs-common to connect to an NFSv4 server. In /etc/default/nfs-common we set:
     NEED_IDMAPD=yes NEED_GSSD=no # no is default
    You can test to see if the drive your trying to mount is there:
    showmount -e 59.99.99.197
    You should see some thing like:
    Export list for 54.235.147.98:
    /var/nfs 59.299.199.198,59.299.199.199
    Mount the NFS drive
    sudo mount -t nfs4 -o proto=tcp,port=2049 59.99.99.197:/var/nfs/ /var/www/somename/
    To make sure that the module is loaded at each boot, simply add nfs on the last line of /etc/modules. We can also mount an exported subtree with:
    mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/users /home/users
    To save us from retyping this after every reboot we add the following line to /etc/fstab:
    59.99.99.197:/var/nfs /var/www/somename nfs4 _netdev,auto 0 0
  18. Add Iocube
     cd /usr/local
    sudo wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
    sudo tar xzf ioncube_loaders_lin_x86-64.tar.gz 
    Make sure its loaded by apache
    echo "zend_extension=/usr/local/ioncube/ioncube_loader_lin_5.4.so" | sudo tee /etc/php5/conf.d/ioncube.ini
    Restart apache
    sudo /etc/init.d/apache2 restart
    To test if ionCube loader is installed you can check the output of phpinfo(); it should contain the line ionCube Loader under Additional Modules. You can also copy the file /usr/local/ioncube/loader-wizard.php to your public web directory and run it via your web browser. It will run some additional tests and tell you if there are still any problems.
  19. Final checks
    If for some reason the site does not load with the new server running it may be comlaining about a mismatch in server name
    Add this to the default_ssl 
    ServerName www.naturehills.com