码迷,mamicode.com
首页 > 其他好文 > 详细

LNMP环境搭建

时间:2016-07-11 01:30:36      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:lnmp环境搭建

LNMP环境搭建

OS: CentOS6.7_x64

IP:192.168.1.101


软件列表:

nginx-1.10.0.tar.gz

php-5.5.35.tar.gz

mysql-5.5.50.tar.gz

libiconv-1.14.tar.gz

wordpress-4.5.2-zh_CN.tar.gz


软件下载目录为/opt

软件安装路径为/lnmp


=======nginx安装================

1 安装依赖包

yum install gcc pcre pcre-devel openssl openssl-devel


2 创建应用程序账号

groupadd nginx

useradd -M -g nginx -s /sbin/nologin nginx


3 下载nginx至/opt

cd /opt

wget http://nginx.org/download/nginx-1.10.0.tar.gz


4 安装nginx

tar zxvf nginx-1.10.0.tar.gz

cd nginx-1.10.0

./configure --user=nginx --group=nginx --prefix=/lnmp/nginx-1.10.0/

make

make install


5 检查配置

/lnmp/nginx/sbin/nginx –t


./sbin/nginx -t

nginx: the configuration file /lnmp/nginx-1.10.0//conf/nginx.conf syntax is ok

nginx: configuration file /lnmp/nginx-1.10.0//conf/nginx.conf test is successful


6 启动nginx

/lnmp/nginx/sbin/nginx


7 访问http://192.168.1.101


=======php安装================

1 安装PHP依赖包

yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libmcrypt-devel mhash


2 下载并安装libiconv

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

tar zxvf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make&&make install


3 下载并安装PHP-5.5.35

tar php-5.5.35.tar.gz

cd php-5.5.35

touch ext/phar/phar.php

ln -s /lnmp/mysql/lib/libmysqlclient.so.18 /usr/lib64/


./configure --prefix=/lnmp/php5.5.35 --with-mysql=mysqlnd --with-iconv-dir=/usr/local/libiconv/ --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-maintainer-zts --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curl=/usr/include/curl/ --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-opcache=no

make&&make install


4 按系统提示执行

/opt/php-5.5.35/build/shtool install -c ext/phar/phar.phar /lnmp/php5.5.35/bin

ln -s -f phar.phar /lnmp/php5.5.35/bin/phar


5 拷贝模板文件为php.ini

cd /opt/php-5.5.35/php.ini-production /lnmp/php5.5.35/lib/php.ini


6 拷贝php-fpm模板

cd /application/php/etc

cp /lnmp/php5.5.35/etc/php-fpm.conf.default /lnmp/php5.5.35/etc/php-fpm.conf


7 启动PHP服务

/lnmp/php5.5.35/sbin/php-fpm


8 查看php-fpm状态

 lsof -i :9000

COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

php-fpm 10184   root    7u  IPv4 130751      0t0  TCP localhost:cslistener (LISTEN)

php-fpm 10185 nobody    0u  IPv4 130751      0t0  TCP localhost:cslistener (LISTEN)

php-fpm 10186 nobody    0u  IPv4 130751      0t0  TCP localhost:cslistener (LISTEN)


9 nginx配置php

  在nginx.conf的server{}区段内,增加index.php首页并添加php解析字段

location / {

            root   html;

            index  index.php index.html index.htm;

        }


        location ~ .*\.(php|php5)?$ {

            root   html;

            index  index.php index.html index.htm;

            fastcgi_pass 127.0.0.1:9000;

            fastcgi_index index.php;

            include fastcgi.conf;

                }


10 创建index.php测试文件

echo "<?php phpinfo(); ?>"> index.php


11 修改nginx目录权限

chown -R nginx.nginx /lnmp/nginx-1.10.0/


12 访问测试

http://192.168.1.101/index.php

技术分享



=======mysql安装==================

1 安装依赖包

yum install cmake ncurses-devel libaio libaio-devel


2 创建mysql用户与组

groupadd mysql

useradd -M -s /sbin/nologin -g mysql mysql


3 解压编译安装,配置编译参数

tar zxvf mysql-5.5.50.tar.gz

cd mysql-5.5.50

cmake -DCMAKE_INSTALL_PREFIX=/lnmp/mysql-5.5.50 \

-DMYSQL_DATADIR=/lnmp/mysql-5.5.50/data \

-DMYSQL_UNIX_ADDR=/lnmp/mysql-5.5.50/data/mysqld.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=all \

-DWITH_READLINE=1 \

-DWITH_EMBEDDED_SERVER=1 \

-DENABLED_LOCAL_INFILE=1 \

-DENABLED_LOCAL_INFILE=ON \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

-DWITHOUT_FEDERATED_STORAGE_ENGINE=1 \

-DWITHOUT_ZLIB=bundled


make&&make install


4 创建my.cnf

/bin/cp /lnmp/mysql-5.5.50/support-files/my-small.cnf /etc/my.cnf 


5 配置启动脚本(由于采用源码编译,故无需修改启动文件默认路径)

cp /lnmp/mysql-5.5.50/support-files/mysql.server /etc/init.d/mysqld


6 初始化数据库

/lnmp/mysql-5.5.50/scripts/mysql_install_db --basedir=/lnmp/mysql-5.5.50/ --datadir=/lnmp/mysql-5.5.50/data --user=mysql


9 修改目录权限

chown -R mysql.mysql /lnmp/mysql-5.5.50/


7 启动数据库

/etc/init.d/mysqld start



8 设置mysql登录密码

mysqladmin -u root password 123456


9 查看mysql状态

lsof -i :3306

COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

mysqld  37929 mysql   10u  IPv4 200571      0t0  TCP *:mysql (LISTEN)


10 lnmp环境测试

    备份nginx站点目录下的文件

mv /lnmp/nginx-1.10.0/html/* /tmp/


11 下载wordpress-4.5.2-zh_CN.tar.gz至/opt并解压

    将解压目录下的全部文件内容拷贝至/lnmp/nginx-1.10.0/html/

cp -r /opt/wordpress/* /lnmp/nginx-1.10.0/html/


12 登录mysql创建数据库用户wordpress并授权

mysql> create database wordpress;

mysql> create user wordpress;

mysql> grant all on wordpress.* on wordpress@‘192.168.1.%‘ identified by ‘123456‘;

mysql> flush privileges;


13 创建新的workpress配置文件

cp /lnmp/nginx-1.10.0/html/wp-config-sample.php /lnmp/nginx-1.10.0/html/wp-config.php


14 修改wp-config.php数据库连接信息

define(‘DB_NAME‘, ‘wordpress‘);

define(‘DB_USER‘, ‘wordpress‘);

define(‘DB_PASSWORD‘, ‘123456‘);

define(‘DB_HOST‘, ‘192.168.1.101‘);


15 修改目录权限

chown -R nginx.nginx /lnmp/nginx-1.10.0/


16 验证nginx配置并重启web服务

/lnmp/nginx-1.10.0/sbin/nginx -t

/lnmp/nginx-1.10.0/sbin/nginx -s reload


17 登录安装wordpress

技术分享


18 访问wordpress站点

技术分享


至此,LNMP环境搭建完毕,测试通过。

本文出自 “Clark的运维” 博客,转载请与作者联系!

LNMP环境搭建

标签:lnmp环境搭建

原文地址:http://szcat.blog.51cto.com/665775/1813966

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!