当前位置: > CentOS > CentOS教程 >

CENTOS 下使用 YUM 搭建 LNMP

时间:2016-10-03 21:36来源:linux.it.net.cn 作者:IT

1、yum源安装

yum install epel-release -y

yum install wget vim -y

wget http://www.atomicorp.com/installer/atomic

sh ./atomic

yum check-update

2、安装开发包和库文件

yum install ntp make opensll openssl-devel pcre pcre-devel libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel perl perl-devel libxslt libxslt-devel-y

3、安装mysql

3.1 配置mysql官方源

 rpm –ivh http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm


3.2 yum安装mysql

yum install mysql-community-client mysql-community-devel mysql-community-server -y

chkconfig mysqld on

service mysqld start

查看/var/log/mysqld.log 找到随机生成的mysql初始密码,然后重新设置密码

mysqladmin –u root –p password         #输入命令后,第一次输入旧密码,然后输入新密码

service mysqld restart

4、nginx安装

4.1 yum安装nginx

yum install nginx –y                                  #安装nginx

chkconfig nginx on                                    #设置nginx开机启动

service nginx start                                     #启动nginx服务

4.2 nginx初始配置

cd /etc/nginx

mkdir vhosts

mv nginx.conf nginx.bak

vim proxy.conf

#!nginx (-)
# proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 128m;
client_body_buffer_size 512k;
proxy_connect_timeout 6000;
proxy_send_timeout 6000;
proxy_read_timeout 6000;
send_timeout 6000;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_temp_path /tmp/nginx/temp;
proxy_cache_path /tmp/nginx/cache levels=1:2 keys_zone=cache_zone:2048M inactive=1d max_size=20g;
proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400;

vim gzip.conf

gzip on;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6]\.";
#gzip_disable "Mozilla/4";
gzip_static on;
gzip_comp_level 4;
gzip_proxied any;
gzip_vary on;
gzip_buffers 4 16k;
gzip_min_length 1100;
gzip_types text/plain text/xml text/css application/xml application/xhtml+xml application/rss+xml application/atom_xml application/javascript application/x-javascript image/jpeg image/gif image/png;

vim nginx.conf

user nginx;
pid /var/run/nginx.pid;

worker_processes 8;
worker_rlimit_nofile 102400;
events {
	use epoll;
	worker_connections 65535;
}
http {
	include	mime.types;
	charset utf-8;
	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" '
	                              '"$gzip_ratio" $request_time $bytes_sent $request_length';
	set_real_ip_from 10.0.0.0/8;
	real_ip_header X-Forwarded-For;
	include /etc/nginx/gzip.conf;
	include /etc/nginx/proxy.conf;
	sendfile on;
	keepalive_timeout 10;
	client_header_buffer_size 4k;
	open_file_cache max=65535 inactive=60s;
	open_file_cache_valid 80s;
	open_file_cache_min_uses 1;
	include /etc/nginx/vhosts/*.conf;
	server {
		listen 80;
		server_name localhost;
		root /usr/share/nginx/html;
		location / {
			index index.html index.htm index.php;
		}
		error_page 500 502 503 504 /50x.html;
		location = /50x.html {
			root html;
		}
	}
}

4.3 确认nginx配置

nginx -t

4.4 启用nginx新配置

nginx -s reload

5、PHP安装

5.1 下载php5.3

cd /usr/local/src

wget http://cn2.php.net/distributions/php-5.3.29.tar.gz

5.2 编译安装php

tar -zxvf php-5.3.29.tar.gz

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-mcrypt=/usr/lib64 --with-icu-dir=/usr --with-zlib --enable-mbstring --with-openssl --with-mysql=/usr/lib64/mysql --with-mysqli=/usr/bin/mysql_config --with-mysql-sock=/var/lib/mysql/mysql.sock --with-gd --with-jpeg-dir=/usr/lib64 --enable-gd-antive-ttf --enable-pdo --with-pdo-mysql --with-freetype-dir --with-libxml --enable-xml --enable-discard-apth --enable-safe-mode --enable-bcmath --enable-shmop --enable-syssvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-dir=/lib64 --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear

 

5.3 修改php.ini文件中的以下配置

disable_functions = phpinfo,passthru,exec,system,popen,chroot,escapeshellcmd,escapeshellarg,shell_exec,proc_open,proc_get_status
			memory_limit = 512M
			upload_max_filesize = 32M
			date.timezone = Asia/Shanghai
			session.save_path = "/tmp/phpsession"

5.5 设置PHP开机启动

echo “/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf” >> /etc/rc.local

5.6 启动PHP

/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf

至此,LNMP环境搭建完毕。




(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容