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

LNMP搭建

时间:2017-09-14 18:50:50      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:lnmp安装

一.  安装nginx

1.1查看系统环境

[root@localhosttools]# cat /etc/redhat-release

CentOSrelease 6.9 (Final)

[root@localhosttools]# uname -a

Linuxlocalhost 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017 x86_64x86_64 x86_64 GNU/Linux

1.2创建文件存放目录

[root@localhost~]# mkdir /server/tools –p

1.3下载ngin-1.10.3安装包

[root@localhosttools]# wget -q http://nginx.org/download/nginx-1.10.3.tar.gz

[root@localhosttools]# ls -l

total 892

-rw-r--r-- 1root root 911509 Jan 31  2017nginx-1.10.3.tar.gz

1.4 安装依赖包

yum install -y pcre-devel openssl-devel

1.5解压Nginx

[root@localhosttools]# tar xf nginx-1.10.3.tar.gz

[root@localhosttools]# cd nginx-1.10.3

1.6设置nginx管理用户www.

[root@localhostnginx-1.10.3]# useradd www -s /sbin/nologin –M

1.7编译安装Nginx.

./configure --prefix=/application/nginx-1.10.3--user=www --group=www --with-http_stub_status_module --with-http_ssl_module

make&& make install

1.8创建Nginx软链接

[root@localhostnginx-1.10.3]# ln -s /application/nginx-1.10.3/ /application/nginx

[root@localhostnginx-1.10.3]# ln -s /application/nginx/sbin/nginx /usr/sbin/ #可以在任意目录执行Nginx启动命令

1.9启动Nginx

[root@localhostnginx-1.10.3]# nginx

[root@localhostnginx-1.10.3]# ps -ef|grep nginx

root       3722     1  0 08:24 ?        00:00:00 nginx: master process nginx

www        3723  3722  0 08:24 ?        00:00:00 nginx: worker process

root       3728  1247  0 08:25 pts/0    00:00:00 grep nginx

1.10    查看启动情况

在浏览器输入服务器的ip地址,返回下面界面代表Nginx安装成功。

技术分享


.mysql安装

2.1/server/tools/上传mysql安装包

[root@localhosttools]# ls

libiconv-1.14.tar.gz                       nginx-1.10.3         php-5.5.32.tar.gz

mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz  nginx-1.10.3.tar.gz  wordpress-4.7.3-zh_CN.tar.gz

2.2解压安装包

[root@localhosttools]# tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

2.3添加mysql程序运行时的管理用户

[root@localhosttools]# useradd mysql -s /sbin/nologin –M

2.4mysql解压后的程序包搬家到程序目录下,并进行重命名

[root@localhosttools]# mkdir -p /application/

[root@localhosttools]# mv /server/tools/mysql-5.6.34-*-x86_64 /application/mysql-5.6.34

2.5 mysql服务程序创建软链接

[root@localhosttools]#  ln -s /application/mysql-5.6.34//application/mysql

2.6 mysql用户管理 /application/mysql/

[root@localhosttools]# chown -R mysql.mysql /application/mysql/data

2.7初始化数据库

[root@localhosttools]# /application/mysql/scripts/mysql_install_db--basedir=/application/mysql --datadir=/application/mysql/data --user=mysql

注意:此过程中出现两个OK为安装成功

2.8复制启动脚本授权

[root@localhosttools]# cp /application/mysql/support-files/mysql.server  /etc/init.d/mysqld

[root@localhosttools]# chmod +x /etc/init.d/mysqld

2.9修改启动脚本 mysql命令中的路径

[root@localhosttools]#  sed -i‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe/etc/init.d/mysqld

2.10复制默认的配置文件

[root@localhosttools]#  \cp/application/mysql/support-files/my-default.cnf /etc/my.cnf

2.11启动mysql服务

[root@localhosttools]# /etc/init.d/mysqld start

StartingMySQL..... SUCCESS!

[root@localhosttools]# ps -ef|grep mysql

root       3818     1  0 08:43 pts/0    00:00:00 /bin/sh/application/mysql/bin/mysqld_safe --datadir=/application/mysql/data--pid-file=/application/mysql/data/localhost.pid

