CentOS7.4 源码编译安装LNMP

1、基于CentOS7.4源码编译安装得lnmp

系统环境CentOS 7.4

系统最小化安装,只安装了一些常用包(vim、lirzs、gcc*、wget、bash-completion)

nginx版本1.14.0

mysql版本5.7.20

php版本7.2.6

1.1 下载网络yum源

[[email protected]_4 ~]# wget http://mirrors.aliyun.com/repo/Centos-7.repo -P /etc/yum.repos.d/    #这里安装的是阿里的网络源,epel扩展源,也可以安装阿里的,但是阿里的epel源有些包不全,所以下面就直接用yum安装网络epel源

[[email protected]_4 ~]# yum -y install epel-release

[[email protected]_4 ~]# ls /etc/yum.repos.d/

back  Centos-7.repo  CentOS-Media.repo  epel.repo  epel-testing.repo

[[email protected]_4 ~]# yum clean all;yum makecache

2 源码编译安装nginx

2.1 安装依赖包:

[[email protected]_4 ~]# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre*

2.2 创建nginx运行用户

[[email protected]_4 ~]# useradd -M -s /sbin/nologin nginx

下载pcre包

[[email protected]_4 ~]# wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.zip

[[email protected]_4 ~]# unzip pcre-8.42.zip -d /usr/local/src/

2.3 下载nginx源码包并解压

[[email protected]_4 ~]# wget http://nginx.org/download/nginx-1.14.0.tar.gz

[[email protected]_4 ~]# tar zxf nginx-1.14.0.tar.gz -C /usr/local/src/

[[email protected]_4 ~]# cd /usr/local/src/nginx-1.14.0/

[[email protected]_4 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx \

--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 \

--user=nginx \

--group=nginx \

--with-pcre=/usr/local/src/pcre-8.42 \     #这个是可选项,如果yum安装了依赖包这里也可以不用

2.4 编译并安装

[[email protected]_4 nginx-1.14.0]# echo $?

0

[[email protected]_4 nginx-1.14.0]# make

[[email protected]_4 nginx-1.14.0]# echo $?

0

[[email protected]_4 nginx-1.14.0]# make install

[[email protected]_4 nginx-1.14.0]# echo $?

0

2.5 修改配置文件

[[email protected]_4 nginx-1.14.0]# vim /usr/local/nginx/conf/nginx.conf

user  nginx nginx;      #修改用户和组

location ~ \.php$ {

root           html;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;    #修改路径

include        fastcgi_params;

}

2.6 添加环境变量,优化nginx服务

[[email protected]_4 ~]# nginx -t                    #检查nginx语法是否正确

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected]_4 ~]# /usr/local/nginx/sbin/nginx            #安装好的启动路径

[[email protected]_4 ~]# vim /etc/profile                      #添加环境变量

export PATH=$PATH:/usr/local/nginx/sbin

[[email protected]_4 ~]# source /etc/profile

[[email protected]_4 ~]# nginx

[[email protected]_4 ~]# netstat -antup|grep nginx

tcp    0    0 0.0.0.0:80        0.0.0.0:*       LISTEN      7417/nginx: master

[[email protected]_4 ~]# vim /etc/init.d/nginx         #配置启动脚本

#!/bin/bash

# chkconfig: 2345 99 20

#description: nginx-server

nginx=/usr/local/nginx/sbin/nginx

case $1 in

start)

netstat -anptu | grep nginx

if [ $? -eq 0 ]

then

echo "nginx service is already running"

else

echo "nginx Service started successfully "

$nginx

fi

;;

stop)

$nginx -s stop

if [ $? -eq 0 ]

then

echo "nginx service closed successfully"

else

echo "nginx server stop fail,try again"

fi

;;

status)

netstat -anlpt | grep nginx

if [ $? -eq 0 ]

then

echo "nginx server is running"

else

echo "nginx service not started "

fi

;;

restart)

$nginx -s reload

if [ $? -eq 0 ]

then

echo "nginx service restart successfully "

else

echo "nginx server restart failed"

fi

;;

*)

echo "please enter {start restart status stop}"

;;

esac

[[email protected]_4 ~]# chmod +x /etc/init.d/nginx

[[email protected]_4 ~]# chkconfig --add nginx

