LNMP Server on CentOS
Step 1. install yum repo
- //32 bit
rpm -ivh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -ivh http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1.0-6.ius.el5.noarch.rpm - //64 bit
rpm -ivh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
rpm -ivh http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/ius-release-1.0-6.ius.el5.noarch.rpm
Step 2. install MySQL
- //Visit http://dev.mysql.com/downloads/mysql/5.5.html?current_os=7#downloads
//You need to download 4 packages, they are:
MySQL-client MySQL-server MySQL-shared-compat MySQL-shared
//After you download them run:
rpm -ivh *.rpm - //change MySQL root password:
service mysql start
mysqladmin -u root password 'yourpasswd'
service mysql stop
Step 3. Add www account
groupadd www
useradd -g www -d /home/www www
// We add www as user of nginx and php-fpm
Step 4. install php
yum install php53u-cli php53u-common php53u php53u-devel php53u-mysql php53u-xmlrpc php53u-xml php53u-gd php53u-pdo php53u-tidy php53u-mcrypt php53u-mbstring php53u-pear php53u-pecl php53u-pecl-memcache php53u-pecl-apc php53u-fpm
//The current PHP version is 5.3.5-3, IUS' package's name is php53u
//You can run command blew to find out lastest version
yum list | grep -w \.ius\.
Step 5. configure php-fpm
- //setup php-fpm
vim /etc/php-fpm.d/www.conf
//Find Unix user/group of processes
//change user & group to www
Step 6. Install Nginx
- //visit http://nginx.org/en/download.html to get lastest Nginx
//for example, we use http://nginx.org/download/nginx-0.9.5.tar.gzyum install pcre pcre-devel # these are depend by nginx
cd /tmp
wget http://nginx.org/download/nginx-0.9.5.tar.gz
tar -zxvf nginx-*.tar.gz
cd nginx-*
./configure --user=www --group=www --conf-path=/etc/nginx/nginx.conf --with-http_stub_status_module --with-http_ssl_module
make
make install
//register nginx as a service
vim /etc/init.d/nginx
//paste the script blew then run:chmod 755 /etc/init.d/nginx#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
Step 7. Start at boot
chkconfig mysql on
chkconfig php-fpm on
chkconfig nginx on
Step 8. Start services
service mysql start
service php-fpm start
service nginx start
Finish
By the way, there is an easy solution which help you do the same, try LNMP Installer for RHEL & CentOS