Setup 128MB VPS for website using Centos 6

Posted by Nurasto | December 14, 2011 | Computer and Tech | 5 Comments

Installing nginx, php, mysql on Centos 6 is tricky business. Unlike Debian or Ubuntu, some package not available on it’s default repository. I tend to use Centos or Debian as server, but this time I choose to install Centos on my 128MB VPS. My consideration because of OpenVZ which is different from XEN which has it’s own kernel space and iptables. It’s recommended to use same Linux Distro on OpenVZ while XEN you could use any linux flavor regardless the container. Maybe I am out of date about OpenVZ improvement but that’s what I know.

I want to use latest version of LAMP LNMP pack. As we all know, Centos is an enterprise grade linux based operating system which means the updates will not as fast as bleeding edge distro such as Fedora Core. The situation is quite same like Debian vs Ubuntu*. We will use use third party repository to install software we need, so we don’t need to compile every software on production server. I will use EPEL and Remi’s repository in this article.

Disclaimer: I am not responsible for anything happen with your production server/VPS, you may test this article on your VirtualBox before applying into your VPS.

Before we start, you need to login as root or escalate to be root using su –

Get RPM from EPEL & Remi

Run this command one by one in your root home.

wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

Update

yum update

Installing MySQL

yum install mysql mysql-server

Configuring MySQL

We need to make sure that mysql runs without innodb engine, so we need to adjust my.cnf. This step would be tricky and we will use default small configuration. Run this command one by one.

cp /etc/my.cnf /etc/my.cnf.bak
cp /usr/share/mysql/my-small.cnf /etc/my.cnf

There you go, we have copied the small configuration for mysql. Now, we need to tweak our my.cnf configuration because we need to skip innodb. You could use vi to edit the file.

vi /etc/my.cnf

We need to add these two following line under [mysqld]

default-storage-engine = myisam
skip-innodb

After you done just press : (double colon) and x, it will save your changes and exit from vi editor. Now you can start the mysql server

/etc/init.d/mysqld start

The initial start will create mysql table. Hopefully, it will create smoothly. You can run this command to makes mysql start on your VPS.

chkconfig mysqld on

It’s recommended to run mysql_secure_installation after mysql server installation.

Installing PHP and PHP-FPM

yum install php-fpm php-cli php-mysql php-pear php-apc

Now we need to make PHP-FPM running in our VPS. Run these command one by one.

/etc/init.d/php-fpm start
chkconfig php-fpm on

Installing Nginx

yum install nginx

Now, we need to adjust our nginx to be able to run php in our VPS.  Run this command

vi /etc/nginx/nginx.conf

Find these line in comment. Uncomment it then change as follows

 location ~ \.php$ {
            root           /usr/share/nginx/html;
           fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

index.php is not yet set as root document. So, we need to add index.php in same config file.

  location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm index.php;
        }

You see, I am adding index.php in the end of the index configuration. Now the last step is restarting nginx and make it run at the start up.

/etc/init.d/nginx start
chkconfig nginx on

When server start, nginx will have delay for about a minute then it will run. We need to make sure that our configuration to LNMP is good. Run this command

echo '<?php phpinfo();' > /usr/share/nginx/html/info.php

Try to connect to your IP, in this case I will use localhost ip, http://127.0.0.1/info.php. If you see php information then your configuration to Nginx and PHP are good.

One last thing before I forgot to write, if you have permission problem with wordpress when updating or installing plugin you need to change default php-fpm user from apache to nginx.

vi /etc/php-fpm.d/www.conf

Find user and group whose own the php-fpm there then change to nginx. That’s it.

So far, I have problem with MySQL and have nightmare tweaking MySQL in such low end box, because 128MB VPS will hit swap for database driven website. In the end, I decided to upgrade my VPS to 256MB plan and the tension is gone. Booyah.

Thank you for reading. Please don’t hesitate to give feedback, suggestions or comment.

*If you have output from cat /etc/debian_version it’s mean that you are using Debian derivatives.

Comments

  1. fajarramd says:

    when i want to try, a syntax 
    wget http://download.fedora.redhat.com/pub/epel/beta/6/i386/epel-release-6-5.noarch.rpm not work. Should the link is broken ?

    • yes, it’s broken. Seems they change the url, it was listed as beta. Please try this instead

      wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm

      Thank you for letting me know.

      • fajarramd says:

        Woohoo 🙂
        Now my VPS is running. you’re welcome.

        Thank you very much for this nice aticle. Very Helpfull !

  2. Gene says:

    I get an error saying No package php-fpm available and No package php-apc available… Do you have any ideas on the cause?

Sorry, comments are closed

Bit and Bytes

Hello. My name is Dityo Nurasto. I am working as freelance software and web developer.

This is my personal playground. Enjoy your stay and don't hesitate to send comments.

ShoutBox