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

等待成功後,開始配置

複製配置文件,進行修改

[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

修改制定目錄所有者與所有組

[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

添加啓動腳本,添加執行權限。

[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

 vim auto/cc/gcc

開始編譯和安裝

 [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 的連接,和默認發佈。

設置環境變量和軟連接

[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   #刷新

[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 ~]# 

 

四 .加入 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

/etc/init.d/php-fpm  start            #開啓php

nginx -s reload                          #重載nginx 服務

測試:

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章