共计 8209 个字符,预计需要花费 21 分钟才能阅读完成。
1、安装必须的开发库
yum install ntp wget cpp gcc gcc-c++ gcc-g77 make unzip libtool \
libtool-ltdl-devel libc-client-devel libstdc++-devel db4-utils libcap-devel \
expat-devel perl pam-devel perl-Time-HiRes libaio-devel bzr patch bzip2-devel \
cmake bison libevent-devel ncurses-devel openssl-devel zlib-devel curl-devel \
libxml2-devel tcp_wrappers-devel nasm lemon flex libXpm-devel fontconfig-devel \
pcre-devel sqlite-devel perl-ExtUtils-Embed neon-devel
2、源码包
mysql-5.5.34.tar.gz
php-5.6.10.tar.gz
nginx-1.8.0.tar.gz
libmcrypt-2.5.7.tar.gz
将以上几个源码包都放在~/soft 目录下,cd 之
3、编译 mysql
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1
make
make install
#新增 mysql 组
groupadd mysql
#新增 mysql 用户
useradd -r -g mysql mysql
cd /usr/local/lnmp/mysql
chown mysql:mysql -R *
scripts/mysql_install_db --user=mysql --datadir=/usr/local/lnmp/mysql/data
cp /usr/local/lnmp/mysql/support-files/my-default.cnf /etc/my.cnf
cp /usr/local/lnmp/mysql/support-files/mysql.server /etc/init.d/mysqld
参考文章:http://www.cnblogs.com/apexchu/p/4245278.html
4、编译安装 libmcrypt-2.5.7.tar.gz
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make
make install
5、安装 php
tar zxvf php-5.6.10.tar.gz
cd php-5.6.10
./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --enable-inline-optimization --enable-shared --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=/usr/local/lnmp/mysql --enable-sockets --enable-pdo --with-pdo-mysql
make
make install
修改 /usr/local/lnmp/php/etc/php-fpm.conf
[global]
pid = run/php-fpm.pid
log_level = error
[www]
user = www
group = www
listen = /tmp/php-fcgi.sock
listen.owner = www
listen.group = www
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chroot=/usr/local/lnmp/nginx/html
6、安装 nginx
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/lnmp/nginx --sbin-path=/usr/local/lnmp/nginx/sbin/nginx --conf-path=/usr/local/lnmp/nginx/conf/nginx.conf --error-log-path=/tmp/nginx_error.log --http-log-path=/tmp/nginx_access.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --user=www --group=www --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-proxy-temp-path=/tmp/ --http-fastcgi-temp-path=/tmp --with-pcre
make
make install
修改 nginx 配置文件 /usr/local/lnmp/nginx/conf/nginx.conf, 没有什么什么优化处理,支持 PATHINFO:
worker_processes 1;
user www www;
error_log logs/error.log;
events { worker_connections 1024;}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root html;
index index.html index.htm index.php;
if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .+\.php($|/) {
set $script $uri;
set $path_info "/";
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
set $path_info $2;
}
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_NAME $script;
fastcgi_param SCRIPT_FILENAME /$script;
}
}
}
编写 nginx 启动脚本,将之放入 /etc/init.d 目录中:
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
# Author: guozi
# website: http://lnmp.org
. /etc/init.d/functions
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
NGINX_BIN=/usr/local/lnmp/nginx/sbin/$NAME
CONFIGFILE=/usr/local/lnmp/nginx/conf/$NAME.conf
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
case "$1" in
start)
echo -n "Starting $NAME... "
if netstat -tnpl | grep -q nginx;then
echo "$NAME (pid `pidof $NAME`) already running."
exit 1
fi
$NGINX_BIN -c $CONFIGFILE
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Stoping $NAME... "
if ! netstat -tnpl | grep -q nginx; then
echo "$NAME is not running."
exit 1
fi
$NGINX_BIN -s stop
for nid in `ps aux | grep "nginx:" | grep -v grep | awk '{print $1}'`
do
kill -9 $nid >/dev/null 2>&1
done
if [ "$?" != 0 ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
status)
if netstat -tnpl | grep -q nginx; then
PID=`pidof nginx`
echo "$NAME (pid $PID) is running..."
else
echo "$NAME is stopped"
exit 0
fi
;;
force-quit)
echo -n "Terminating $NAME... "
if ! netstat -tnpl | grep -q nginx; then
echo "$NAME is not running."
exit 1
fi
kill `pidof $NAME`
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$SCRIPTNAME stop
sleep 1
$SCRIPTNAME start
;;
reload)
echo -n "Reload service $NAME... "
if netstat -tnpl | grep -q nginx; then
$NGINX_BIN -s reload
echo " done"
else
echo "$NAME is not running, can't reload."
exit 1
fi
;;
configtest)
echo -n "Test $NAME configure files... "
$NGINX_BIN -t
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|force-quit|restart|reload|status|configtest}"
exit 1
;;
esac
7、编写 LNMP 启动、停止总脚本, 方便测试
#!/bin/bash
PHPFPM=/usr/local/lnmp/php/sbin/php-fpm
PHPFPM_CONFIG=/usr/local/lnmp/php/etc/php-fpm.conf
start()
{
/etc/init.d/mysqld start
/etc/init.d/nginx start
$PHPFPM -y $PHPFPM_CONFIG
}
stop()
{
killall -9 php-fpm
/etc/init.d/mysqld stop
/etc/init.d/nginx stop
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'*')
echo "No such selection"
;;
esac
正文完
扫码赞助
