Archive for the 'Server' Category

magento 500 error after fresh install

I’ve just started to learn magento and I had a problem with my install always giving a 500 error, even after following the install instructions. Correct permission, all apache and php requirements met, I kept getting 500 errors on every page. I finally found out why. Magento doesn’t allow you to use localhost as your domain. I think it was something about cookies not working correctly under the localhost domain. The solution was simple: add another alias for localhost. I use a Mac so I went into /etc/hosts and added this line:

127.0.0.1 local.dev.com

The domain could be anything, I just chose local.dev.com since it’s pretty generic and I can use it again for any other projects that have a similar problem.

mysql 5.5 skip innodb

In MySQL 5.5, it seems the skip-innodb option was removed so trying to boot MySQL with that option just makes it fail. Skipping InnoDB can save quite a lot of RAM and on lower end systems, this can be very useful. Here’s the new equivalent to skip-innodb in MySQL 5.5:

ignore_builtin_innodb
default_storage_engine=MyISAM

rvm + capistrano + gitosis install guide

Even though the mentioned 3 tools are the de facto that everyone is using, it’s actually a huge pain in the ass to set up for the first time. One could easily spend a few days just trying to troubleshoot any problems that come up, and there are so many potential problems that even Google doesn’t have all the answers in plain sight.

First, install git and gitosis. I run debian so you’ll have to find the equivalent commands on your version of linux, but for debian/ubuntu you can install those using:

aptitude install git-core gitosis curl

For CentOS you can install git with yum using

yum install git-core

But for gitosis, you’ll have to install it via the python install or adding the REPOs referenced in this post.

Curl will be used to install RVM.

