Linux-CentOS 7.7编译安装LNMP,阿里云Centos 7安装LNMP(源码编译安装LNMP)

2020-03-21
0评论
/
阅读
管理员

LNMP是由Linux操作系统、Nginx中间件、MySQL数据库、PHP脚本语言四大开源免费产品组合而成的Web服务框架,早前网站已分享过Nginx、MySQL、PHP单独编译安装教程,或许有些朋友仍不清楚怎么使用,今天给大家分享完整的LNMP使用配置方法。

Linux编译安装Nginx

Linux编译安装MySQL

Linux编译安装PHP

LNMP实验环境

操作系统:CentOS 7.7

主机地址:192.168.168.21

Nginx:1.16.1

MySQL:5.7.28

PHP:7.4.1

Zlib:1.2.11

Pcre:8.43

OpenSSL:1.0.2u

LNMP安装篇

第一步 安装依赖包

[root@wanghualang ~]# yum -y install epel-release
[root@wanghualang ~]# yum -y install gcc gcc-c++ autoconf automake wget vim make cmake openssl-devel bison-devel ncurses-devel libsqlite3x-devel oniguruma-devel curl-devel libxml2-devel libjpeg-devel libpng-devel freetype-devel libicu-devel libsodium-devel

第二步 下载、解压源码包

[root@wanghualang ~]# cd /usr/local/src/
[root@wanghualang src]# wget --no-check-certificate http://zlib.net/zlib-1.2.11.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
[root@wanghualang src]# wget --no-check-certificate http://nginx.org/download/nginx-1.16.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.php.net/distributions/php-7.4.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2t.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
[root@wanghualang src]# tar xzf pcre-8.43.tar.gz  
[root@wanghualang src]# tar xzf php-7.4.1.tar.gz  
[root@wanghualang src]# tar xzf zlib-1.2.11.tar.gz
[root@wanghualang src]# tar xzf nginx-1.16.1.tar.gz
[root@wanghualang src]# tar xzf openssl-1.0.2u.tar.gz
[root@wanghualang src]# tar xzf mysql-boost-5.7.28.tar.gz

第三步 新建用户组、用户

[root@wanghualang ~]# groupadd nginx
[root@wanghualang ~]# groupadd mysql
[root@wanghualang ~]# useradd nginx -M -g nginx -s /sbin/nologin
[root@wanghualang ~]# useradd mysql -M -g mysql -s /sbin/nologin

第四步 编译安装Nginx(按需添加更多功能模块)

[root@wanghualang ~]# cd /usr/local/src/nginx-1.16.1
[root@wanghualang nginx-1.16.1]# ./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--with-pcre=/usr/local/src/pcre-8.43 \
--with-openssl=/usr/local/src/openssl-1.0.2u \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-http_gzip_static_module \
--with-http_dav_module \
--with-http_stub_status_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_ssl_module  \
--with-http_v2_module
[root@wanghualang nginx-1.16.1]# make
[root@wanghualang nginx-1.16.1]# make install

第五步 配置Nginx启动服务脚本、开机启动

[root@wanghualang ~]# vim /etc/init.d/nginx
#!/bin/bash    
#chkconfig: 2345 55 25    
    
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin    
NAME=nginx    
NGINX_BIN=/usr/local/nginx/sbin/$NAME    
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf    
PIDFILE=/usr/local/nginx/logs/$NAME.pid  
  
if [ -s /bin/ss ]; then    
    StatBin=/bin/ss    
else    
    StatBin=/bin/netstat    