mysql      3934  3818  4 08:43 pts/0    00:00:01 /application/mysql/bin/mysqld--basedir=/application/mysql --datadir=/application/mysql/data--plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/application/mysql/data/localhost.err--pid-file=/application/mysql/data/localhost.pid

2.12创建登录mysql的软链接

[root@localhosttools]# echo ‘export PATH=/application/mysql/bin:$PATH‘ >>/etc/profile

[root@localhosttools]# source /etc/profile

[root@localhosttools]# which mysql

/application/mysql/bin/mysql

2.13登录mysql设置mysql密码

[root@localhosttools]# mysql #登录mysql

Welcome tothe MySQL monitor.  Commands end with ;or \g.

Your MySQLconnection id is 1

Serverversion: 5.6.34 MySQL Community Server (GPL)

 

Copyright (c)2000, 2016, Oracle and/or its affiliates. All rights reserved.

 

Oracle is aregistered trademark of Oracle Corporation and/or its

affiliates.Other names may be trademarks of their respective

owners.

 

Type ‘help;‘or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

 

mysql>

 

[root@localhosttools]# mysqladmin -uroot password oldboy123#在命令行设置

Warning:Using a password on the command line interface can be insecure.

[root@localhosttools]# mysql -u root -poldboy123 #通过密码登录

Warning: Usinga password on the command line interface can be insecure.

Welcome tothe MySQL monitor.  Commands end with ;or \g.

Your MySQLconnection id is 3

Serverversion: 5.6.34 MySQL Community Server (GPL)

 

Copyright (c)2000, 2016, Oracle and/or its affiliates. All rights reserved.

 

Oracle is aregistered trademark of Oracle Corporation and/or its

affiliates.Other names may be trademarks of their respective

owners.

 

Type ‘help;‘or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

 

mysql>

三.  Php5.5.32安装

3.1安装依赖包

[root@localhosttools]# yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devellibiconv-devel –y

[root@localhosttools]# yum install freetype-devel libpng-devel gd-devel libcurl-devellibxslt-devel libxslt-devel –y

cd /server/tools

tar zxf libiconv-1.14.tar.gz

[root@localhosttools]# cd libiconv-1.14

[root@localhostlibiconv-1.14]# ./configure --prefix=/usr/local/libiconv

[root@localhostlibiconv-1.14]# make && make install

安装与加密相关的3个软件

wget -O /etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-6.repo

[root@localhostlibiconv-1.14]# yum -y install libmcrypt-devel mhash mcrypt

3.2解压安装php

[root@localhost tools]# tar xf php-5.5.32.tar.gz

[root@localhost tools]# cd php-5.5.32

./configure \
--prefix=/application/php-5.5.32 \
--with-mysql=/application/mysql/ \
--with-pdo-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-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-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-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftp \
--enable-opcache=no

为防止在make时报错做一下操作

[root@localhost php-5.5.32]# ln -s /application/mysql/lib/libmysqlclient.so.18  /usr/lib64/

[root@localhost php-5.5.32]# touch ext/phar/phar.phar

[root@localhost php-5.5.32]# make && makeinstall

ln -s -f phar.phar /application/php-5.5.32/bin/phar

Installing PDO headers:          /application/php-5.5.32/include/php/ext/pdo/

3.3php做软链接

[root@localhost php-5.5.32]#  ln -s /application/php-5.5.32//application/php

3.4配置php解析文件/配置php-fpm配置文件

[root@localhost php-5.5.32]# cd/server/tools/php-5.5.32

[root@localhost php-5.5.32]# cp php.ini-production/application/php/lib/php.ini

php.ini-production 与 php.ini-development 文件区别关系对比

扩展:文件比较命令 diff zdiff vimdiff windows上的文件比较

[root@localhost php-5.5.32]# cd /application/php/etc/

[root@localhost etc]# cp php-fpm.conf.defaultphp-fpm.conf

3.5启动php-fpm程序

[root@localhost etc]# /application/php/sbin/php-fpm

[root@localhost etc]# lsof -i:9000

COMMAND    PIDUSER   FD   TYPE DEVICE SIZE/OFF NODE NAME

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

php-fpm 125952 www    0u  IPv4 125162      0t0 TCP localhost:cslistener (LISTEN)

php-fpm 125953 www    0u  IPv4 125162      0t0 TCP localhost:cslistener (LISTEN)

四.配置nginx+php

 

