lnmp环境搭建步骤

lnmp

l指linux下的操作系统
n指Nginx:Nginx是一个高性能的HTTP和反向代理服务器。
m指mysql:Mysql是一个小型关系型数据库管理系统。
p指php语言:PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。

四者共同组成一个免费、高效、扩展性强的网站服务系统。

一.mysql 源码编译

下载mysql安装包和cmake编译工具

解压mysql 安装包

[root@2048-3 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-boost-5.7.17.tar.gz
[root@2048-3 ~]# yum install cmake-2.8.12.2-4.el6.x86_64.rpm  -y
...
...
...
[root@2048-3 ~]# tar zxf mysql-boost-5.7.17.tar.gz  #解压mysql
[root@2048-3 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-5.7.17  mysql-boost-5.7.17.tar.gz



 
~       

创建安装路径,并进入解压路径,安装gcc编译器

[root@2048-3 ~]# mkdir /usr/local/lnmp
[root@2048-3 ~]# cd /root/mysql-5.7.17/
[root@2048-3 mysql-5.7.17]# ls
boost            dbug                 libmysql     rapid          testclients
BUILD            Docs                 libmysqld    README         unittest
client           Doxyfile-perfschema  libservices  regex          VERSION
cmake            extra                man          scripts        vio
CMakeLists.txt   include              mysql-test   sql            win
cmd-line-utils   INSTALL              mysys        sql-common     zlib
config.h.cmake   libbinlogevents      mysys_ssl    storage
configure.cmake  libbinlogstandalone  packaging    strings
COPYING          libevent             plugin       support-files
[root@2048-3 mysql-5.7.17]# yum install gcc -y

开始编译  (编译中断时需要删除文件 : CMakeCache.txt)

[root@2048-3 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0
[root@2048-3 mysql-5.7.17]# rm -fr CMakeCache.txt  

依次解决依赖性,直到不出错为止。

[root@2048-3 mysql-5.7.17]# yum install gcc  bison  ncurses-devel  gcc-c++  -y

-- Check size of wchar_t
-- Check size of wchar_t - done
-- Check size of wint_t
-- Check size of wint_t - done
-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH) 
CMake Error at cmake/readline.cmake:64 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:107 (FIND_CURSES)
  cmake/readline.cmake:197 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:483 (MYSQL_CHECK_EDITLINE)


-- Configuring incomplete, errors occurred!
See also "/root/mysql-5.7.17/CMakeFiles/CMakeOutput.log".
See also "/root/mysql-5.7.17/CMakeFiles/CMakeError.log".
[root@2048-3 mysql-5.7.17]# rm -fr CMakeCache.txt 
[root@2048-3 mysql-5.7.17]# yum install ncurses-devel  -y

......

......

开始安装 make  &&  make  install

lnmp环境搭建步骤_第1张图片

等待成功后,开始配置

复制配置文件,进行修改

[root@2048-3 support-files]# pwd
/usr/local/lnmp/mysql/support-files
[root@2048-3 support-files]# ls
magic           mysqld_multi.server  mysql.server
my-default.cnf  mysql-log-rotate
[root@2048-3 support-files]# cp my-default.cnf /etc/my.cnf
[root@2048-3 support-files]# vim /etc/my.cnf

lnmp环境搭建步骤_第2张图片

修改制定目录所有者与所有组

[root@2048-3 ~]# groupadd -g 27 mysql
[root@2048-3 ~]# useradd -u 27 -g 27 mysql
[root@2048-3 ~]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)
[root@2048-3 ~]# chown mysql.mysql /usr/local/lnmp/mysql  -R

配置环境变量

[root@2048-3 ~]# cd 
[root@2048-3 ~]# vim .bash_profile 
[root@2048-3 ~]# source .bash_profile 
[root@2048-3 ~]# cat .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin

export PATH

生成启动脚本

[root@2048-3 support-files]# ls
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@2048-3 support-files]# cp mysql.server /etc/init.d/mysqld
[root@2048-3 mysql]# chkconfig --add mysqld
[root@2048-3 mysql]# chkconfig mysqld on

创建data,修改用户和组

[root@2048-3 mysql]# pwd
/usr/local/lnmp/mysql
[root@2048-3 mysql]# ll
total 56
drwxr-xr-x.  2 mysql mysql  4096 Feb 20 11:40 bin
-rw-r--r--.  1 mysql mysql 17987 Nov 28  2016 COPYING
drwxr-xr-x.  2 mysql mysql  4096 Feb 20 11:40 docs
drwxr-xr-x.  3 mysql mysql  4096 Feb 20 11:40 include
drwxr-xr-x.  4 mysql mysql  4096 Feb 20 11:40 lib
drwxr-xr-x.  4 mysql mysql  4096 Feb 20 11:40 man
drwxr-xr-x. 10 mysql mysql  4096 Feb 20 11:40 mysql-test
-rw-r--r--.  1 mysql mysql  2478 Nov 28  2016 README
drwxr-xr-x. 28 mysql mysql  4096 Feb 20 11:40 share
drwxr-xr-x.  2 mysql mysql  4096 Feb 20 13:56 support-files
[root@2048-3 mysql]# mkdir data
[root@2048-3 mysql]# chown mysql.mysql data
[root@2048-3 mysql]# ls
bin      data  include  man         README  support-files
COPYING  docs  lib      mysql-test  share
[root@2048-3 mysql]# chown mysql data/ -R
[root@2048-3 mysql]# chgrp root . -R