fi    
    
    
case "$1" in    
    start)    
        echo -n "Starting $NAME... "    
    
        if $StatBin -tnpl | grep -q nginx;then    
            echo "$NAME (pid `pidof $NAME`) already running."    
            exit 1    
        fi    
    
        $NGINX_BIN -c $CONFIGFILE    
    
        if [ "$?" != 0 ] ; then    
            echo " failed"    
            exit 1    
        else    
            echo " done"    
        fi    
        ;;    
    
    stop)    
        echo -n "Stoping $NAME... "    
    
        if ! $StatBin -tnpl | grep -q nginx; then    
            echo "$NAME is not running."    
            exit 1    
        fi    
    
        $NGINX_BIN -s stop    
    
        if [ "$?" != 0 ] ; then    
            echo " failed. Use force-quit"    
            exit 1    
        else    
            echo " done"    
        fi    
        ;;    
    
    status)    
        if $StatBin -tnpl | grep -q nginx; then    
            PID=`pidof nginx`    
            echo "$NAME (pid $PID) is running..."    
        else    
            echo "$NAME is stopped."    
            exit 0    
        fi    
        ;;    
    
    force-quit|kill)    
        echo -n "Terminating $NAME... "    
    
        if ! $StatBin -tnpl | grep -q nginx; then    
            echo "$NAME is is stopped."    
            exit 1    
        fi    
    
        kill `pidof $NAME`    
    
        if [ "$?" != 0 ] ; then    
            echo " failed"    
            exit 1    
        else    
            echo " done"    
        fi    
        ;;    
    
    restart)    
        $0 stop    
        sleep 1    
        $0 start    
        ;;    
    
    reload)    
        echo -n "Reload service $NAME... "    
    
        if $StatBin -tnpl | grep -q nginx; then    
            $NGINX_BIN -s reload    
            echo " done"    
        else    
            echo "$NAME is not running, can't reload."    
            exit 1    
        fi    
        ;;    
    
    configtest)    
        echo -n "Test $NAME configure files... "    
    
        $NGINX_BIN -t    
        ;;    
    
    *)    
        echo "Usage: $0 {start|stop|restart|reload|status|configtest|force-quit|kill}"    
        exit 1    
        ;;
esac
[root@wanghualang ~]# chmod +x /etc/init.d/nginx
[root@wanghualang ~]# chkconfig --add nginx
[root@wanghualang ~]# chkconfig nginx on

第六步 编译安装MySQL(按需添加更多功能模块)

[root@wanghualang ~]# cd /usr/local/src/mysql-5.7.28
[root@wanghualang mysql-5.7.28]# cmake  \
[root@wanghualang ~]# cd /usr/local/src/
[root@wanghualang src]# wget --no-check-certificate http://zlib.net/zlib-1.2.11.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
[root@wanghualang src]# wget --no-check-certificate http://nginx.org/download/nginx-1.16.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.php.net/distributions/php-7.4.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2t.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
[root@wanghualang src]# tar xzf pcre-8.43.tar.gz  
[root@wanghualang src]# tar xzf php-7.4.1.tar.gz  
[root@wanghualang src]# tar xzf zlib-1.2.11.tar.gz
[root@wanghualang src]# tar xzf nginx-1.16.1.tar.gz
[root@wanghualang src]# tar xzf openssl-1.0.2u.tar.gz
[root@wanghualang src]# tar xzf mysql-boost-5.7.28.tar.gz0
[root@wanghualang ~]# cd /usr/local/src/
[root@wanghualang src]# wget --no-check-certificate http://zlib.net/zlib-1.2.11.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
[root@wanghualang src]# wget --no-check-certificate http://nginx.org/download/nginx-1.16.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.php.net/distributions/php-7.4.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2t.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
[root@wanghualang src]# tar xzf pcre-8.43.tar.gz  
[root@wanghualang src]# tar xzf php-7.4.1.tar.gz  
[root@wanghualang src]# tar xzf zlib-1.2.11.tar.gz
[root@wanghualang src]# tar xzf nginx-1.16.1.tar.gz
[root@wanghualang src]# tar xzf openssl-1.0.2u.tar.gz
[root@wanghualang src]# tar xzf mysql-boost-5.7.28.tar.gz1

第七步 优化数据库配置(4G内存优化方案,仅供参考)

[root@wanghualang ~]# cd /usr/local/src/
[root@wanghualang src]# wget --no-check-certificate http://zlib.net/zlib-1.2.11.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
[root@wanghualang src]# wget --no-check-certificate http://nginx.org/download/nginx-1.16.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.php.net/distributions/php-7.4.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2t.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
[root@wanghualang src]# tar xzf pcre-8.43.tar.gz  
[root@wanghualang src]# tar xzf php-7.4.1.tar.gz  
[root@wanghualang src]# tar xzf zlib-1.2.11.tar.gz
[root@wanghualang src]# tar xzf nginx-1.16.1.tar.gz
[root@wanghualang src]# tar xzf openssl-1.0.2u.tar.gz
[root@wanghualang src]# tar xzf mysql-boost-5.7.28.tar.gz2
[root@wanghualang ~]# cd /usr/local/src/
[root@wanghualang src]# wget --no-check-certificate http://zlib.net/zlib-1.2.11.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
[root@wanghualang src]# wget --no-check-certificate http://nginx.org/download/nginx-1.16.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.php.net/distributions/php-7.4.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2t.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
[root@wanghualang src]# tar xzf pcre-8.43.tar.gz  
[root@wanghualang src]# tar xzf php-7.4.1.tar.gz  
[root@wanghualang src]# tar xzf zlib-1.2.11.tar.gz
[root@wanghualang src]# tar xzf nginx-1.16.1.tar.gz
[root@wanghualang src]# tar xzf openssl-1.0.2u.tar.gz
[root@wanghualang src]# tar xzf mysql-boost-5.7.28.tar.gz3