[[email protected]_4 ~]# chkconfig nginx on

3 源码安装MySQL

3.1 卸载系统自带的mariadb*

[[email protected]_4 ~]# yum -y remove mariadb* boost-*

3.2 安装依赖包

[[email protected]_4 ~]# yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel

3.3 下载源码包

[[email protected]_4 ~]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.20.tar.gz

3.4 解压源码包

[[email protected]_4 ~]# tar zxf mysql-boost-5.7.20.tar.gz -C /usr/local/src/

3.5 配置编译并安装

[[email protected]_4 ~]# cd /usr/local/src/mysql-5.7.20/

[[email protected]_4 mysql-5.7.20]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DDOWNLOAD_BOOST=1 \

-DWITH_BOOST=/usr/local/src/mysql-5.7.20/boost/boost_1_59_0 \

-DSYSCONFDIR=/etc \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DENABLE_DTRACE=0 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DMYSQL_USER=mysql \

编译并安装

[[email protected]_4 mysql-5.7.20]# make

[[email protected]_4 mysql-5.7.20]# make install

3.6 创建数据库用户和数据目录

[[email protected]_4 ~]# useradd -M -s /sbin/nologin -r mysql

[[email protected]_4 ~]# mkdir -p /usr/local/mysql/data          #创建数据存储目录

[[email protected]_4 ~]# chown -R mysql.mysql /usr/local/mysql/     #更改属主数组为MySQL

3.7 配置my.cnf文件

[[email protected]_4 ~]# vim /etc/my.cnf             #以下是简单配置

[mysqld]

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

port=3306

socket=/usr/local/mysql/mysql.sock

symbolic-links=0

character-set-server=utf8

pid-file=/usr/local/mysql/mysqld.pid

log-error=/var/log/mysqld.log

3.8 配置MySQL启动脚本

