Thursday, June 7, 2012

Setting up CentOS 6.x server for Magento 1.6 on fresh a Rackspace server

I was asked to create a new server on Rackspace to run Magento CE. It was me who had to take the decisions for suitable OS and hardware configuration. I went for CentOS 6.2 simply because I had worked on it before and there was lot of help available on internet for that. Actually I'm not particularly a server guy. I'm a web specialist. So I had to rely on whatever help I can get from internet. I eventually found everything I wanted but I hoped I could get everything under one single link. I learned this in reasonably hard way so decided to put it up for non-server type guys (like me). I know that PHP programmers are often rotten by the deadline and mostly they don't have time to understand why they are doing what they are doing - as long as it works for them. So I will try to make it as easy and as "laymanish" as possible.

So my first choice was simple. CentOS 6.2. Simply because I had 'some' experience on it. The second choice - of hardware configuration - was under my domain. Magento requires minimum 256MB memory limit and they recommend minimum 512M server RAM. Don't go by this number because they simply don't work. In practice you HAVE to have minimum 1GB RAM of server and 512M for PHP runtime. Even that is not enough if you expect sizable traffic on your site. So I created a server for 2GB RAM with 1GB intended RAM for PHP specifically. The rest of the post will assume that you have a CentOS 6.x server set up with 2GB RAM.

Enough with the story? Let's get to the action!!

Step 1 - Install LAMP

1. Login to your server using PuTty or any other terminal tool

2. Open this URL in a browser - http://blog.svnlabs.com/installing-apache-mysql-php-in-centos-5-5-on-rackspace-cloud/ . Follow each and every step exactly. This will install Apache, MySql, PHP and PhpMyAdmin to your server. While you are installing PhpMyAdmin will get stuck on the console after showing some log. Don't worry. Just abort the process by typing Ctrl+C. The PhpMyAdmin would have been installed successfully by then. Then follow the rest of the instructions.

3. Since the Apache is installed you will obviously try to open the IP in the URL to see if it shows the Apache's default page. This won't work straight away!! This is because the port 80 is not open. Type following command to open the port 80.

iptables -I INPUT -p tcp --dport 80 -j ACCEPT

4. Since the PhpMyAdmin is installed you will try to open it in the browser. But it will require a password which you donot have. You have to set a password for root user of MySql to get in. For that run the following command.

mysqladmin -u root password NEWPASSWORD

For more information about changing the MySql password visit this link -http://www.cyberciti.biz/faq/mysql-change-root-password/

5. Php-mcrypt. is required for Magento. To install php-mcrypt you will have to first update the EPEL on your CentOS. By default php-mcrypt is not available in the centOS's repository so you have to get the extended package. In short, run the following command.

rpm -Uvh http://mirror.overthewire.com.au/pub/epel/6/i386/epel-release-6-7.noarch.rpm

NOTE: The epel releases' version keep changing. So in future the above link may not work. Go to http://mirror.overthewire.com.au/pub/epel/6/i386/ to find out the appropriate release. Copy the URL of that location and add to above command. For more information visit this link http://www.ctkn.net/tag/enable-epel-centos-6/

6. Now you can install php-mcrypt by running the command - yum install php-mcrypt

7. You need to install the SOAP as well

yum install php-soap

8. Open the /etc/httpd/conf/httpd.conf file and find for "AllowOverride". You will find this in two places. On both it would be set to "None". Change both setting to "All".

9. Run this command to set Mysqld service to auto start on reboot

chkconfig –-level 2345 mysqld on

Step 2 - Install Sendmail


1. By default the sendmail is not installed. So Magento will not send any system mails. You will have to install Sendmail on the server. Command...

yum install sendmail

Then follow the instructions provided in this link http://www.unixmen.com/configuring-
sendmail-smtp-server-on-centos-a-scientific-linux/

2. SMTP requires the port 25 to be open. Run following command to open it.

iptables -I INPUT -p tcp --dport 25 -j ACCEPT


Step 3 - Memory Limit

Is your Magento running slow? It would be definitely. The problem is the memory. You have got a server of 2 GB RAM (as per aforementioned spec) but your Magento is not utilizing it -  as yet. For that follow the below steps.

1. Increase the memory limit to 1GB in your php.ini file. This file is by default located in /etc/php.ini. And then run the phpinfo file. See if the master value changed to 1GB? Don't worry about the local value as it is coming from the .htaccess file. If master value is changed then you are good to move on to the next step.

2. Change the memory limit from .htaccess file. This will change the local value of memory limit in the phpinfo. Until this is done the Magento will not use anymore memory than the default 256M. Now check the site again. It would be significantly faster.

Step 4 - Install SSL

You can simply follow the instructions given in this link http://www.akadia.com/services/ssh_test_certificate.html or go by the following steps.

1. Generate the CSR file. Reference this link for more info http://www.rackspace.com/knowledge_center/index.php/Generate_a_CSR

2. Send this CSR file to the site owner and ask him to obtain a CRT file using this CSR file from a certificate authority. 

3. Once you have the CRT file use it to install the SSL on your server. For more info refer this link http://www.rackspace.com/knowledge_center/index.php/Installing_an_SSL_certificate

4. Run following command to open port 443 (for HTTPS) 
iptables -I INPUT -p tcp --dport 443 -j ACCEPT

After all these is done, install your Magento in the document root (by default in /var/www/html/). Your basic Magento should be running fine after performing all these steps. 

Good Luck!! You need it with Magento ... :)

No comments:

Post a Comment