[root@localhost conf]# egrep -v "#|^$"nginx.conf.default >nginx.conf

[root@localhost conf]# vim nginx.conf

worker_processes 1;

events {

   worker_connections  1024;

}

http {

    include       mime.types;

   default_type application/octet-stream;

   sendfile        on;

   keepalive_timeout  65;

    includeextra/blog.conf;

}

[root@localhost ~]# cd /application/nginx/conf/

[root@localhost conf]# mkdir extra

[root@localhost conf]# cd extra/

[root@localhost extra]# vim blog.conf

server {

       listen       80;

       server_name  blog.bai.com;

        location/ {

           root   html/blog;

           index  index.php index.htmlindex.htm;

        }

       error_page   500 502 503 504  /50x.html;

        location= /50x.html {

           root   html;

        }

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

                  root html/blog;

                  fastcgi_pass  127.0.0.1:9000;

                  fastcgi_index index.php;

                  include fastcgi.conf;

       }

 }

检查语法重启Nginx.

[root@localhost extra]# nginx -t

nginx: the configuration file /application/nginx-1.10.3/conf/nginx.confsyntax is ok

nginx: configuration file/application/nginx-1.10.3/conf/nginx.conf test is successful

[root@localhost extra]# nginx -s reload

在windows本地做域名解析

10.0.0.152  blog.bai.org

技术分享

[root@localhost blog]# pwd

/application/nginx/html/blog

[root@localhost blog]# cat test_info.php

<?php phpinfo(); ?>

访问网页:http://blog.bai.org/test_info.php,出现下面网页即成功。

技术分享

五.配置nginx连接数据库

[root@localhost blog]# cat test_mysql.php

<?php

//$link_id=mysql_connect(‘主机名‘,‘用户‘,‘密码‘);

//mysql -u用户 -p密码 -h 主机

$link_id=mysql_connect(‘localhost‘,‘root‘,‘oldboy123‘)or mysql_error();

if($link_id){

            echo "mysql successful by root !\n";

           }else{

            echo mysql_error();

            }

?>

[root@localhost blog]# /etc/init.d/mysqld start

Starting MySQL..... SUCCESS!

访问网页,出现下面界面。表示连接成功。

技术分享

六.wordpress博客搭建

6.1解压安装wordpress安装包

[root@localhost blog]# cd /server/tools/

[root@localhost tools]# tar xfwordpress-4.7.3-zh_CN.tar.gz

[root@localhost tools]# cd wordpress

[root@localhost wordpress]# ls

index.php   wp-activate.php    wp-comments-post.php wp-cron.php        wp-load.

license.txt wp-admin           wp-config-sample.php wp-includes        wp-login

readme.html wp-blog-header.php wp-content           wp-links-opml.php  wp-mail.

[root@localhost wordpress]# mv ./*/application/nginx/html/blog/

[root@localhost wordpress]# chown -R www.www/application/nginx/html/blog/

6.2创建数据库和管理账号

[root@localhost wordpress]# mysql -u root -poldboy123-e "create database wordpress;"

Warning: Using a password on the command lineinterface can be insecure.

[root@localhost wordpress]# mysql -u root -poldboy123-e "show databases;"

Warning: Using a password on the command lineinterface can be insecure.

+--------------------+

| Database          |

+--------------------+

| information_schema |

| mysql             |

| performance_schema |

| test              |

| wordpress         |

+--------------------+

[root@localhost wordpress]# mysql -u root -poldboy123-e "grant all on wordpress.* to wordpress@‘10.0.0.%‘ identified by‘oldboy123‘;"

Warning: Using a password on the command lineinterface can be insecure.

[root@localhost wordpress]# mysql -u root -poldboy123-e "flush privileges;"

6.3设置wordpress

6.3.1通过浏览器访问blog.bai.org。输入设置的数据库和主机信息

技术分享

6.3.2信息输入正确就会到下面这一步,点击进行安装即可。

技术分享

6.3.3设置用户名和密码

技术分享

6.3.4出现下面的界面,代表安装成功。

技术分享

 

 

 

 


本文出自 “10997527” 博客,请务必保留此出处http://11007527.blog.51cto.com/10997527/1965201

LNMP搭建

标签:lnmp安装

原文地址:http://11007527.blog.51cto.com/10997527/1965201

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