如何搭建 LNMP环境
和LAMP不同的是LNMP中的N指的是是Nginx(类似于Apache的一种web服务软件)其他都一样。目前这种环境应用的也是非常之多。 Nginx设计的初衷是提供一种快速高效多并发的web服务软件。在静态页面的处理上Nginx的确胜Apache一筹,然而在动态页面的处理上 Nginx并不比Apache有多少优势。但是,目前还是有很多爱好者对Nginx比较热衷,随着Nginx的技术逐渐成熟,它在web服务软件领域的地 位越来越高。
【MySQL安装】
1. 下载mysql到/usr/local/src/
cd /usr/local/src/
wget http://syslab.comsenz.com/downloads/linux/mysql-5.0.86-linux-i686-icc-glibc23.tar.gz
2. 解压
tar zxvf /usr/local/src/ mysql-5.0.86-linux-i686-icc-glibc23.tar.gz
3. 把解压完的数据移动到/usr/local/mysql
mv mysql-5.0.86-linux-i686-ii-glibc23 /usr/local/mysql
4. 建立mysql用户
useradd mysql
5. 初始化数据库
cd /usr/local/mysql
mkdir /data/mysql ; chown -R mysql:mysql /data/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
--user定义数据库的所属主,--datadir定义数据库安装到哪里,建议放到大空间的分区上,这个目录需要自行创建。
6. 拷贝配置文件
cp support-files/my-large.cnf /etc/my.cnf
7. 拷贝启动脚本文件并修改其属性
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
8. 修改启动脚本
vim /etc/init.d/mysqld
需要修改的地方有datadir=/data/mysql(前面初始化数据库时定义的目录)
9. 把启动脚本加入系统服务项,并设定开机启动,启动mysql
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
如果启动不了,请到/data/mysql/ 下查看错误日志,该日志格式为主机名.err。
【php的安装】
这里要先声明一下,针对Nginx的php安装和针对apache的php安装是有区别的,因为Nginx中的php是以fastcgi的方式结合nginx的,可以理解为nginx代理了php的fastcgi,而apache是把php作为自己的模块来调用的。
useradd www
cd /usr/local/src/
wget http://syslab.comsenz.com/downloads/linux/php-5.2.10.tar.gz
wget http://syslab.comsenz.com/downloads/linux/php-5.2.10-fpm-0.5.13.diff.gz
下载的第二个包php-5.2.10-fpm-0.5.13.diff.gz是用来给php打补丁的,默认情况下,php是无法编译出fastcgi的。
tar zxvf php-5.2.10.tar.gz
gzip -cd php-5.2.10-fpm-0.5.13.diff.gz | patch -d php-5.2.10 -p1
cd php-5.2.10
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --enable-zend-multibyte --disable-ipv6 --enable-fastcgi --enable-fpm
make && make install
mkdir /usr/local/php/etc
cp php.ini-dist /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php-fpm.conf
<value name="listen_address">/tmp/php-fcgi.sock</value> 这一行要改成这样,这里这样修 改了以后,在配置nginx的时候就需要注意这个路径了。修改用户和组的名称为”www” 去掉注释,改成这样:Unix user of processes <value name="user">www</value> Unix group of processes <value name="group">www</value>
/usr/local/php/sbin/php-fpm start
其他关于php的扩展模块安装请参考:
CentOS 5.5下安装mysql5.1.57+php5.2.17(FastCGI)+nginx1.0.1高性能Web服务器
【nginx 安装以及配置】
1. nginx源码安装
cd /usr/local/src/
wget http://syslab.comsenz.com/downloads/linux/nginx-0.9.6.tar.gz
tar zxvf nginx-0.9.6.tar.gz
cd nginx-0.9.6
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/var/nginx.pid --lock-path=/usr/local/nginx/var/nginx.lock --http-client-body-temp-path=/dev/shm/nginx_temp/client_body --http-proxy-temp-path=/dev/shm/nginx_temp/proxy --http-fastcgi-temp-path=/dev/shm/nginx_temp/fastcgi --user=www --group=www --with-cpu-opt=pentium4F --without-select_module --without-poll_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --without-http_ssi_module --without-http_userid_module --without-http_geo_module --without-http_memcached_module --without-http_map_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-pcre
make && make install
mkdir /dev/shm/nginx_temp
有 的nginx版本编译时会因为pcre编译不过去,需要修改一下 --with-pcre=/usr/local/src/pcre-7.8,前提是已经 下载了pcre源码包pcre-7.8.tar.gz,并解压到/usr/local/src/pcre-7.8,不需要编译pcre
2. 编写nginx的启动脚本,并加入系统服务
vi /etc/init.d/nginx 写入以下内容:
#!/bin/bash# chkconfig: - 30 21# description: http service.# Source Function Library. /etc/init.d/functions# Nginx SettingsNGINX_SBIN="/usr/local/nginx/sbin/nginx"NGINX_CONF="/usr/local/nginx/conf/nginx.conf"NGINX_PID="/usr/local/nginx/var/nginx.pid"RETVAL=0prog="Nginx"start() {echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL}stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL}reload(){ echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL}restart(){ stop start}configtest(){ $NGINX_SBIN -c $NGINX_CONF -t return 0}case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1esacexit $RETVAL
保存后,更改/etc/init.d/nginx的权限
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
3. nginx的配置
vim /usr/local/nginx/conf/nginx.conf
把原来的文件清空,然后粘贴如下内容:
user www www;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/var/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 6000;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 2048;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local] '
'$host "$request_uri" $status '
'"$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml;
server
{
listen 80;
server_name www.example.com;
index index.html index.htm index.php;
root /data/www;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/ php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
保 存后就可以启动nginx了,在重启之前最好先检查一下是否有问题/usr/local/nginx/sbin/nginx -t 如果显示 "syntax is ok 和 nginx.conf was tested successfully"这样的信息,就说明配置没有问题了,否则就需要根据提示修改了。service nginx start
如果启 动不了,请到/usr/local/nginx/logs/目录下查看nginx_error.log这个日志文件。若是没有这个日志文件,很有可能是那 个目录没有写权限,请执行chmod +w /usr/local/nginx/logs/ service nginx restart
【测试是否解析php文件】
vim /data/www/1.php
写入如下内容:
<?phpphpinfo();?>
然后设定hosts文件,访问 www.92csz.com/1.php 看是否能解析出这个页面。
来源http://jingyan.baidu.com/article/fc07f9891c2b6412ffe51908.html
如何搭建 LNMP环境的更多相关文章
- CentOS6.6搭建LNMP环境
CentOS6.6搭建LNMP环境 1.设置yum源,本地安装依赖包 1 yum -y install gcc gcc-c++ automake autoconf libtool make 2.下载依 ...
- Yum搭建LNMP环境(动、静、库分离)(week4_day5)--技术流ken
前言 本篇博客使用yum来搭建lnmp环境,将采用动态,静态以及数据库分开安装的方式即nginx,php,mysql.会被分开安装在不同的服务器之上,搭建出来一套lnmp环境,并部署wordpress ...
- [Linux] deepin15.8搭建LNMP环境
LAMP和LNMP LAMP==Linux+Apache+Mysql+PHP LNMP==Linux+Nginx+Mysql+PHP 安装nginx sudo apt install nginx 安装 ...
- CentOS 7 源码搭建LNMP环境
搭建 LNMP 环境 源码包版本 : CentOS Linux 7 nginx-1.15.1.tar.gz mysql-boost-5.7.21.tar.gz php-7.2.7.tar.gz ...
- Vmware搭建LNMP环境(Centos7+Nginx+Mysql+PHP7.1.8)
参考:1.Linux学习之CentOS(一)----在VMware虚拟机中安装CentOS 7(图文教程) 2.Centos7搭建LNMP环境 3.MySQL5.7修改默认root密码 4.CentO ...
- ubuntu通过apt-get方式搭建lnmp环境以及php扩展安装
v 一直是在用的lnmp的集成安装包搭建lnmp环境,因为工作需要需要安装ldap扩展,在网上怎么都找不到源码安装包,只能卸载掉原来的lnmp环境,用ubuntu的php5-ldap扩展, 在安装中遇 ...
- Mac下docker搭建lnmp环境 + redis + elasticsearch
之前在windows下一直使用vagrant做开发, 团队里面也是各种开发环境,几个人也没有统一环境,各种上线都是人肉,偶尔还会有因为开发.测试.生产环境由于软件版本或者配置不一致产生的问题, 今年准 ...
- WIN10 vagrant和virtualbox虚拟机和一键搭建lnmp环境配置thinkphp虚拟主机
版本:win10系统 virtualbox:5.1.26 vagrant :1.9.7 centos 7.0 xshell/git 首先下载好对应版本的软件 配置vagrant和virtualbox ...
- docker搭建lnmp环境(问题,资料,命令)
入门参考 http://www.runoob.com/docker/docker-install-nginx.html 十大常用命令玩转docker 1. #从官网拉取镜像 docker pull & ...
- centos7 yum搭建lnmp环境及配置wordpress超详细教程
yum安装lnmp环境是最方便,最快捷的一种方法.源码编译安装需要花费大量的人类时间,当然源码编译可以个性化配置一些其它功能.目前来说,yum安装基本满足我们搭建web服务器的需求. 本文是我根据近期 ...
随机推荐
- 四、oracle 用户管理 二
一.使用profile管理用户口令概述:profile是口令限制,资源限制的命令集合,当建立数据库时,oracle会自动建立名称为default的profile.当建立用户没有指定profile选项时 ...
- 【Java】 Scanner类的几个方法
通过 Scanner 类可以获取用户的输入,创建 Scanner 对象的基本语法如下: Scanner sc = new Scanner(System.in); nextInt().next()和ne ...
- Python爬虫个人记录(四)利用Python在豆瓣上写一篇日记
涉及关键词:requests库 requests.post方法 cookies登陆 version 1.5(附录):使用post方法登陆豆瓣,成功! 缺点:无法获得登陆成功后的cookie,要使用js ...
- 10 Best jQuery and HTML5 WYSIWYG Plugins
https://www.sitepoint.com/10-best-html-wysiwyg-plugins/
- BZOJ2152 [国家集训队] 聪聪可可 [点分治]
题目传送门 聪聪可可 Time Limit: 3 Sec Memory Limit: 259 MBSubmit: 5237 Solved: 2750[Submit][Status][Discuss ...
- Intellij IDEA Cannot resolve symbol XXX 问题解决办法汇总
maven项目遇到这类问题基本上是两方面的原因,类对应的依赖没有加载进来.编译器自身的设置和缓存问题. 解决第一类:1.检查项目的pom文件,是否必要的依赖都写清楚了: 2.是否使用自己的私有库,&l ...
- poj-2528线段树练习
title: poj-2528线段树练习 date: 2018-10-13 13:45:09 tags: acm 刷题 categories: ACM-线段树 概述 这道题坑了我好久啊啊啊啊,,,, ...
- iOS 9应用开发教程之多行读写文本ios9文本视图
iOS 9应用开发教程之多行读写文本ios9文本视图 多行读写文本——ios9文本视图 文本视图也是输入控件,与文本框不同的是,文本视图可以让用户输入多行,如图2.23所示.在此图中字符串“说点什么吧 ...
- with上下文管理器
术语 要使用 with 语句,首先要明白上下文管理器这一概念.有了上下文管理器,with 语句才能工作. 下面是一组与上下文管理器和with 语句有关的概念. 上下文管理协议(Context Mana ...
- 浏览器在线查看pdf文件 pdf.js的使用教程
谷歌浏览器可以直接在线查看pdf,而IE内核浏览器无法在线查看,默认是下载. 这里用到的是pdf.js,不仅支持IE内核浏览器,而且兼容手机查看pdf 官网地址:http://mozilla.gith ...