[[email protected]_4 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld                      #复制启动脚本到/etc/init.d

[[email protected] mysql-5.7.20]# ll /etc/init.d/mysqld                          #默认拥有执行权限

-rwxr-xr-x 1 root root 10576 Jun  7 19:27 /etc/init.d/mysqld

[[email protected]_4 mysql]# chkconfig --add mysqld                #添加到开机启动项

[[email protected]_4 mysql]# chkconfig mysqld on                   #添加开机自启动

[[email protected]_4 mysql]# vim /etc/init.d/mysqld                #修改路径

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

[[email protected]_4 mysql]# vim /etc/profile                       #配置环境变量

export PATH=$PATH:/usr/local/mysql/bin

[[email protected]_4 mysql]# source /etc/profile                 #加载变量立即生效

配置MySQL启动脚本,这个和上面的二选一都可以

[[email protected]_4 system]# vim mysqld.service

[Unit]

Description=MySQL DBMS

[Service]

LimitNOFILE=10000

Type=simple

User=mysql

Group=mysql

PIDFile=/usr/local/mysql/mysqld.pid

ExecStart=/usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data

ExecStop=/bin/kill -9 $MAINPID

[Install]

WantedBy=multi-user.target

[[email protected]_4 system]# chmod +x mysqld.service               #添加执行权限

[[email protected]_4 system]# systemctl enable mysqld.service       #设置开机启动

3.9 安全初始化数据库

[[email protected]_4 ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data      #这样初始化之后,数据库是没有密码的

如果要想初始化之后分配临时密码,可以将--initialize-insecure 红色部分去掉,初始化之后,可以分配到一个临时密码。

[[email protected]_4 ~]# /etc/init.d/mysqld start                     #启动数据库

Starting MySQL. SUCCESS!

[[email protected]_4 ~]# mysql -uroot                         #登录数据库修改root用户密码

mysql> alter user ‘root‘@‘localhost‘ identified by ‘123456‘;

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

4 源码编译安装PHP

4.1 安装依赖包

[[email protected]_4 ~]# yum -y install php-mcrypt libmcrypt libmcrypt-devel  autoconf  freetype gd libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel re2c net-snmp-devel libjpeg-devel php-ldap openldap-devel openldap-servers openldap-clients freetype-devel gmp-devel

4.2 下载PHP源码包

[[email protected]_4 ~]# wget http://cn2.php.net/distributions/php-7.2.6.tar.gz

4.3 解压压缩包

[[email protected]_4 ~]# tar zxf php-7.2.6.tar.gz -C /usr/local/src/

[[email protected]_4 ~]# cd /usr/local/src/php-7.2.6/

4.4 生成配置文件

[[email protected]_4 php-7.2.6]# ./configure --prefix=/usr/local/php \

--with-config-file-path=/usr/local/php/etc \

--with-mysqli \

--with-pdo-mysql \

--with-mysql-sock=/usr/local/mysql/mysql.sock \

--with-iconv-dir \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-curl \

--with-gd \

--with-gmp \

--with-zlib \

--with-xmlrpc \

--with-openssl \

--without-pear \

--with-snmp \

--with-gettext \

--with-mhash \

--with-libxml-dir=/usr \

--with-ldap \

--with-ldap-sasl \            #如果不添加这两项,要是安装zabbix监控时候,会有提示还得需要再次编译,如果不安装zabbix,也可以忽略

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--enable-xml \

--enable-fpm  \

--enable-ftp \

--enable-bcmath \

--enable-soap \

--enable-shmop \

--enable-sysvsem \

--enable-sockets \

--enable-inline-optimization \

--enable-maintainer-zts \

--enable-mbregex \

--enable-mbstring \

--enable-pcntl \

--enable-zip \

--disable-fileinfo \

--disable-rpath \

--enable-libxml \

--enable-opcache \

--enable-mysqlnd \

configure: error: Cannot find ldap libraries in /usr/lib.       #解决方法

[[email protected]_4 php-7.2.6]# cp -frp /usr/lib64/libldap* /usr/lib/    #在重新配置

4.5 编译并安装

[[email protected]_4 php-7.2.6]# make

/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol ‘ber_strdup‘

/usr/lib64/liblber-2.4.so.2: error adding symbols: DSO missing from command line

collect2: error: ld returned 1 exit status

make: *** [sapi/cli/php] Error 1

[[email protected]_4 php-7.2.6]# vim Makefile      #在以EXTRA_LIBS开头的一行结尾添加‘-llber’

EXTRA_LIBS = -lcrypt -lz -lresolv -lcrypt -lrt -lldap -lgmp -lpng -lz -ljpeg -lz -lrt -lm -ldl -lnsl -lpthread -lxml2 -lz -lm -ldl -lssl -lcrypto -lcurl -lxml2 -lz -lm -ldl -lssl -lcrypto -lfreetype -lxml2 -lz -lm -ldl -lnetsnmp -lssl -lssl -lcrypto -lm -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lssl -lcrypto -lcrypt -llber

[[email protected]_4 php-7.2.6]# make

[[email protected]_4 php-7.2.6]# echo $?

0

[[email protected]_4 php-7.2.6]# make install

[[email protected]_4 php-7.2.6]# echo $?

0

4.6 配置php配置文件

移动php配置文件的位置,并修改名称

[[email protected]_4 php-7.2.6]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.conf

复制php.ini文件

[[email protected]_4 php-7.2.6]# cp /usr/local/src/php-7.2.6/php.ini-production /usr/local/php/etc/php.ini

4.7 复制php启动脚本到/etc/init.d/

[[email protected]_4 php-7.2.6]# cp /usr/local/src/php-7.2.6/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

添加执行权限,添加到启动项并设置卡机启动

[[email protected]_4 php-7.2.6]# chmod +x /etc/init.d/php-fpm

[[email protected]_4 php-7.2.6]# chkconfig --add php-fpm

[[email protected]_4 php-7.2.6]# chkconfig php-fpm on

启动php-fpm

[[email protected]_4 ~]# /etc/init.d/php-fpm start

Starting php-fpm  done

[[email protected]_4 ~]# vim /usr/local/nginx/conf/nginx.conf

43         location / {

44             root   html;

45             index  index.php index.html index.htm;

46         }

[[email protected]_4 ~]# service nginx restart     #重启nginx服务

编写php探测文件

[[email protected]_4 ~]# vim /usr/local/nginx/html/index.php

<?php

phpinfo();

?>

[[email protected]_4 ~]# netstat -antup|grep php-fpm

tcp    0    0 127.0.0.1:9000      0.0.0.0:*      LISTEN    128974/php-fpm: mas

通过浏览器测试

到这里整个实验已经完成了,新手上路,有什么写的不完善,还请各位大神多提宝贵意见

原文地址:https://www.cnblogs.com/baorong/p/9166417.html

时间: 2024-10-09 11:47:18

CentOS7.4 源码编译安装LNMP的相关文章

源码编译安装lnmp架构

lnmp的架构 lnmp架构为:linux +nginx +mysql+php/perl/python,我们将只用linux(rhel6.5)+nginx+mysql+php构建企业web架构 环境:RHEL6.5 iptables -F selinux is  disabled 注意:在搭建lnmp环境前,必须检测系统内部不能存在相关的软件:(纯净搭建) #rpm -qa | grep php #rpm -qa | grep httpd #rpm -qa | grep mysql 1.ngin

CentOS7.6源码编译安装PHP 7.3.8

安装步骤 PHP官网下载链接:https://www.php.net/downloads.php 1. 使用wget命令下载源码安装包 wget https://www.php.net/distributions/php-7.3.8.tar.gz --no-check-certificate [说明]如果报SSL Certification错误信息的话,就加上 --no-check-certificate选项,一般不需要添加. 2. 解压.tar.gz文件 tar -xzvf php-7.3.8

源码编译安装lnmp环境

一.源码编译安装步骤 首先说明源码安装的好处   速度快,可自定义路径 主要有三步:1.配置 进入源码安装包  ./configure --prefix=/uer/local/nginx  可指定参数--prefix为安装路径2.编译 相当于rpm包  make3.安装 make install 如果安装出错,先清楚一下 make clean,然后重新配置编译安装 二.安装nginx 1.安装可能需要的依赖环境, yum -y install libxml2-devel gd-devel lib

源码编译安装LNMP环境及配置基于域名访问的多虚拟主机

实验环境及软件版本: CentOS版本: 6.6(2.6.32.-504.el6.x86_64) apache版本: nginx-1.6.2 mysql版本:  Mysql-5.6.23 php版本:    php-5.6.3 一.关闭防火墙:service iptables stop chkconfig iptables off 二.关闭selinux: sed -i 's/SELINUX=disabled/SELINUX=enforcing/g' /etc/selinux/config in

centos6源码编译安装lnmp环境

操作系统 版本 64位 CentOS-6.6    10.0.0.20 安装环境所需依赖包 yum -y install gcc automake autoconf libtool make gcc-c++ glibc libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib

Centos7.2源码编译安装LA(N)MP

LAMP环境中php是作为apache的模块安装的,所以安装顺序是php放在apache的后面安装,这样便于安装php时可以在apache的模块目录生成对应的php模块. apache版本:2.4.37 mysql版本:5.7.24 php版本:7.3.0 nginx版本:nginx-1.14.2 注意:这里是使用的root用户安装,如果是其他用户,相应的操作前需要加上sudo. 1.安装apache 需要安装的依赖 apr.apt-util.pcre,pcre是一个正则表达式库,apache在

源码编译安装LNMP

Nginx是一种最重要的技能,在公司里可以不会其他的,nginx精通了你也可以所向披靡. 这篇文章也许是有史以来最长的文章了,没有之一. LNMP=Linux Nginx MysqlPHP nginx在工作中是非常重要的web服务器,它是一个高性能的 HTTP 和 反向代理 服务器,也是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,百度BWS.新浪.网易.腾讯等都是使用的是nginx Nginx的工作原理 Nginx 本身只支持静态页面的处理,当客户端访问

源码编译安装LNMP架构环境

OS版本:2.6.32-431.el6.x86_64 Nginx版本:nginx-1.6.1 mariadb版本:mariadb-10.0.13 php版本:php-5.4.26 1.安装编译安装所需系统环境 ~]# yum groupinstall "Development Tools" "Server Platform Development" -y 2.编译安装nginx-1.6.1 # yum -y install pcre-devel openssl-de

源码编译安装lnmp环境(nginx-1.14.2 + mysql-5.6.43 + php-5.6.30 )------踩了无数坑,重装了十几次服务器才会的,不容易啊!

安装顺序 php --- nginx -- mysql 安装php-5.6.30: 1 环境准备 yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel jemalloc jemalloc-devel y