标签:lnmp环境
1.1 系统环境
实验环境为系统CentOS 6.5 x86_64,虚拟机上有两个IP地址,其中一个连接Internet,方便使用yum方式通过网络安装所需软件包。主要软件如Nginx、MySQL、PHP都通过源码安装,相关信息如下:
1) Nginx官网为http://nginx.org/,这里使用最新稳定版nginx-1.6.1.tar.gz
2) MySQL官网为http://www.mysql.com/,这里使用最新5.5版本稳定版mysql-5.5.39.tar.gz
3) PHP官网为http://www.php.org/,这里使用5.3版本php-5.3.28.tar.gz
1.2 安装LNMP
1.2.1 安装所需rpm软件包
本次实验下载安装了epel源以解决安装LNMP过程遇到软件包依赖问题:
[root@server src]# rpm -ivh http://ftp.sjtu.edu.cn/fedora/epel/6Server/x86_64/epel-release-6-8.noarch.rpm [root@server src]# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel pcre pcre-devel openssl openssl-devel ncurses ncurses-devel bison bison-devel libxml2 libxml2-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel freetype freetype-devel freetype freetype-devel
1.2.2 安装设置Nginx
[root@server src]# groupadd www
[root@server src]# useradd -g www -s /sbin/nologin www
[root@server src]# tar zxf nginx-1.6.1.tar.gz
[root@server nginx-1.6.1]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
…
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library
…
[root@server nginx-1.6.1]# make && make install
[root@server nginx-1.6.1]# cd /usr/local/nginx/conf/
[root@server conf]# cp nginx.conf{,.bak}
[root@server conf]# vi nginx.conf
user www www;
worker_processes 1;
error_log /home/wwwlogs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events {
use epoll;
worker_connections 51200;
}
http {
include mime.types;
default_type application/octet-stream;
log_format access ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" $http_x_forwarded_for‘;
access_log /usr/local/nginx/logs/access.log access;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
client_header_timeout 10;
client_body_timeout 10;
send_timeout 10;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server {
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /home/wwwroot;
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
location /status {
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 12h;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@server conf]# vi fastcgi_params
…
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
[root@server conf]# mkdir /home/wwwroot
[root@server conf]# mkdir /home/wwwlogs
[root@server conf]# chmod 777 /home/wwwlogs/
[root@server conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server conf]# vi /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it‘s not for everyone.
# processname: nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
[root@server conf]# chmod u+x /etc/init.d/nginx
[root@server conf]# chkconfig --add nginx
[root@server conf]# chkconfig nginx on
[root@server conf]# chkconfig --list nginx
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off1.2.3 安装设置MySQL
[root@server src]# wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz [root@server src]# tar zxf cmake-2.8.12.2.tar.gz [root@server src]# cd cmake-2.8.12.2 [root@server cmake-2.8.12.2]# ./configure && make && make install [root@server src]# groupadd mysql [root@server src]# useradd -g mysql mysql [root@server src]# tar zxf mysql-5.5.39.tar.gz [root@server src]# cd mysql-5.5.39 [root@server mysql-5.5.39]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 [root@server mysql-5.5.39]# make && make install [root@server mysql-5.5.39]# cp support-files/my-medium.cnf /usr/local/mysql/my.cnf [root@server mysql-5.5.39]# cd /usr/local/mysql/ [root@server mysql]# vi my.cnf [mysqld] … basedir = /usr/local/mysql datadir = /usr/local/mysql/data [root@server mysql]# chown -R mysql.mysql data [root@server mysql]# scripts/mysql_install_db --defaults-file=./my.cnf --user=mysql [root@server mysql]# cp /usr/local/src/mysql-5.5.39/support-files/mysql.server /etc/init.d/mysqld [root@server mysql]# chmod u+x /etc/init.d/mysqld [root@server mysql]# chkconfig --add mysqld [root@server mysql]# chkconfig mysqld on [root@server mysql]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
1.2.4 安装设置PHP
[root@server src]# tar zxf php-5.3.28.tar.gz [root@server src]# cd php-5.3.28 [root@server php-5.3.28]# ln -s /usr/lib64/libltdl.so.3.1.4 /usr/lib64/libltdl.so [root@server php-5.3.28]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-fpm --with-mcrypt --with-mhash --enable-mbstring --with-gettext --with-gd --with-gettext --with-jpeg-dir --with-freetype-dir --enable-bcmath --enable-sockets [root@server php-5.3.28]# make && make install [root@server php-5.3.28]# cp php.ini-production /usr/local/php/etc/php.ini [root@server php-5.3.28]# cd /usr/local/php/etc [root@server etc]# cp php-fpm.conf.default php-fpm.conf [root@server etc]# vi php-fpm.conf user = www group = www [root@server etc]# cp /usr/local/src/php-5.3.28/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@server etc]# chmod u+x /etc/init.d/php-fpm [root@server etc]# chkconfig --add php-fpm [root@server etc]# chkconfig php-fpm on [root@server etc]# chkconfig --list php-fpm php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
1.2.5 启动各个服务并创建测试页面
[root@server ~]# /etc/init.d/nginx start [root@server ~]# /etc/init.d/mysqld start [root@server ~]# /etc/init.d/php-fpm start [root@server etc]# echo "<?php phpinfo(); ?>" > /home/wwwroot/phpinfo.php
1.2.6 安装phpMyAdmin
[root@server src]# tar zxf phpMyAdmin-4.2.7.1-all-languages.tar.gz [root@server src]# cp -rf phpMyAdmin-4.2.7.1-all-languages /home/wwwroot/phpmyadmin [root@server src]# /usr/local/mysql/bin/mysqladmin -u root password ‘iforgot‘
标签:lnmp环境
原文地址:http://373510.blog.51cto.com/363510/1543516