LNMP环境搭建

环境:  CentOS6.5(L)  Nginx1.10.1 (N)  MySQL(M)  PHP(P)     在MacOS下进行搭建

使用Docker搭建CentOS 环境

使用Docker搭建CentOS环境,Docker使用自行学习

$ docker pull index.docker.io/library/centos //(拉取CentOS镜像)

$ docker run -v /Users/arnoma2015/Downloads:/data/ --name mysql-study -i -t centos /bin/bash //( 启动容器,并挂载本机/Users/arnoma2015/Downloads目录,该目录存放共享的数据)

安装Nginx服务器

下载最新稳定版Nginx

http://nginx.org/en/download.html

nginx需要依赖zlib、pcre、openssl等库 参考:
http://www.cnblogs.com/skynet/p/4146083.html

另外如果没有安装开发工具包,请通过yum安装,如下

yum groupinstall -y “Development Tools”

编译安装nginx

$ cp /data/nginx-1.10.1.tar.gz  // 移动至/opt目录

$ cd /opt

$ tar -xzvf  nginx-1.10.1.tar.gz  //解压文件

$ cd nginx-1.10.1

$ ./configure

$ make & make install

$ cd /usr/local/nginx/sbin

$ ./nginx  (启动nginx)

我启动时出现了错误,如下图屏幕快照 2016-08-15 上午11.16.44

解决方案:cp /usr/local/lib64/libcrypto.so.1.1 /lib64 重新启动

检查是否启动成功

$ curl localhost  

=========如果有以下数据输出则安装成功==========

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href=”http://nginx.org/”>nginx.org</a>.<br/>
Commercial support is available at
<a href=”http://nginx.com/”>nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

添加nginx开机自启动

方法 :/etc/rc.local
这是一个最简单的方法,编辑“/etc/rc.local”,把启动程序的shell命令输入进去即可(要输入命令的全路径),类似于windows下的“启动”。

使用命令 vi /etc/rc.local

然后在文件最后一行添加要执行程序的全路径。

例如,每次开机时要执行一个haha.sh,这个脚本放在/opt下面,那就可以在“/etc/rc.local”中加一行“/opt/./haha.sh”,或者两行“cd /opt”和“./haha.sh”。

本例中: /usr/local/nginx/sbin/nginx

MySQL安装与配置

请移步我的CSDN博客:
http://blog.csdn.net/u012535312/article/details/52127798

PHP安装与配置

下载PHP二进制压缩包

http://php.net/get/php-5.6.24.tar.gz/from/a/mirror

首先通过yum安装PHP依赖的库

$ yum install libxml2-devel openssl-devel bzip2-devel libmcrypt-devel -y

源码编译PHP

$ cp /data/php-5.6.24.tar.gz  /opt

$ cd /opt

$ tar -xzvf php-5.6.24.tar.gz

$ cd php-5.6.24

$ ./configure –prefix=/usr/local/php –with-mysql=mysqlnd –with-pdo-mysql=mysqlnd –with-mysqli=mysqlnd –enable-mbstring –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –enable-sockets –enable-fpm –with-mcrypt –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-bz2 –enable-opcache=no

如果遇到如下问题: configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决方法: 手动编译安装libmcrypt

下载地址https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download

$ make & make install

$ cp php.ini-production /etc/php.ini   //设置配置文件 配置php-fpm

$ cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

$ chmod +x /etc/rc.d/init.d/php-fpm

$ chkconfig –add php-fpm

$ chkconfig php-fpm on

$ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

$ service php-fpm start

配置fastcgi_params

/usr/local/nginx/conf/fastcgi_params

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

PHP only, required if PHP was built with –enable-force-cgi-redirect

fastcgi_param  REDIRECT_STATUS    200;

配置nginx 虚拟主机

/usr/local/nginx/config/nginx.conf

//取消注释
server{
    location / {
            root   html;
            index  index.html index.htm index.php;
        }
     location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
}

测试

$ curl localhost

打印phpinfo()的信息

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值