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

/tmp/php-fcgi.sock这一行要改成这样,这里这样修改了以后,在配置nginx的时候就需要注意这个路径了。
修改用户和组的名称为”www” 
去掉注释,改成这样:
Unix user of processes
www
                        Unix group of processes
www

/usr/local/php/sbin/php-fpm start

其他关于php的扩展模块安装请参考:

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
# chk
conf
ig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
#
Nginx
Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/var/nginx.pid"
RETVAL=0
prog="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
}
config
test
(){
    $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=1
esac
exit $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

写入如下内容:

phpinfo();
?>

然后设定hosts文件,访问 www.92csz.com/1.php 看是否能解析出这个页面。

linux的基本操作(LNMP的基本操作)的更多相关文章

  1. Linux 目录结构及文件基本操作

    Linux 目录结构及文件基本操作 实验介绍 1.Linux 的文件组织目录结构. 2.相对路径和绝对路径. 3.对文件的移动.复制.重命名.编辑等操作. 一.Linux 目录结构 在讲 Linux ...

  2. 实验楼学习linux第一章第四节linux目录结构及文件基本操作

    linux目录结构及文件基本操作 常用命令 切换目录 cd 当前目录 . 上一级目录 .. (.和..开头的都是隐藏文件) 查看隐藏文件 ls -a 上一级所在目录 - 当前用户home目录 ~ 获取 ...

  3. linux用户管理-用户的基本操作

    目录 linux用户管理-用户的基本操作 用户相关的命令 linux用户管理-用户的基本操作 什么是用户 用户指能够正常登录linux或windows系统 区别 本质都是登录系统的,只不过Linux支 ...

  4. linux下安装lnmp集成环境

    linux下安装lnmp集成环境 教程地址:https://www.cnblogs.com/peteremperor/p/6750204.html 必须要用root用户,否则权限不够无法安装 安装最新 ...

  5. Linux一键安装LNMP环境

    Linux一键安装LNMP环境 官方地址:https://lnmp.org/. 参考安装步骤:https://lnmp.org/install.html. 一键安装可以选择mysql版本.php版本, ...

  6. linux下MongoDB客户端shell基本操作

    MongoDB 是一款NoSql数据库,没有固定的模式,即同一个集合中的不同文档结构可以不同,如:第一条记录{name:”xiaoming”},第二条记录:{name:”xiaoli”,age:15} ...

  7. Linux 用户与组的基本操作及文件权限位的设置方法

    用户的基本操作 添加用户: useradd xxx 查看所有的用户: cat /etc/passwd 用户更改组: usermod -G groups loginname 将用户从组中删除: gpas ...

  8. 第四节 Linux目录文件及文件基本操作

    一.Linux目录结构 Linux 的目录与 Windows 的目录的区别: 一种不同是体现在目录与存储介质(磁盘,内存,DVD 等)的关系上,以往的 Windows 一直是以存储介质为主的,主要以盘 ...

  9. linux进程地址空间--vma的基本操作【转】

    转自:http://blog.csdn.net/vanbreaker/article/details/7855007 版权声明:本文为博主原创文章,未经博主允许不得转载. 在32位的系统上,线性地址空 ...

随机推荐

  1. Git远程仓库地址变更本地如何修改

    以项目test为例: 老地址:http://192.168.1.1:9797/john/test.git 新地址:http://git.xxx.xxx/john/test.git 远程仓库名称: or ...

  2. [Canvas]空战游戏 已经可以玩了 1.13Playable

    空战游戏做到这里,己方运动,己方发射子弹,敌方运动,敌方发射子弹,子弹与飞机碰撞,飞机与飞机碰撞都已经具备了,换言之已经可以玩了. 还需要一个奖励升级系统,在上面显示击落敌机数量等,还有己方不幸被击落 ...

  3. 【纵谭 Python】系列直播(持续更新)

    老周最近录了一些跟 Python 有关的直播,可以在“一直播”中搜索 ID 号 139251129 关注,也可以在微博中查看,反正都一样,同步的. 第一集:简单胡扯一下相关环境搭建.安装 Python ...

  4. Webdings字体和Wingdings字体对照表

    一.Webdings是一个TrueType的dingbat字体,于1997年发表,搭载在其后的Microsoft Windows视窗系统内,大多的字形都没有Unicode的相对字. 使用很简单1.网页 ...

  5. angualrjs 配置超时时间

    timeout 1 本想通过$httpProvider的defaults属性配置timeout时间, defaults中没有这个属性. https://docs.angularjs.org/api/n ...

  6. 对Rethinking ImageNet Pre-training的理解

    Kaiming He的这篇论文提出了一个新问题,在目标检测.实例分割和人体关键点检测等领域,预训练的模型是否真的起了作用?通过实验,得出结论:迭代次数较少时,使用预训练模型效果更好:但是只要迭代次数充 ...

  7. GPL、BSD、MIT、Mozilla、Apache、LGPL开源协议介绍

    BSD开源协议 BSD开源协议是一个给于使用者很大自由的协议.基本上使用者可以”为所欲为”,可以自由的使用,修改源代码,也可以将修改后的代码作为开源或者专有软件再发布. 但”为所欲为”的前提当你发布使 ...

  8. hdu 3068 最长回文(manacher&最长回文子串)

    最长回文 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  9. Atitit php java python nodejs错误日志功能的比较

    Atitit php  java  python  nodejs错误日志功能的比较 1.1. Php方案 自带 1 1.2. Java解决方案 SLF4J 1 1.3. Python解决方案 自带lo ...

  10. Session 在分布式系统中实现方式

    ##server独立Session 例如以下图所看到的: server独立Session要求用户的每次请求都必须在同一台应用server上面操作,这就要求负载均衡server每次都能把用户的请求发送到 ...