第八步 修改MySQL数据库目录、配置文件权限

[root@wanghualang ~]# cd /usr/local/src/
[root@wanghualang src]# wget --no-check-certificate http://zlib.net/zlib-1.2.11.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
[root@wanghualang src]# wget --no-check-certificate http://nginx.org/download/nginx-1.16.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.php.net/distributions/php-7.4.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2t.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
[root@wanghualang src]# tar xzf pcre-8.43.tar.gz  
[root@wanghualang src]# tar xzf php-7.4.1.tar.gz  
[root@wanghualang src]# tar xzf zlib-1.2.11.tar.gz
[root@wanghualang src]# tar xzf nginx-1.16.1.tar.gz
[root@wanghualang src]# tar xzf openssl-1.0.2u.tar.gz
[root@wanghualang src]# tar xzf mysql-boost-5.7.28.tar.gz4

第九步 配置MySQL数据库环境变量

[root@wanghualang ~]# cd /usr/local/src/
[root@wanghualang src]# wget --no-check-certificate http://zlib.net/zlib-1.2.11.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
[root@wanghualang src]# wget --no-check-certificate http://nginx.org/download/nginx-1.16.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.php.net/distributions/php-7.4.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2t.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
[root@wanghualang src]# tar xzf pcre-8.43.tar.gz  
[root@wanghualang src]# tar xzf php-7.4.1.tar.gz  
[root@wanghualang src]# tar xzf zlib-1.2.11.tar.gz
[root@wanghualang src]# tar xzf nginx-1.16.1.tar.gz
[root@wanghualang src]# tar xzf openssl-1.0.2u.tar.gz
[root@wanghualang src]# tar xzf mysql-boost-5.7.28.tar.gz5

第十步 配置MySQL启动服务脚本、开机启动

[root@wanghualang ~]# cd /usr/local/src/
[root@wanghualang src]# wget --no-check-certificate http://zlib.net/zlib-1.2.11.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
[root@wanghualang src]# wget --no-check-certificate http://nginx.org/download/nginx-1.16.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.php.net/distributions/php-7.4.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2t.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
[root@wanghualang src]# tar xzf pcre-8.43.tar.gz  
[root@wanghualang src]# tar xzf php-7.4.1.tar.gz  
[root@wanghualang src]# tar xzf zlib-1.2.11.tar.gz
[root@wanghualang src]# tar xzf nginx-1.16.1.tar.gz
[root@wanghualang src]# tar xzf openssl-1.0.2u.tar.gz
[root@wanghualang src]# tar xzf mysql-boost-5.7.28.tar.gz6

第十一步 初始化MySQL数据库

[root@wanghualang ~]# cd /usr/local/src/
[root@wanghualang src]# wget --no-check-certificate http://zlib.net/zlib-1.2.11.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
[root@wanghualang src]# wget --no-check-certificate http://nginx.org/download/nginx-1.16.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.php.net/distributions/php-7.4.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2t.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
[root@wanghualang src]# tar xzf pcre-8.43.tar.gz  
[root@wanghualang src]# tar xzf php-7.4.1.tar.gz  
[root@wanghualang src]# tar xzf zlib-1.2.11.tar.gz
[root@wanghualang src]# tar xzf nginx-1.16.1.tar.gz
[root@wanghualang src]# tar xzf openssl-1.0.2u.tar.gz
[root@wanghualang src]# tar xzf mysql-boost-5.7.28.tar.gz7

第十二步 编译安装PHP(按需添加更多功能模块)