初始化

[root@2048-3 support-files]# mysqld --user=mysql --initialize
2019-02-20T07:25:43.146228Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-02-20T07:25:43.146272Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2019-02-20T07:25:43.146277Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
...
...
...
@localhost: qY-Z:Gg/y6d<

[root@2048-3 support-files]# cd ..
[root@2048-3 mysql]# ls
bin      data  include  man         README  support-files
COPYING  docs  lib      mysql-test  share
[root@2048-3 mysql]# cd data/
[root@2048-3 data]# ls
auto.cnf        ibdata1      ib_logfile1  performance_schema
ib_buffer_pool  ib_logfile0  mysql        sys
[root@2048-3 data]#  # 密码 qY-Z:Gg/y6d<    



[root@2048-3 ~]# /etc/init.d/mysqld stop
Shutting down MySQL. SUCCESS! 
[root@2048-3 ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 

 

进入数据库修改密码

[root@2048-3 mysql]# mysql_secure_installation 

Securing the MySQL server deployment.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password:

选择 n 之后直接回车 

.......
.......
.......
 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : 

 ... skipping.
All done! 

mysql 配置完成,进入查看

[root@2048-3 mysql]# mysql -u root -predhat
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.17 Source distribution

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> show DATABASE;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DATABASE' at line 1
mysql> show DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
mysql> exit
Bye

二. 编译php

下载所需安装包:    php-5.6.35.tar.bz2

解压并进入解压目录

[root@2048-3 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-5.7.17  mysql-boost-5.7.17.tar.gz  php-5.6.35.tar.bz2
[root@2048-3 ~]# tar jxf php-5.6.35.tar.bz2 
[root@2048-3 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-5.7.17  mysql-boost-5.7.17.tar.gz  php-5.6.35  php-5.6.35.tar.bz2
[root@2048-3 ~]# cd php-5.6.35

进行编译,依次解决很多的依赖性.......。

[root@2048-3 php-5.6.35]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd --enable-mysqlnd --with-mysqyi=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
...
...
...
checking for atoll... yes
checking for strftime... (cached) yes
checking which regex library to use... php
checking whether to enable LIBXML support... yes
checking libxml2 install dir... yes
checking for xml2-config path... 
configure: error: xml2-config not found. Please check your libxml2 installation.

[root@2048-3 php-5.6.35]# yum install libxml2-devel -y   
#......
[root@2048-3 php-5.6.35]# yum install openssl-devel -y
#......
[root@2048-3 php-5.6.35]# yum install curl-devel -y
#......
[root@2048-3 php-5.6.35]# yum list gd
#
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Available Packages
gd.i686                                      2.0.35-11.el6                                    rhel-source
gd.x86_64                                    2.0.35-11.el6                                    rhel-source
[root@2048-3 php-5.6.35]# yum install gd.x86_64 -y
#......
[root@2048-3 php-5.6.35]# yum whatprovides */jpeglib.h
#
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
b/filelists_db                                                                    | 3.9 kB     00:00     
h/filelists_db                                                                    |  38 kB     00:00     
r/filelists_db                                                                    |  39 kB     00:00     
rhel-source/filelists_db                                                          | 3.8 MB     00:00     
s/filelists_db                                                                    | 3.0 kB     00:00     
libjpeg-turbo-devel-1.2.1-1.el6.x86_64 : Headers for the libjpeg-turbo library
Repo        : rhel-source
Matched from:
Filename    : /usr/include/jpeglib.h


libjpeg-turbo-devel-1.2.1-1.el6.i686 : Headers for the libjpeg-turbo library
Repo        : rhel-source
Matched from:
Filename    : /usr/include/jpeglib.h

[root@2048-3 php-5.6.35]#  yum install  -y libjpeg-turbo-devel-1.2.1-1.el6.x86_64 #同上

[root@2048-3 php-5.6.35]# yum install -y libpng-devel-1.2.49-1.el6_2.x86_64
#
[root@2048-3 php-5.6.35]# yum install -y freetype-devel-2.3.11-14.el6_3.1.x86_64 #寻找方法同上
[root@2048-3 php-5.6.35]# yum install -y gmp-devel-4.3.1-7.el6_2.2.x86_64  #同上

[root@2048-3 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm         mysql-5.7.17               php-5.6.35.tar.bz2
libmcrypt-2.5.8-9.el6.x86_64.rpm        mysql-boost-5.7.17.tar.gz  re2c-0.13.5-1.el6.x86_64.rpm
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm  php-5.6.35
[root@2048-3 ~]# yum install libmcrypt-2.5.8-9.el6.x86_64.rpm -y

[root@2048-3 ~]# yum install libmcrypt-devel-2.5.8-9.el6.x86_64.rpm -y

[root@2048-3 php-5.6.35]# yum install -y net-snmp-devel

make && make install     进行安装

配置步骤

[root@2048-3 etc]# pwd
/usr/local/lnmp/php/etc
[root@2048-3 etc]# ls
pear.conf  php-fpm.conf.default
[root@2048-3 etc]# cp php-fpm.conf.default php-fpm.conf
[root@2048-3 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default
[root@2048-3 etc]# cd php-fpm.conf

[root@2048-3 etc]# cd /root/php-5.6.35
[root@2048-3 php-5.6.35]# cp php.ini-production /usr/local/lnmp/php/etc/php-ini
[root@2048-3 php-5.6.35]# cd /usr/local/lnmp/php/etc/
[root@2048-3 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php-ini
[root@2048-3 etc]# vim php-ini # 修改时区

打开配置文件的PID

[root@2048-3 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php-ini
[root@2048-3 etc]# vim php-fpm.conf
[root@2048-3 etc]# pwd
/usr/local/lnmp/php/etc

lnmp环境搭建步骤_第3张图片

添加启动脚本,添加执行权限。

[root@2048-3 etc]# cd ~/php-5.6.35/sapi/fpm/
[root@2048-3 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@2048-3 fpm]# chmod +x /etc/init.d/php-fpm 

三. nginx 编译安装

下载安装包并解压

进入目录,关闭版本号,提高安全性。 关闭debug 日志,防止占用大量储存空间。

[root@2048-3 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm         nginx-1.14.0.tar.gz
libmcrypt-2.5.8-9.el6.x86_64.rpm        php-5.6.35
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm  php-5.6.35.tar.bz2
mysql-5.7.17                            re2c-0.13.5-1.el6.x86_64.rpm
mysql-boost-5.7.17.tar.gz
[root@2048-3 ~]# ### nginx-1.14.0.tar.gz 
[root@2048-3 ~]# tar zxf nginx-1.14.0.tar.gz 
[root@2048-3 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm         nginx-1.14.0
libmcrypt-2.5.8-9.el6.x86_64.rpm        nginx-1.14.0.tar.gz
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm  php-5.6.35
mysql-5.7.17                            php-5.6.35.tar.bz2
mysql-boost-5.7.17.tar.gz               re2c-0.13.5-1.el6.x86_64.rpm
[root@2048-3 ~]# cd nginx-1.14.0
[root@2048-3 nginx-1.14.0]# vim  src/core/nginx.h  #隐藏
[root@2048-3 nginx-1.14.0]# vim auto/cc/gcc #debug

vim  src/core/nginx.h

lnmp环境搭建步骤_第4张图片

 vim auto/cc/gcc

lnmp环境搭建步骤_第5张图片

开始编译和安装

 [root@2048-3 nginx-1.14.0]#./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio --user=nginx --group=nginx
...
...
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library



[root@2048-3 nginx-1.14.0]# yum install -y pcre-devel      #解决依赖性

 

[root@2048-3 nginx-1.14.0]# make && make install

nginx 简单配置

[root@2048-3 nginx-1.14.0]# cd /usr/local/lnmp/nginx/
[root@2048-3 nginx]# ls
conf  html  logs  sbin
[root@2048-3 nginx]# vim conf/nginx.conf

设置和模块很多,这里先打开与php 的连接,和默认发布。

lnmp环境搭建步骤_第6张图片

lnmp环境搭建步骤_第7张图片

设置环境变量和软连接

[root@2048-3 sbin]# ln -s  nginx /usr/local/sbin/  #软连接
[root@2048-3 sbin]# cd 
[root@2048-3 ~]# vim .bash_profile 
[root@2048-3 ~]# pwd
/root
[root@2048-3 ~]#  #vim .bash_profile   添加环境变量
[root@2048-3 ~]# source .bash_profile   #刷新

lnmp环境搭建步骤_第8张图片

[root@2048-3 ~]# source .bash_profile   #刷新
[root@2048-3 ~]# nginx -t               #监测语法
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@2048-3 ~]# 

关闭防火墙,测试nginx 页面,

[root@2048-3 ~]# nginx 
[root@2048-3 ~]# nginx -s reload #重新加载
[root@2048-3 ~]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 52:54:00:61:AA:4F  
          inet addr:172.25.42.3  Bcast:172.25.42.255  Mask:255.255.255.0
          inet6 addr: fe80::5054:ff:fe61:aa4f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10671 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8148 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5624660 (5.3 MiB)  TX bytes:5273412 (5.0 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
...
...
[root@2048-3 ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@2048-3 ~]# 

lnmp环境搭建步骤_第9张图片

 

四 .加入 php 页面

[root@2048-3 ~]# cd /usr/local/lnmp/nginx/html/
[root@2048-3 html]# ls
50x.html  index.html
[root@2048-3 html]# vim index.php
[root@2048-3 html]# nginx -s reload

lnmp环境搭建步骤_第10张图片

/etc/init.d/php-fpm  start            #开启php

nginx -s reload                          #重载nginx 服务

测试:

 

lnmp环境搭建步骤_第11张图片

 

 

 

 

 

你可能感兴趣的:(企业)