My friend told me about my NginX Auto Installer, too bad because it only support CentOS, he really want to use my auto installer if it supports Debian or Ubuntu. As i said before, i’ve never tried OS other than CentOS, so last night i tried to install NginX, PHP, and MySQL under Ubuntu 10.04.2 Lucid, guess what? It was confusing me, why can’t this OS just give a standard name for their modules and packages? For example, on CentOS if we want to install PAM and PAM devel, then we’re just type
yum install pam pam-devel
but on Ubuntu
apt-get install libpam0g-dev libpam-devperm
Why not creating the normal name like ‘pam’ for package name and ‘pam-devel’ for development package name? I had to do googling for almost of those packages which i wanted to install because they have a ‘not normal’ name. :p
Okay, enough with the preamble story, here’s the result of my experiment.
Box: Ubuntu 10.04.2 Lucid 64bit with 256MB RAM OpenVZ
First update Ubuntu repository list and update existing packages
apt-get update apt-get upgrade
Install dependencies
apt-get install -y build-essential make automake patch bc netcat libgeoip1 libgeoip-dev fontconfig libfontconfig-dev libpam0g-dev libpam-devperm slapd ldap-utils libldap-2.4-2 libdb4.6 libxpm-dev libtool libaio-dev libltdl3-dev libmcrypt-dev libmhash-dev unixodbc unixodbc-dev zip unzip nano perl openssl libssl-dev libdevel-repl-perl libperl-dev libpcre3 libpcre3-dev libjpeg62 libjpeg62-dev libpng-dev libtiff4 libtiff-dev libfreetype6 libfreetype6-dev libgmp3-dev aspell libaspell-dev libpspell-dev libiconv-ruby mlocate libc-client2007e libc-client2007e-dev uw-imapd tidy libtidy-dev libbz2-dev libmysqlclient15-dev
Because i want to build NginX, PHP, and MySQL manually from source, also i will update a few dependencies for PHP, so now remove the following packages and also stop apache and bind processes.
apt-get remove apache2 php5 mysql-server gnupg curl libcurl3 libcurl-dev libidn11 libidn11-dev libxslt-dev killall -9 apache2 killall -9 named
Install GD Library
wget http://pkgs.serversreview.net/files/gd-2.0.33.tar.gz tar -zxvf gd-2.0.33.tar.gz cd gd-2.0.33 ./configure --prefix=/usr --libdir=/usr/lib --with-png=/usr/lib --with-freetype=/usr/lib --with-fontconfig=/usr/lib --with-jpeg=/usr/lib --with-xpm=/usr/lib make make install
Install another dependencies
GnuPG
wget http://pkgs.serversreview.net/files/gnupg-1.4.11.tar.gz tar -zxvf gnupg-1.4.11.tar.gz cd /tmp/pkgs/gnupg-1.4.11 ./configure --prefix=/usr --libdir=/usr/lib make make install
Gnu Libidn
wget http://pkgs.serversreview.net/files/libidn-1.9.tar.gz tar libidn-1.9.tar.gz cd libidn-1.9 ./configure --prefix=/usr --libdir=/usr/lib make make install
cURL
wget http://pkgs.serversreview.net/files/curl-7.21.4.tar.gz tar curl-7.21.4.tar.gz cd curl-7.21.4 ./configure --prefix=/usr --libdir=/usr/lib --with-openssl --with-libidn --enable-ipv6 make make install
Libxml2
wget http://pkgs.serversreview.net/files/libxml2-2.7.8.tar.gz tar -zxvf libxml2-2.7.8.tar.gz cd libxml2-2.7.8 rm -rf /usr/lib/libxml2* ./configure --prefix=/usr --libdir=/usr/lib make make install
Libxslt and Libexslt
wget http://pkgs.serversreview.net/files/libxslt-1.1.26.tar.gz tar libxslt-1.1.26.tar.gz cd libxslt-1.1.26 rm -rf /usr/lib/libxslt* /usr/lib/libexslt* ./configure --prefix=/usr --libdir=/usr/lib make make install
Install NginX
You can choose NginX Legacy Version 0.7.68, Stable Version 0.8.54, or Development Version 0.9.7. I’m going to use Stable Version 0.8.54.
First i’m going to add master user for NginX and PHP, also it is used for managing domains.
useradd www passwd www
*you can choose any username for this master user
Now installation process
mkdir -p /var/tmp/nginx/client /var/tmp/nginx/proxy /var/tmp/nginx/fcgi wget http://nginx.org/download/nginx-0.8.54.tar.gz tar -zxvf nginx-0.8.54.tar.gz cd nginx-0.8.54 ./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --user=www --group=www --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-file-aio --with-mail_ssl_module --with-ipv6 make make install
NginX init script
nano /etc/init.d/nginx
It is something like this
#! /bin/sh case "$1" in start) echo "Starting NginX" start-stop-daemon --start --exec /usr/sbin/nginx ;; stop) echo "Stopping NginX" start-stop-daemon --stop --exec /usr/sbin/nginx ;; restart) echo "Stopping NginX" start-stop-daemon --stop --exec /usr/sbin/nginx sleep 1 echo "Starting NginX" start-stop-daemon --start --exec /usr/sbin/nginx ;; *) echo "Usage: {start|stop|restart}" exit 1 ;; esac exit 0
make it executable and auto start
chmod +x /etc/init.d/nginx update-rc.d -f nginx defaults
NginX and Virtual Host Configuration
First about NginX master configuration, the main things you need to configure are
user www www; worker_processes 1;
*user and group is master user you have created before, and worker process is many cores does your box have.
and then because we’re going to use separate virtual host configuration, add the following line before the last “)” in Nginx master configuration
include /etc/nginx/sites-enabled/*;
you can adjust another configuration by referring to NginX HTTP Core Module
Now Virtual Host Configuration, create two directory named “sites-available” and “sites-enabled”
mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled
create NginX virtual host configuration
nano /etc/nginx/sites-available/serversreview.net
it would be something like this
server { server_name www.serversreview.net; rewrite ^/(.*) https://serversreview.net$1 permanent; } server { listen 80; server_name serversreview.net; access_log /home/www/serversreview.net/logs/access.log; error_log /home/www/serversreview.net/logs/error.log; location / { root /home/www/serversreview.net/public_html/; index index.html index.htm index.php; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/www/serversreview.net/public_html$fastcgi_script_name; } }
*change every serversreview.net with your domain name
*’www’ is master user directory, adjust it with your preferred master user directory name
*the virtual host configuration above is redirecting www.serversreview.net to serversreview.net
don’t forget to symlink your virtual host configuration to the “sites-enabled” directory everytime you add a new configuration
ln -s /etc/nginx/sites-available/serversreview.net /etc/nginx/sites-enabled
Install MySQL from source
I’m going to use the latest version 5.5.10, first create user and group for MySQL
groupadd mysql useradd -r -g mysql mysql
Download, unpack, symlink new directory for MySQL
wget http://pkgs.serversreview.net/files/mysql-5.5.10-linux2.6-x86_64.tar.gz cd /usr/local tar -zxvf /path/to/mysql-5.5.10-linux2.6-x86_64.tar.gz mv mysql-5.5.10-linux2.6-x86_64 mysql
Configuring MySQL
cd mysql chown -R mysql . chgrp -R mysql . scripts/mysql_install_db --user=mysql chown -R root . chown -R mysql data cp support-files/my-small.cnf /etc/my.cnf
*i’m using my-small.cnf as mysql configuration, you can choose any available configurations depending on your needs
now test your MySQL with mysqld_safe and run it on background
bin/mysqld_safe --user=mysql & bg
copy MySQL init script to /etc/init.d and make it autorun
cp support-files/mysql.server /etc/init.d/mysql chmod +x /etc/init.d/mysql update-rc.d -f mysql defaults
securing your mysql
bin/mysql_secure_installation
*you can take a look at my previous NginX under CentOS installation for details
Install PHP
PHP 5.2.17 is still used because of its compatibility for many apps, but PHP 5.3.6 provides faster PHP processing, so it is your choice and now i’m going to use PHP 5.3.6 for the example.
First, install autoconf 2.13
wget http://pkgs.serversreview.net/files/autoconf-2.13.tar.gz tar -zxvf autoconf-2.13.tar.gz cd autoconf-2.13 ./configure make make install
And PHP 5.3.6 installation show time
wget http://pkgs.serversreview.net/files/php-5.3.6.tar.gz tar -zxvf php-5.3.6.tar.gz cd php-5.3.6 ./buildconf --force ./configure --prefix=/usr --libdir=/usr/lib/php --with-libdir=lib --enable-force-cgi-redirect --enable-fpm --enable-cli --with-mcrypt --enable-mbstring --with-openssl --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql --with-gd --with-zlib --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-png --with-jpeg --with-gmp --with-sqlite --enable-pdo --with-xpm-dir=/usr/lib --with-freetype-dir=/usr/include/freetype2 --with-ttf=/usr/include/freetype2 --libdir=/usr/lib --enable-gd-native-ttf --enable-fileinfo --disable-debug --with-pic --with-bz2 --with-curl --with-curlwrappers --without-gdbm --with-gettext --with-iconv --with-pspell --with-pcre-regex --with-imap --with-imap-ssl=/usr/lib --enable-exif --enable-ftp --enable-magic-quotes --enable-sockets --disable-sysvsem --disable-sysvshm --disable-sysvmsg --enable-track-vars --enable-trans-sid --enable-yp --enable-wddx --with-kerberos --enable-ucd-snmp-hack --enable-memory-limit --enable-shmop --enable-calendar --enable-dbx --enable-dio --with-mime-magic --with-system-tzdata --with-odbc --enable-gd-jis-conv --enable-dom --disable-dba --enable-xmlreader --enable-xmlwriter --with-tidy --with-xml --with-xmlrpc --with-xsl --enable-bcmath --enable-soap --enable-zip --enable-inline-optimization --with-mhash --enable-mbregex
PHP-FPM init script
nano /etc/init.d/php-fpm
and the content of php-fpm init script is like the following
#! /bin/sh case "$1" in start) /usr/sbin/php-fpm --fpm-config /etc/php-fpm.conf echo "PHP-FPM started successfully" exit 1 ;; stop) killall -9 php-fpm echo "PHP-FPM stopped" exit 1 ;; restart) echo "Stopping php-fpm" killall -9 php-fpm sleep 1 echo "Starting php-fpm" /usr/sbin/php-fpm --fpm-config /etc/php-fpm.conf sleep 1 echo "PHP-FPM restarted successfully" exit 1 ;; *) echo "Usage: start - stop - restart" exit 1 ;; esac
make executable plus autorun after boot
chmod +x /etc/init.d/php-fpm update-rc.d -f php-fpm defaults
copy php-fpm config to /etc/ directory
cp /usr/etc/php-fpm.conf.default /etc/php-fpm
then uncomment and adjust the following lines to suit your needs
user = www group = www pm = dynamic pm.max_children = 3 pm.start_servers = 1 pm.min_spare_servers = 1 pm.max_spare_servers = 2 pm.max_requests = 250
*remember that user and group is master user you’ve created before
So it is now you’re ready to rock your website under Ubuntu 10.04.2 Lucid!!! Don’t forget to use this command to manage those three main things above
/etc/init.d/nginx {start|stop|restart} /etc/init.d/mysql {start|stop|restart} /etc/init.d/php-fpm {start|stop|restart}
Problem
Init scripts for autorun is not working, i don’t have any idea and still looking for the answer.
http://pkgs.serversreview.net/files/GD_2_0_33.tar.gz
Returns a 404 🙁
it has been fixed, you can wget it now.
Hello there,
this tutorial is great.
i can’t download file “http://pkgs.serversreview.net/files/mysql-5.5.10-linux2.6-x86_64.tar.gz” so i download from mysql “MySQL-5.5.17-1.linux2.6.i386.tar” and iam stuck in
========================================
tar -zxvf /path/to/mysql-5.5.10-linux2.6-x86_64.tar.gz
mv mysql-5.5.10-linux2.6-x86_64 mysql
========================================
i don’t understand this command “tar -zxvf /path/to/mysql-5.5.10-linux2.6-x86_64.tar.gz”
and why after that “mv mysql-5.5.10-linux2.6-x86_64 mysql”
hi there,
it is just renamed to mysql folder name
great!!!, thanks for the reply. i have finished install although i must write code in rc.local to start nginx, mysql n php-fpm.