[root@wanghualang ~]# cd /usr/local/src/
[root@wanghualang src]# wget --no-check-certificate http://zlib.net/zlib-1.2.11.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
[root@wanghualang src]# wget --no-check-certificate http://nginx.org/download/nginx-1.16.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.php.net/distributions/php-7.4.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2t.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
[root@wanghualang src]# tar xzf pcre-8.43.tar.gz  
[root@wanghualang src]# tar xzf php-7.4.1.tar.gz  
[root@wanghualang src]# tar xzf zlib-1.2.11.tar.gz
[root@wanghualang src]# tar xzf nginx-1.16.1.tar.gz
[root@wanghualang src]# tar xzf openssl-1.0.2u.tar.gz
[root@wanghualang src]# tar xzf mysql-boost-5.7.28.tar.gz8
[root@wanghualang ~]# cd /usr/local/src/
[root@wanghualang src]# wget --no-check-certificate http://zlib.net/zlib-1.2.11.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
[root@wanghualang src]# wget --no-check-certificate http://nginx.org/download/nginx-1.16.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.php.net/distributions/php-7.4.1.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2t.tar.gz
[root@wanghualang src]# wget --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
[root@wanghualang src]# tar xzf pcre-8.43.tar.gz  
[root@wanghualang src]# tar xzf php-7.4.1.tar.gz  
[root@wanghualang src]# tar xzf zlib-1.2.11.tar.gz
[root@wanghualang src]# tar xzf nginx-1.16.1.tar.gz
[root@wanghualang src]# tar xzf openssl-1.0.2u.tar.gz
[root@wanghualang src]# tar xzf mysql-boost-5.7.28.tar.gz9
[root@wanghualang ~]# groupadd nginx
[root@wanghualang ~]# groupadd mysql
[root@wanghualang ~]# useradd nginx -M -g nginx -s /sbin/nologin
[root@wanghualang ~]# useradd mysql -M -g mysql -s /sbin/nologin0

第十三步 创建PHP配置文件

[root@wanghualang ~]# groupadd nginx
[root@wanghualang ~]# groupadd mysql
[root@wanghualang ~]# useradd nginx -M -g nginx -s /sbin/nologin
[root@wanghualang ~]# useradd mysql -M -g mysql -s /sbin/nologin1

第十四步 配置PHP启动服务脚本、开机启动

[root@wanghualang ~]# groupadd nginx
[root@wanghualang ~]# groupadd mysql
[root@wanghualang ~]# useradd nginx -M -g nginx -s /sbin/nologin
[root@wanghualang ~]# useradd mysql -M -g mysql -s /sbin/nologin2

第十五步 创建PHP测试网站根目录、测试页面

[root@wanghualang ~]# groupadd nginx
[root@wanghualang ~]# groupadd mysql
[root@wanghualang ~]# useradd nginx -M -g nginx -s /sbin/nologin
[root@wanghualang ~]# useradd mysql -M -g mysql -s /sbin/nologin3

第十六步 配置Nginx

[root@wanghualang ~]# groupadd nginx
[root@wanghualang ~]# groupadd mysql
[root@wanghualang ~]# useradd nginx -M -g nginx -s /sbin/nologin
[root@wanghualang ~]# useradd mysql -M -g mysql -s /sbin/nologin4
[root@wanghualang ~]# groupadd nginx
[root@wanghualang ~]# groupadd mysql
[root@wanghualang ~]# useradd nginx -M -g nginx -s /sbin/nologin
[root@wanghualang ~]# useradd mysql -M -g mysql -s /sbin/nologin5

第十七步 配置PHP测试网站虚拟主机

[root@wanghualang ~]# groupadd nginx
[root@wanghualang ~]# groupadd mysql
[root@wanghualang ~]# useradd nginx -M -g nginx -s /sbin/nologin
[root@wanghualang ~]# useradd mysql -M -g mysql -s /sbin/nologin6
[root@wanghualang ~]# groupadd nginx
[root@wanghualang ~]# groupadd mysql
[root@wanghualang ~]# useradd nginx -M -g nginx -s /sbin/nologin
[root@wanghualang ~]# useradd mysql -M -g mysql -s /sbin/nologin7

第十八步 启动Nginx、MySQL、PHP

[root@wanghualang ~]# groupadd nginx
[root@wanghualang ~]# groupadd mysql
[root@wanghualang ~]# useradd nginx -M -g nginx -s /sbin/nologin
[root@wanghualang ~]# useradd mysql -M -g mysql -s /sbin/nologin8

第十九步 测试PHP网站

Linux-CentOS 7.7编译安装LNMP,阿里云Centos 7安装LNMP(源码编译安装LNMP)

本站附件分享,如附件失效,可以去找找看
诚通网盘附件百度网盘附件
PS:由于百度网盘附件太大,所以百度网盘附件为拆分压缩,全部下载后打开zip后缀文件即可。也可以只下载zip后缀文件查看(只可以查看不能解压)是否有需要的文件,再下载全部文件解压需要的文件


干饭福利分享: 微信扫码领取“饿了么”抵用券↓↓↓↓↓↓↓↓↓↓

于2020-03-21发布