Perfect web server for your blog running CentOS (nginx + php-fpm + mysql)
Having your own blog this days can be a piece of cake, as there are a lot of hosting packages to choose from and also they are very cheap. Like I said, having a blog it’s not a big deal, but having a dedicated server or VPS with your own custom setup can be some what difficult to achieve. I’m talking about a setup which includes nginx as a web server, php-fpm as a back-end php server and mysql server as a database server. The easy way how to do this, could be by installing this packages from the distro’s repository, but again, is this case I will do it from the source code.
To start with this, we need a VPS or dedicated server, which can be a problem, because can cost some money. A VPS can cost from about $20 and up and you’ll get with this money about 256MB of RAM and maybe 10-20GB of disk space. If you need something better or faster, a dedicated server would do the job and the price for having a dedicated server would easily start from $50 and up.
Remember, for this web server, we need at least 256MB of RAM and let’s say 2GB free disk space, to be able to build nginx, php-fpm and MySQL.
I will assume that we already have the VPS or dedicated server, the OS it’s already install and everything is up and running. What we need now its to download the source code of nginx, php, php-fpm patch and MySQL, then build them, install them and of course configured them.
Before we start, I have to remind you that it is possible that some builds will fail due to some missing libraries, which you will need to install at that time and the version of the applications in this post might not be the same as maybe in a month from the time I’m writing this, so this means it could be newer versions, which you will need to check.
We do everything with user root, much more easier, the to use sudo.
Download the source code (nginx, php, MySQL and php-fpm patch):
> mkdir build
> cd build
> wget http://cz.php.net/get/php-5.2.9.tar.gz/from/us.php.net/mirror (php 5.2.9 source code)
> wget http://sysoev.ru/nginx/nginx-0.7.60.tar.gz (nginx 0.7.60 source code)
> wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.83.tar.gz/from/http://mysql.mirrors.hoobly.com/ (mysql 5.0.83 source code)
> wget http://php-fpm.anight.org/downloads/head/php-5.2.8-fpm-0.5.10.diff.gz (the php-fpm patch for php 5.2.9)
Unpack the downloaded source code archives:
> tar -xzvf php-5.2.9.tar.gz
> tar -xzvf nginx-0.7.60.tar.gz
> tar -xzvf mysql-5.0.83.tar.gz
> gunzip -d php-5.2.8-fpm-0.5.10.diff.gz
Build and install the source code (start with MySQL, also we will install it, as php can’t be build without MySQL):
> cd mysql-5.0.83
> ./configure –prefix=/applications/mysql –sysconfdir=/etc –with-openssl –with-machine-type –with-system-type –with-mysqld-user=mysql –without-docs –without-bench –enable-large-files-without-debug –disable-maintainer-mode –without-man –with-unix-socket-path=/tmp/mysql.sock –without-debug –with-archive-storage-engine –with-low-memory
> make
> make install> cd ../php-5.2.9
> patch -p1 < ../php-5.2.8-fpm-0.5.10.diff
> ./configure –enable-fpm –enable-discard-path –enable-inline-optimization –enable-fastcgi –enable-force-cgi-redirect –prefix=/applications/php-cgi –with-config-file-path=/applications/php-cgi/etc –enable-bcmath –enable-calendar –with-curl –enable-exif –enable-ftp –with-gd –with-gettext –with-iconv –enable-mbstring –enable-mbregex –with-mcrypt –with-mhash –with-openssl –with-pear=/applications/php-cgi/lib –with-xsl –enable-sockets –with-ttf –enable-gd-native-ttf –with-zlib –enable-zip –enable-pcntl –enable-magic-quotes –enable-discard-path –with-ttf –with-freetype-dir=/usr –with-kerberos –disable-ipv6 –with-tidy –with-bz2 –enable-shmop –with-jpeg-dir=/usr –with-mm –enable-mbstring=all –with-mime-magic=/usr/share/magic.mime
> make
> make install> cd ../nginx-0.7.60
> ./configure –prefix=/applications/nginx –with-http_ssl_module –with-http_realip_module –with-http_addition_module –with-http_flv_module –with-http_gzip_static_module –with-http_sub_module –http-log-path=/var/log/nginx/access_log –with-http_perl_module –user=www –group=www –conf-path=/applications/nginx/conf/nginx.conf –http-fastcgi-temp-path=/applications/nginx/tmp/fastcgi –http-client-body-temp-path=/applications/nginx/tmp/client –http-proxy-temp-path=/applications/nginx/tmp/proxy –pid-path=/var/run/nginx.pid –error-log-path=/var/log/nginx/error_log –with-sha1=/usr/lib –with-md5=/usr/lib
> make
> make install
Configure the build applications:
- setup the mysql server:
> cd ../mysql-5.0.83/scripts
> groupadd -g 10001 mysql
> useradd -M -d /srv/databases/mysql -g 10001 -r -s /bin/false mysql
> ./mysql_install_db.sh –datadir=/srv/databases/mysql
> cd ../../
> chown -R mysql.mysql /srv/databases/mysql
> wget http://dl.robertalks.com/nginx+php-fpm+mysql/mysql -O /etc/rc.d/init.d/mysql
> chmod +x /etc/rc.d/init.d/mysql
> chkconfig –add mysql
> chkconfig mysql on
> wget http://dl.robertalks.com/nginx+php-fpm+mysql/my.cnf.txt -O /etc/my.cnf
> touch /var/log/mysql-slow.log; chown mysql.mysql /var/log/mysql-slow.log; chmod 644 /var/log/mysql-slow.log
> /etc/init.d/mysql start
- setup php-fpm:
> cd php-5.2.9
> cp php.ini-recommended /applications/php-cgi/etc/php.ini
> groupadd -g 10002 www
> useradd -M -d /srv/www -g 10002 -r -s /bin/false www
> mkdir /var/log/nginx
> chown www.www /var/log/nginx
> chmod 770 /var/log/nginx
> wget http://dl.robertalks.com/nginx+php-fpm+mysql/php-fpm -O /etc/rc.d/init.d/php-fpm
> chmod +x /etc/rc.d/init.d/php-fpm
> chkconfig –add php-fpm
> chkconfig php-fpm on
> wget http://dl.robertalks.com/nginx+php-fpm+mysql/php-fpm.conf.txt -O /applications/php-cgi/etc/php-fpm.conf
> /etc/init.d/php-fpm start
- setup nginx:
> cd ~
> wget http://dl.robertalks.com/nginx+php-fpm+mysql/nginx.conf.txt -O /applications/nginx/conf/nginx.conf
> wget http://dl.robertalks.com/nginx+php-fpm+mysql/fastcgi_params.txt -O /applications/nginx/conf/fastcgi_params
> wget http://dl.robertalks.com/nginx+php-fpm+mysql/www.example.com.txt -O /applications/nginx/conf/host/www.example.com (this you will need to name and configurate acording to you blog/dns/system)
> mkdir /applications/nginx/conf/host
> wget http://dl.robertalks.com/nginx+php-fpm+mysql/blog.example.com.txt -O /applications/nginx/conf/host/blog.example.com (this you will need to name and configurate acording to you blog/dns/system)
> wget http://dl.robertalks.com/nginx+php-fpm+mysql/nginx -O /etc/rc.d/init.d/nginx
> chmod +x /etc/rc.d/init.d/nginx
> chkconfig –add nginx
> chkconfig nginx on
So this should be the base setup for your server and of course for your blog to run, but there will be some settings which you will need to check and set depending on some different things which exist or not on your server. This configuration and setup works perfectly for my blog, which is this, from where you’re reading now. The hardware it’s not very powerful, it’s an Intel P4 at 2.8Ghz, with 512MB of RAM and 75GB disk and as I remember a 100 Mbit line. The system is running on CentOS 5.3, only 32bit kernel and its fast and very stable… don’t really think you need more then this for your personal blog and maybe web page. If you have a lot of hits on your blog, you might need a better system, not because of the web server, but because of MySQL and even php, which will start eating the resources if it’s necessary.
Do not forget, this setup is design like this:
All the applications are install in directory /applications, all the data, the blog itself, MySQL database are install in /srv and all the logs go into /var/log and /var/log/nginx. If you want a totally different configuration, then you need to modify accordingly to what you want.
P.S. I can not guarantee that this post will help 100% or it will work 100%. This is my way of working and doing the setup, but depends on everybody style and know-how. Do not forget to recheck the configuration of nginx, php and MySQL. Setup can differ depending on your system.
| Print article | This entry was posted by robert on June 20, 2009 at 22:39, and is filed under General, Linux, Talk. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
No comments yet.
No trackbacks yet.
Kernel 2.6.34.1-blackjack released for Debian/Ubuntu (Blackjack)
about 3 weeks ago - 5 comments
I haven’t been writing on my blog for quite a while and I guess now I should, well actually The Kernel Development just released kernel 2.6.34.1, so I have a good reason for adding a new post .
This kernel really stayed in the cooker for some time, as version 2.6.34 was release two months ago. I
Kernel 2.6.34-final is here!
about 2 months ago - 4 comments
After a couple of days of waiting for BFS scheduler patch and rebuilding the patch for ureadahead, kernel 2.6.34-final is here. I know, again, it’s with a certain delay, but some parts are not in my control and it’s not much that I can do about it.
As usual, the same stuff are included in this
Kernel 2.6.33.3-soultrain released for Debian/Ubuntu (Soultrain)
about 2 months ago - 8 comments
Well first of all, sorry for this late release, but had some stuff to handle which at that point in time where more important. Kernel 2.6.33.3 was released last week and it comes like always with a bunch of bug fixes, improvements and new stuff added. I’m not gonna go into them, because there are
Kernel 2.6.33.2-coolcat released for Debian/Ubuntu (Coolcat)
about 3 months ago - 12 comments
A couple of days ago Kernel 2.6.33.2 was released. Due to the Easter holidays, I didn’t have the time to build this kernel, but yesterday evening somehow I get around it and now the packages are ready for use.
There are no major stuff added in this kernel from my side, besides the removal of PAE
Kernel 2.6.33.1-beetlejuice released for Debian/Ubuntu (Beetlejuice)
about 4 months ago - 2 comments
Another day, another kernel, another kernel package. To be damn honest, I can’t keep up with the kernel development team. They are releasing kernels like on a production line. It’s almost impossible for a single person to keep the the releases on time, but I’m trying
Anyway, I will keep this short and tell
Brain Fuck Scheduler and Kernel 2.6.33 (2.6.33-final-bfs)
about 4 months ago - 5 comments
A couple of days ago, I discovered, thanks to PCLinuxOS, a new kernel scheduler, Brain Fuck Scheduler or BFS. The name of this kernel scheduler is not very attractive, but what this scheduler does, is. It seems that this scheduler is more simple and fast, especially when it comes to low spec computers.
Because I’ve tried
Kernel 2.6.33-final is here!
about 5 months ago - No comments
A couple of days ago kernel 2.6.33 was released. Due to some personal issues which I had to deal with, I couldn’t actually release the packages sooner than now.
Because I don’t wanna carry too much about this and that and plus I don’t really have much time, I will just say that this final release
Kernel 2.6.32.8-pharox released for Debian/Ubuntu (Pharox)
about 5 months ago - 4 comments
Today seems a good day to release a new kernel package. It’s Friday, it’s almost weekend and why not have some fun with a new kernel release. The kernel was release a couple of days ago, but to be honest, I couldn’t build it due to not having a machine working on some older Ubuntu.
TweeU plugin for WordPress released (version 1.0)
about 5 months ago - No comments
A couple of days ago I have created a new plugin, TweeU, based on Tweetly Updater. This plugin updates your Twitter account with the new posts from your blog when they are published and creates a short URL link to the post using buh.bz. The difference between the original plugin, Tweetly Updater and TweeU is
Kernel 2.6.32.7-firefly released for Debian/Ubuntu (Firefly)
about 6 months ago - No comments
Now I know I’m gonna repeat myself, but this is the 4th release in 2 weeks. I’m not sure how come there are so many release out of the door, but seems there are a lot of fixes added to each release. So this release is 2.6.32.7 which seems to bring more improvements and fixes