Now for RVM, run this command:
bash << (curl -s https://rvm.beginrescueend.com/install/rvm)
If you run that command as root, it will do a system install. Otherwise, it will do a user install (RVM will only work for that user). It's up to you which one you want to do, but I usually do a system install. After the install, you'll need to add this to /etc/profile or the .bash_profile of every user you want to use RVM:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

The above code is for a user install. If you're doing a system install, replace $HOME/.rvm/scripts/rvm with /usr/local/bin/rvm.

Now run:

source /etc/profile

or

source .bash_profile

depending on where you added that code. Once it's installed, install your preferred version of ruby. I use REE, so I do

rvm install ree

Once you have your version of ruby running, you may want to create separate gemsets. If so, use this command:

rvm gemset create yourgemset

If you don't use a gemset, it will just use the default gemset which is no gemset. On your local machine, install capistrano with this command:

gem install capistrano

Go to the root of your rails application, and type:

capify .

This will generate a Capfile and, more importantly, a deploy.rb inside your config folder. This deploy.rb is the heart of how you will deploy applications now. I won't go into a sample cap file since there are quite a bit on the web, but I think it's good to mention that capistrano is just a tool that runs commands for you, instead of you having to go into the machine and do them yourself. You can create capistrano tasks which are just basically commands you'd type when you're SSHed into a machine, only here you can run them easily by doing cap namespace:task. That's all there is to it.

To get RVM and capistrano working, check out my earlier post about it.

Now, gitosis is kind of a bitch to work with if you haven’t used it before. I find this tutorial to be a very valuable resource when working with gitosis, especially the initial setup. However, one thing to add to that tutorial that YOU MUST DO is SSH into your REMOTE machine as the user that will be used to deploy the application. You must generate an SSH key for that user, and add it to the gitosis-admin keydir and basically add that user as a gitosis user in addition to yourself. This is needed since capistrano will use that user to deploy and get the code from gitosis.

After all this is working, you should have a basic setup with rvm + capistrano + gitosis working. It’s real tough to install the first time, but after a while you get used to it. If anyone finds anything to add to this tutorial, I’d be more than happy to update this post!

installing iis 6 on windows 2003 server

I don’t know about anyone else, but this task was one of the most difficult server tasks I’ve ever had to do. Installing IIS on Windows 2008 is a lot easier, but in 2003 it’s akin to banging your head against a wall for a day or so. The thing is, you need so much stuff just to install IIS it’s hard to know where to get everything. I’m using Windows 2003 Server R2 SP2, but the installation requires files from the REGULAR, NOT R2 version! So here’s how I did it:

Install SP2 EVEN IF YOU ALREADY HAVE IT INSTALLED! I just downloaded it from Microsoft again and installed it. Next, I downloaded the admin pack (Located under system32 as adminpak.msi, or download from here: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=16770). Then I loaded the OLDER REGULAR version of Windows 2003 Server with Alcohol 52%, pointed to the i386 directory, and it installed.

Ultimate Hosting Server – Virtualmin on Debian Squeeze

I like to provide hosting to friends and such, so having a control panel for them is very important. However, at the same time, I’m too cheap to buy a DirectAdmin or cPanel license. After a lot of researching and trying different panels, it’s my personal opinion that Virtualmin is the best free hosting control panel out there at the moment. Although it isn’t as flashy and aesthetically pleasing as commercial control panels, it provides many of the same features (except really good script installers) and I feel that it even gives more control to both the admin and the users. Plus, it doesn’t dictate the versions or setups of the software, so you can basically roll with anything you want.

I chose to use Debian over CentOS since Debian has more up to date packages and I’m more experienced with Debian. CentOS is really good for stability, but I’m going to be hosting my own content and friend’s content so it won’t be anything that’s really mission critical.

In this tutorial, I’ll be teaching you how to install a VPS or dedicated server with Virtualmin running Apache2 with MPM worker, PHP5 on FCGI, MySQL5, RoR with RVM, and Varnish. I believe this setup to be very good on performance and resources, but you’ll need a VPS with at least 1GB RAM. 512MB is really pushing it and you probably wouldn’t be able to run Varnish at the start, and a very limited number of websites.

It’s highly recommended that you start this guide with a fresh install of Debian Squeeze. Installing Virtualmin on an existing system with a web stack will probably cause a lot of problems.

Once you’ve installed, update the system:

apt-get update

I like to aptitude instead of apt-get, so this command is optional:

apt-get install aptitude

From now on I’ll be using aptitude, but you can substitute it for apt-get if you want. Next, install Virtualmin by downloading and running the script:

wget http://software.virtualmin.com/gpl/scripts/install.sh

sh install.sh

It’ll prompt you about installing Virtualmin and just press ‘y’ and enter, then it’ll install. The install itself will take a while so go get some coffee or watch a show while it installs. After it’s done, you can login to your site from the web panel located at https://your-hostname:10000, or put your IP if you didn’t configure your hostname yet.

You won’t need to login yet since we’re going to be installing and configuring some more stuff server-side, but go ahead and login if you want. After Virtualmin is nice and cozy on your server, go ahead and install some important tools that you’ll need not only for this tutorial, but later on for anything else you’ll want to build or compile:

aptitude install build-essential autoconf automake

Apache2 will come with prefork as the default, so we’ll be uninstalling the prefork module and installing the mpm module. This can easily be done with the following command:

aptitude install apache2-mpm-worker

This should prompt you about uninstalling prefork, and just agree to the solution. Since mod_php is only for prefork, you’ll need to use fcgi now to serve PHP. PHP CGI should already be installed but in case it’s not, one of these commands should do the trick:

aptitude install php5-cgi

or

aptitude install php-cgi

You need the actions module enabled in Apache and it should be enabled by default, but in case it’s not, here’s the command:

a2enmod actions

After that’s done, go into /etc/apache2/conf.d/ and add a new file called php-cgi.conf or whatever you want, then add the following into this new file:

ScriptAlias /local-bin /usr/bin
AddHandler application/x-httpd-php5 php
Action application/x-httpd-php5 /local-bin/php-cgi

Save and exit, then restart apache with

service apache2 restart

Next, you’ll install RVM system wide install by running this command as root, or using sudo. IT’S VERY IMPORTANT THAT YOU RUN THIS AS ROOT OR SUDO! If not, it will install the user version of RVM instead of the system wide, but if that’s what you want, then go ahead:

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

Now go into /etc/profile (file) and add the following:

[[ -s "/usr/local/bin/rvm" ]] && . "/usr/local/bin/rvm"  # Load RVM into a shell session *as a function*

NOTE!: You might need to add the line above to each individual user’s .bash_profile or whatever equivalent your shell has.

RVM should be installed now. Install Ruby Enterprise Edition with RVM by running these commands:

aptitude install

rvm install ree

We want REE to be the default interpretor, so the following command will do that:

rvm –default use ree

Almost done! All we have to do is install varnish. Run these commands to install Varnish:

sudo curl http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add -

sudo echo “deb http://repo.varnish-cache.org/debian/ $(lsb_release -s -c) varnish-2.1″ >> /etc/apt/sources.list

aptitude update

aptitude install varnish

Now open the /etc/default/varnish file and find the uncommented DAEMON_OPS line. You’ll see 6081; change it to 80. A few lines below, look for “default.vcl”. Change it to something else, I used virt.vcl. Save and exit. Now create a new file in /etc/varnish/ named after what you changed default.vcl to, so for me I made a file /etc/varnish/virt.vcl. Paste the following contents:

## Redirect requests to Apache, running on port 8000 on localhost
backend apache {
        .host = "127.0.0.1";
        .port = "8000";
}
## Fetch
sub vcl_fetch {
		## Remove the X-Forwarded-For header if it exists.
        remove req.http.X-Forwarded-For;

		## insert the client IP address as X-Forwarded-For. This is the normal IP address of the user.
        set    req.http.X-Forwarded-For = req.http.rlnclientipaddr;
		## Added security, the "w00tw00t" attacks are pretty annoying so lets block it before it reaches our webserver
        if (req.url ~ "^/w00tw00t") {
                error 403 "Not permitted";
        }
		## Deliver the content
        return(deliver);
}

## Deliver
sub vcl_deliver {
		## We'll be hiding some headers added by Varnish. We want to make sure people are not seeing we're using Varnish.
              ## Since we're not caching (yet), why bother telling people we use it?
        remove resp.http.X-Varnish;
        remove resp.http.Via;
        remove resp.http.Age;

		## We'd like to hide the X-Powered-By headers. Nobody has to know we can run PHP and have version xyz of it.
        remove resp.http.X-Powered-By;
}

You can change the port to whatever you want, I used 8080. However, you must remember this port since we’re going to have to change some Apache configs to listen on that new port since Varnish will be listening on port 80. Save and exit. Open up /etc/apache2/ports.conf and find where 80 is, and change it to the port in the previous file. For me it was 8080, so I changed all 80 to 8080. Save and exit. Next, run this command:

aptitude install libapache2-mod-rpaf

Then restart Apache with

service apache2 restart

Now that everything is installed, we still need configure a few things, such as RVM. The system wide install of RVM requires users to be in a group called “rvm” in order to use it, so go ahead and log into the Virtualmin control panel which is usually located at https://hostname:10000, where hostname is your hostname. After you login, look at the side menu and find “Server Settings”, and click on it. This will open a new menu, and find the second item called “Server Templates” and click on it.  The server templates are very useful for customizing your Virtualmin experience, so remember it! Now, you should see 2 templates already made for you: “Default Settings”, and “Settings For Sub-Servers”. Click on “Default Settings”. You should now see a page with a drop down menu near the top. Click the drop down menu and find the second item called “Administration User”. This should take to you a new page. If it doesn’t, click the “Change” button with “Administration User” selected in the drop down menu. Now, look for the item “Add domain owners to secondary group” and select “Selected group”. A new window should open up displaying all the groups. Find “rvm” and select it, then click the “Save” button.

Now you’re done! Everything should be working correctly assuming you didn’t mess up somewhere. Enjoy your new server! If I missed anything anywhere, please don’t hesitate to comment!

References:

http://www.howtoforge.com/putting-varnish-in-front-of-apache-on-ubuntu-debian

http://library.linode.com/web-servers/apache/php-cgi/debian-5-lenny

virtualmin centos awstats not found error

I got a really weird error when doing a fresh install of Virtualmin on a basically fresh install of CentOS 5.5. After installing Virtualmin, it told me that AwStats couldn’t be found, but when I checked the packages it was installed. Basically, this boiled down to having unofficial repos. What I mean is, after I installed CentOS I immediately added the 3 repos I listed in a previous post and updated. Somehow, the awstats installed didn’t get installed into a place that Virtualmin looks for it.

I tested this and installed another fresh CentOS 5.5 and updated without adding any other repos. Sure enough, this problem disappeared.

CentOS Repositories

CentOS is a very stable distro and because of that, it lacks really up to date packages. Here are some repos that will provide more recently up to date and extra packages:

Utter Ramblings – Up to date LAMP

EPEL – Fedora Packages ported to RHL

DAG – Extra Packages

Debian GPG error

When trying to do an aptitude update in Debian on a fresh install of lenny, I got this error:
W: GPG error: http://ftp.de.debian.org lenny/updates Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY xxx
W: You may want to run apt-get update to correct these problems
It can easily be fixed by running the following commands:
gpg --keyserver keys.gnupg.net --recv-key xxx
gpg -a --export xxx | sudo apt-key add -

Of course, replace xxx with your own key.

E: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable)

So sometimes when you’re using apt-get or aptitude (I use aptitude) and you’re updating a large amount of packages or just large packages, you’ll just sit there and forget about it and somehow loose connection to your server. When you go back in to complete the upgrade process, you get this error: E: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable). To solve this, run the following:

killall aptitude (or apt-get)

dpkg –configure -a

Then run aptitude upgrade to finish up!

rvm and capistrano

RVM is a really cool tool that allows users to have multiple Ruby installs. I suggest using it as its very useful, just like having a package manager for Ruby versions. When I switched to rvm, I was having errors on my production server that some Rails commands like bundle couldn’t be found. Long story short, here’s a link to the solution:

SOLUTION!

In case the link is down, here’s a brief overview:

After installing RVM System Wide (you can find this easily in Google), add this to your default bash profiles:

[[ -s '/usr/local/bin/rvm' ]] && source '/usr/local/bin/rvm'

Then in Capistrano, you must add this in your deploy.rb:

require ‘rvm/capistrano’
set :rvm_ruby_string, ‘some-ruby’ # Defaults to ‘default’

Also, you MUST HAVE RVM ON YOUR LOCAL MACHINE!

EDIT: Just in case, you can also install the rvm gem using gem install rvm.