lnmp

本文详细介绍如何从零开始在Linux环境下安装Nginx、MySQL及PHP,包括各组件的源码编译安装步骤、配置文件调整及常见错误解决方法。

lnmp = linux + nginx + mysql + php/python

mysql 源码安装

[root@server1 ~]# mkdir /var/local/lnmp

[root@server1 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-boost-5.7.17.tar.gz
[root@server1 ~]# yum install cmake-2.8.12.2-4.el6.x86_64.rpm

[root@server1 ~]# yum install gcc gcc-c++

[root@server1 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-boost-5.7.17.tar.gz
[root@server1 ~]# tar -zxf mysql-boost-5.7.17.tar.gz 
[root@server1 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-5.7.17  mysql-boost-5.7.17.tar.gz
[root@server1 ~]# cd mysql-5.7.17/
[root@server1 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@server1 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

-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql  ##指定目录
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data    ##指定数据库路径
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock  ##Unix socket 存放路径
-DWITH_MYISAM_STORAGE_ENGINE=1      ##安装 myisam 存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1    ##安装 innodb 存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1   ##安装数据库分区
-DDEFAULT_CHARSET=utf8          ##使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci ##校验字符
-DEXTRA_CHARSETS=all            ##安装所有扩展字符集
-DWITH_BOOST=boost/boost_1_59_0/    ##指定 boost 路径
依赖软件。按照提示安装。
[root@server1 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

CMake Error at cmake/boost.cmake:81 (MESSAGE):
  You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>


[root@server1 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/

  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):

[root@server1 mysql-5.7.17]# rm -rf CMakeCache.txt
[root@server1 mysql-5.7.17]# yum install ncurses-devel

[root@server1 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/

CMake Warning at cmake/bison.cmake:20 (MESSAGE):
  Bison executable not found in PATH

[root@server1 mysql-5.7.17]# yum install bison
[root@server1 mysql-5.7.17]# rm -rf CMakeCache.txt

[root@server1 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/
make && make install
  • 初始化:

[root@server1 mysql-5.7.17]# cd /usr/local/lnmp/mysql/

[root@server1 mysql]# cd support-files/
[root@server1 support-files]# ls
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@server1 support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@server1 support-files]# vim /etc/my.cnf  配置一下

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

[root@server1 support-files]# groupadd -g 27 mysql
[root@server1 mysql]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/data -s /sbin/nologin mysql
[root@server1 mysql]# cd bin/
[root@server1 bin]# pwd
/usr/local/lnmp/mysql/bin
[root@server1 bin]# cd ~
[root@server1 ~]# vim .bash_profile 
[root@server1 ~]# source .bash_profile 

[root@server1 mysql]# mysqld --initialize --user=mysql
2018-08-05T03:08:09.732491Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-05T03:08:09.732538Z 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.
2018-08-05T03:08:09.732542Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2018-08-05T03:08:11.826611Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-05T03:08:12.184322Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-05T03:08:12.295367Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c9afc6b8-985c-11e8-bdda-525400d0916d.
2018-08-05T03:08:12.377937Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-05T03:08:12.378588Z 1 [Note] A temporary password is generated for 
root@localhost: WG.wto%gk4l!    这是mysql初始密码,等会修改密码会用到。


[root@server1 mysql]# chgrp -R root  data/
[root@server1 mysql]# ls
bin      data  include  man         README  support-files
COPYING  docs  lib      mysql-test  share

[root@server1 mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/lnmp/mysql/data/server1.err'.
 SUCCESS! 
[root@server1 mysql]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS! 

[root@server1 mysql]# mysql_secure_installation 


[root@server1 mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/lnmp/mysql/data/server1.err'.
 SUCCESS! 
[root@server1 mysql]# mysql_secure_installation 

mysql安全配置,密码就是刚才初始化的,修改

[root@server1 mysql]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
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 databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>




php源码编译安装
[root@server1 ~]# tar -jxf php-5.6.35.tar.bz2 
[root@server1 ~]# ls
gd-devel-2.0.35-11.el6.x86_64.rpm  php-5.6.35.tar.bz2
php-5.6.35                         re2c-0.13.5-1.el6.x86_64.rpm
[root@server1 ~]# cd php-5.6.35

[root@server1 ~]# ./configure –prefix=/usr/local/lnmp/php –with-config-file-path=/usr/local/lnmp/php/etc –with-mysql=mysqlnd –enable-mysqlnd –with-mysqli=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

php源码编译时不会生成缓存文件,看报错缺少啥就安装啥!!(devel)

这几个包要到网上下,其他的yum都有

gd-devel-2.0.35-11.el6.x86_64.rpm       
libmcrypt-2.5.8-9.el6.x86_64.rpm       
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm  
re2c-0.13.5-1.el6.x86_64.rpm    这是个警告需要的包

这里不一一列举了。。。

配置:

[root@server1 ~]# cd  /usr/local/lnmp/
[root@server1 lnmp]# ls
mysql  php
[root@server1 lnmp]# cd php/
[root@server1 php]# cd etc/
[root@server1 etc]# ls
pear.conf  php-fpm.conf.default
[root@server1 etc]# cp php-fpm.conf.default  php-fpm.conf
[root@server1 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default
[root@server1 etc]# cd ~
[root@server1 ~]# cd php-5.6.35

[root@server1 php-5.6.35]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server1 php-5.6.35]# vim /usr/local/lnmp/php/etc/php.ini
------------------
    修改date.timezone =Asia/Shanghai
------------------

[root@server1 php-5.6.35]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php.ini
[root@server1 etc]# vim php-fpm.conf


[root@server1 etc]# id nginx
id: nginx: No such user

[root@server1 etc]# useradd -M -d /usr/local/lnmp/nginx -s /sbin/nologin nginx
[root@server1 etc]# cd ~
[root@server1 ~]# cd php-5.6.35
[root@server1 php-5.6.35]# cd sapi/
[root@server1 sapi]# cd fpm/
[root@server1 fpm]# ls
config.m4       init.d.php-fpm.in  php-fpm.8        php-fpm.service     tests
CREDITS         LICENSE            php-fpm.8.in     php-fpm.service.in  www.conf.in
fpm             Makefile.frag      php-fpm.conf     status.html
init.d.php-fpm  php-fpm            php-fpm.conf.in  status.html.in
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@server1 fpm]# chmod +x /etc/init.d/php-fpm
[root@server1 fpm]# /etc/init.d/php-fpm start
Starting php-fpm  done
[root@server1 fpm]# 
nginx解压与安装:

[root@server1 ~]# tar zxf nginx-1.10.1.tar.gz 
[root@server1 ~]# tar zxf nginx-sticky-module-1.1.tar.gz 
[root@server1 ~]# ls
nginx-1.10.1         nginx-sticky-module-1.1
nginx-1.10.1.tar.gz  nginx-sticky-module-1.1.tar.gz
[root@server1 ~]# rm -rf nginx-1.10.1.tar.gz nginx-sticky-module-1.1.tar.gz
[root@server1 ~]# ls
nginx-1.10.1  nginx-sticky-module-1.1
[root@server1 ~]# cd nginx-1.10.1/
     cd src/core/
     vim nginx.h
       ##修改标示符
       ------------------------
       14 #define NGINX_VER          "nginx"
       ------------------------

     cd ../..
     cd auto/cc
     vim gcc 
       ##关掉debug 加快编译进度
       ---------------
       171 # debug
       172 #CFLAGS="$CFLAGS -g"
       ---------------

     cd -
     ./configure --help
     ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio --user=nginx --group=nginx

      ##报错:安装pcre-devel
      ------------------------------
       ./configure: error: the HTTP rewrite module requires the PCRE library.
      -----------------------------

    yum install -y pcre-devel

      ##报错:安装openssl
     ----------------------------
     ./configure: error: SSL modules require the OpenSSL library.
     -----------------------------

    yum install -y openssl-devel

    make && make install
    cd /usr/local/lnmp
    cd nginx/sbin
    cd conf/
    ln -s /usr/local/lnmp/nginx/sbin/nginx  /sbin/  ##建立启动命令

    nginx -t  ##检测nginx配置有没有问题

    vim /etc/security/limits.conf 
      ----------------------------
      54 nginx           -           nofile      65536
      -----------------------------

    useradd -u 800 nginx

    [root@server1 conf]# vim nginx.conf

这里写图片描述

检测:
这里写图片描述

  • vim /usr/local/lnmp/nginx/html/index.php
    这里写图片描述

[root@server1 ~]# cd /usr/local/lnmp/nginx/html/
[root@server1 html]# ls
50x.html  index.html  index.php  readme  upload  utility
[root@server1 html]# mv ./upload/ bbs
[root@server1 html]# ls
50x.html  bbs  index.html  index.php  readme  utility


[root@server1 mysql]# chmod 755 data 


/usr/local/lnmp/mysql/data/mysql.sock
添加mysqlsock路径,三个。 *socket= /usr/local/lnmp/mysql/data/mysql.sock

[root@server1 data]# vim /usr/local/lnmp/php/etc/php.ini 
[root@server1 data]# /etc/init.d/php-fpm reload
Reload service php-fpm  done

[root@server1 ~]# cd /usr/local/lnmp/nginx/html/bbs/
[root@server1 bbs]# chmod 777 config/ data/ uc_server/ uc_client/ -R

登陆172.25.5.1/bbs/install
这里写图片描述

简单设置后;
这里写图片描述

LNMP指的是一组通常一起使用来运行动态网站或者服务器的软件组合,分别是Linux(操作系统)、Nginx(Web服务器)、MySQL(数据库管理系统)和PHP(脚本语言)。 ### 搭建所需压缩包 搭建LNMP平台需要准备相关的压缩包,如nginx-1.12.0.tar.gz、libmcrypt-2.5.8.tar.gz、mhash-0.9.9.9.tar.gz、mcrypt-2.6.8.tar.gz、php-5.5.38.tar.gz [^1]。 ### 搭建示例 #### Nginx配置 在LNMP环境下搭建应用时,需要对Nginx进行配置。如在搭建WordPress时,编辑Nginx配置文件nginx.conf,添加如下内容: ```nginx location ~ \.php$ { root /usr/local/src/nginx-1.22.0/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ``` 上述配置指定了PHP文件的处理方式,将PHP请求转发到本地的9000端口 [^3]。 #### Discuz!安装 在LNMP架构搭建中,涉及到Discuz!的安装。需要访问论坛页面http://192.168.9.210/discuz/install/index.php ,并在PHP虚拟机中进行相关操作,如更改文件权限: ```bash [root@192 php-fpm.d]# cd /var/www/html [root@192 html]# chown -R nginx:nginx discuz ``` 上述操作将discuz目录的所有者和所属组更改为nginx [^2]。 ### MySQL配置 在搭建LNMP时,MySQL的配置也很重要,例如设置sql_mode: ``` sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES ``` 该配置定义了MySQL的SQL模式 [^4]。 ### 使用 搭建好LNMP环境后,可以部署各种基于PHP的应用程序,如WordPress、Discuz!等。通过Nginx作为Web服务器处理HTTP请求,MySQL存储应用程序的数据,PHP处理动态内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值