lnmp oracle,搭建LNMP经验分享

花了一个礼拜总算是搭建了lnmp集群(也就是传统的web网站架构),下面就来分享一下,搭建的过程,以及遇到的各种坑。

A.首先先搭建nginx服务:

1.先安装pcre(伪静态)库

yum install pcre pcre-devel -y

2.在普通用户的家目录下面创建一个tools目录(这个目录是用来放软件的)

mkdir -p /home/oldboy/tools

3.进入到nginx官方网站http://nginx.org/,下载nginx

wget -q http://nginx.org/download/nginx-1.6.3.tar.gz

4.解压软件包

tar xf nginx-1.6.3.tar.gz

5.创建www用户

useradd www -s /sbin/nologin -M

6.安装openssl

yum install openssl openssl-devel -y

7.配置文件的安装

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

假如配置的时候出现以下问题:./configure --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --prefix=/application/nginx-1.6.3/

checking for OS

+ Linux 2.6.32-573.el6.i686 i686

checking for C compiler ... not found

./configure: error: C compiler cc is not found

是因为没有安装yum -y install gcc

8.编译安装nginx

make

make install

9.为/application/nginx-1.6.3这个目录创建一个软链接

ln -s /application/nginx-1.6.3/ /application/nginx

10.启动并检查安装结果

/application/nginx/sbin/nginx 启动nginx

ps -ef|grep "nginx"

netstat -lntup|grep 80

lsof -i :80

/application/nginx/sbin/nginx -t  检查nginx语法是否出错

/application/nginx/sbin/nginx -V 查看版本已经安装的详细情况

[root@VM_185_169_centos application]# /application/nginx/sbin/nginx

nginx: [alert] could not open error log file: open() "/application/nginx-1.6.3//logs/error.log" failed (2: No such file or directory)

2017/04/18 21:00:12 [emerg] 5735#0: open() "/application/nginx-1.6.3//logs/access.log" failed (2: No such file or directory)

当启动nginx的时候,出现以上报错时,没有logs和里面的日志文件,需要重新创建一个

B.安装mysql数据库

1.下载软件

wget -q http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

2.解压移动

tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

mkdir -p /application

mv mysql-5.6.35-linux-glibc2.5-x86_64 /application/mysql-5.6.35

3.创建用户并授权

useradd -s /sbin/nologinx -M mysql

chown -R mysql.mysql /application/mysql-5.6.35/

4.初始化数据库

cd /application/mysql-5.6.35/

cp support-files/my-default.cnf /etc/my.cnf

/scripts/mysql_install_db --basedir=/application/mysql-5.6.35/ --datadir=/application/mysql-5.6.35/data/ --user=mysql

5.并更改mysql默认配置里面的默认路径(因为笔者使用的是自己的路径)

sed -i 's#/usr/local/mysql#/application/mysql-5.6.35#g' /application/mysql-5.6.35//bin/mysqld_safe

6.启动登陆并且加入PATH路径

/application/mysql-5.6.35//bin/mysqld_safe &

lsof -i :3306

PATH="/application/mysql-5.6.35/bin/:$PATH"

echo "PATH="/application/mysql-5.6.35/bin/:$PATH"" >>/etc/profile

7.简化mysql启动

sed -i 's#/usr/local#/application#g' support-files/mysql.server

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

chmod +x /etc/init.d/mysqld

/etc/init.d/mysqld stop

/etc/init.d/mysqld start

8.并加入开机自启动

chkconfig --add mysqld

chkconfig --list mysqld

9.登陆并测试

[root@oldboy mysql-5.6.35]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.35 MySQL Community Server (GPL)

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

Oracle is a registered 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> select version();

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

| version() |

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

| 5.6.35    |

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

1 row in set (0.00 sec)

mysql> create database oldboy;

Query OK, 1 row affected (0.00 sec)

mysql> create database oldgirl;

Query OK, 1 row affected (0.00 sec)

mysql> show databases like 'old%';

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

| Database (old%) |

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

| oldboy          |

| oldgirl         |

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

2 rows in set (0.00 sec)

C.PHP安装

1.安装PHP基础库

yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel libpng-devel gd-devel libcurl-devel libxslt-devel

2.查看PHP基础库是否安装完成

rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel libpng-devel gd-devel libcurl-devel libxslt-devel

libxml2-devel-2.7.6-21.el6_8.1.x86_64

gd-devel-2.0.35-11.el6.x86_64

zlib-devel-1.2.3-29.el6.x86_64

libxslt-devel-1.1.26-2.el6_3.1.x86_64

libcurl-devel-7.19.7-53.el6_9.x86_64

libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64

freetype-devel-2.3.11-17.el6.x86_64

libpng-devel-1.2.49-2.el6_7.x86_64

3.yum安装的时候,这个包libiconv-devel是没有的,所有需要另外安装

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

tar xf libiconv-1.14.tar.gz

cd libiconv-1.14

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

make

make install

4.下载epel源,并安装PHP相关扩展库

yum install -y libmcrypt-devel

yum install -y mhash

yum install -y mcrypt

5.确认PHP扩展库是否安装正确

rpm -qa mcrypt mhash libmcrypt-devel

6.编译安装PHP5.5.32(这个是有mysql数据库的情况下)

cd /home/oldboy/tools/

#上传php包

tar xf php-5.5.32.tar.gz

cd php-5.5.32

./configure \

--prefix=/application/php5.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

这个是没有mysql的情况下

./configure \

--prefix=/application/php5.5.32 \

--enable-mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-mysqli=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

7.防止等会编译安装的时候出错

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

touch ext/phar/phar.phar

8.开始编译安装并创建软链接,以及启动php

make

make install

9.创建软链接

ln -s /application/php5.5.32/ /application/php

10.配置PHP解析文件

cd /home/oldboy/tools/

cp php.ini-production /application/php/lib/php.ini

11.配置php-fpm配置文件

cd /application/php/etc/

cp php-fpm.conf.default php-fpm.conf

12.启动php

/application/php/sbin/php-fpm

13.检查进程和端口

ps -fe |grep php-fpm

lsof -i:9000

至此LNMP环境搭建完成,谢谢大家

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值