之前写过几篇有关安装lnmp环境的文章,现在回顾感觉有些比较老了或者并不是好的操作,于是更新这篇

1. 安装Nginx

  1) 依赖安装

yum install gcc gcc-c++ openssl openssl-devel cyrus-sasl-md5

  2)下载nginx

wget http://nginx.org/download/nginx-1.12.0.tar.gz

  3)解压并进入安装目录

tar zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0

  4) 编译安装

./configure --prefix=/usr/local/nginx --with-http_ssl_module

make && make install -j2

  5) 启动并查看服务

/usr/local/nginx/sbin/nginx

ps -ef | grep nginx

  6)加入开机自启动

vim  /etc/rc.local
添加代码如下:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf &

  借助systemd进行开机自启动设置

Systemd服务文件以.service结尾,比如现在要建立nginx为开机启动,如果用yum install命令安装的,yum命令会自动创建nginx.service文件,直接用命令
systemcel enable nginx.service 编译安装的需要手动创建nginx.service
1. 在系统服务目录里创建nginx.service文件
vim /lib/systemd/system/nginx.service 内容:
[Unit]
Description=nginx
After=network.target [Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true [Install]
WantedBy=multi-user.target 说明:
[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3 保存退出。 2.设置开机启动
systemctl enable nginx.service 3. 其他命令 启动nginx服务
systemctl start nginx.service 设置开机自启动
systemctl enable nginx.service 停止开机自启动
systemctl disable nginx.service 查看服务当前状态
systemctl status nginx.service 重新启动服务
systemctl restart nginx.service 查看所有已启动的服务
systemctl list-units --type=service

  

  7)加入全局环境变量

vim /etc/profile

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

保存退出

立即生效: source /etc/profile

  8) 验证环境变量

nginx -v

nginx version: nginx/1.12.0

2. 安装PHP

  1) 安装依赖包

yum -y install bzip2

  2)下载PHP

wget https://www.php.net/distributions/php-7.2.28.tar.bz2

tar txvf php-7.2.28.tar.bz2

cd php-7.2.28

  3) 创建www用户

groupadd  www

useradd -g www -s /sbin/nologin www

# 查看www用户
id www

  4)编译安装

./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7 --enable-sockets --enable-fpm --enable-cli --enable-mbstring --enable-pcntl --enable-soap --enable-opcache --disable-fileinfo --disable-rpath --with-mysqli --with-pdo-mysql --with-iconv-dir --with-openssl --with-fpm-user=www --with-fpm-group=www --with-curl --with-mhash --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-zip --with-zlib --enable-simplexml --with-libxml-dir

make && make install

  说明:

--prefix=/usr/local/php7 # 配置安装目录
--with-config-file-path=/usr/local/php7 # 配置文件 php.ini 的路径
--enable-sockets # 开启 socket
--enable-fpm # 启用 fpm 扩展
--enable-cli # 启用 命令行模式 (从 php 4.3.0 之后这个模块默认开启所以可以不用再加此命令)
--enable-mbstring # 启用 mbstring 库
--enable-pcntl # 启用 pcntl (仅 CLI / CGI)
--enable-soap # 启用 soap
--enable-opcache # 开启 opcache 缓存
--disable-fileinfo # 禁用 fileinfo (由于 5.3+ 之后已经不再持续维护了,但默认是开启的,所以还是禁止了吧)(1G以下内存服务器直接关了吧)
--disable-rpath #禁用在搜索路径中传递其他运行库。
--with-mysqli # 启用 mysqli 扩展
--with-pdo-mysql # 启用 pdo 扩展
--with-iconv-dir # 启用 XMLRPC-EPI 字符编码转换 扩展
--with-openssl # 启用 openssl 扩展 (需要 openssl openssl-devel)
--with-fpm-user=www #设定 fpm 所属的用户
--with-fpm-group=www #设定 fpm 所属的组别
--with-curl # 启用 curl 扩展
--with-mhash # 开启 mhash 基于离散数学原理的不可逆向的php加密方式扩展库
# GD
--with-gd # 启用 GD 图片操作 扩展
--with-jpeg-dir # 开启对 jpeg 图片的支持 (需要 libjpeg)
--with-png-dir # 开启对 png 图片支持 (需要 libpng)
--with-freetype-dir # 开启 freetype
# 压缩
--enable-zip # 启用 zip
--with-zlib # 启用对 zlib 支持
# xml
--enable-simplexml # 启用对 simplexml 支持
--with-libxml-dir # 启用对 libxml2 支持

  5)设置配置文件

cp /opt/php-7.2.28/php.ini-production /usr/local/php7/php.ini

cp /usr/local/php7/etc/php-fpm.conf.default  /usr/local/php7/etc/php-fpm.conf

cp  /usr/local/php7/etc/php-fpm.d/www.conf.default    /usr/local/php7/etc/php-fpm.d/www.conf

  php-fpm.conf修改如下:

[global]
; Pid file
; Note: the default prefix is /usr/local/php7/var
; Default Value: none
# 取消下面的注释
pid = run/php-fpm.pid

  6) 配置简单启动命令

# 复制启动脚本到 init.d 目录
$ cp php-7.2.19/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# 增加执行权限
$ chmod +x /etc/init.d/php-fpm

  php-fpm操作命令:

/usr/local/php7/sbin/php-fpm.  # 启动
pkill. -9 php-fpm #停止 /etc/init.d/php-fpm start. # 启动
/etc/init.d/php-fpm stop # 停止
/etc/init.d/php-fpm status # 状态
/etc/init.d/php-fpm restart # 重启

  7)添加自启动

/sbin/chkconfig php-fpm on #再次重启即可完成自启动

  8)php-fpm服务化

# 在 centos 7 之后我们可以使用 systemctl 更好的管理系统服务
# 所以我们也要让 php-fpm 支持
# 因为 php 7.2 源码包里面含有 systemctl 所需要的脚本文件
# 我们只要复制过去即可,我们来开始配置
# 进入下载的 php源码包
$ cd php-7.2.28/sapi/fpm
# 复制其中的 php-fpm.service 到 /usr/lib/systemd/system/
$ cp php-fpm.service /usr/lib/systemd/system/
# 再次使用 systemctl enable php-fpm 进行配置自启动
$ systemctl enable php-fpm
# 重启测试一下看看自己服务器的 php-fpm 是否成功运行
systemctl enable xxxxxx # 配置自启动
systemctl stop xxxxx # 停止服务
systemctl start xxxx # 开启服务
systemctl status xxxx # 查看状态

  9)nginx支持配置

$ vi /usr/local/nginx/conf/nginx.conf
...
http {
...
server {
...
# 把 [1] 换成 [2]
# 让 nginx 支持 php 文件
#[1]
location / {
root html;
index index.html index.htm;
}
#[2]
location / {
root html;
index index.php index.html index.htm;
}
...
# 把 [1] 换成 [2]
# 配置监听 php 端口
# 注意: 要把 /scripts 换成 $document_root
#[1]
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
#[2]
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
...
}

  10)添加PHP全局变量

vim /etc/profile

添加内容如下:
export=$PATH:/usr/local/php7/bin 立即生效
source /etc/profile

  常见错误:

configure: error: libxml2 not found. Please check your libxml2 installation.
# 安装 libxml2 库
$ yum -y install libxml2 libxml2-devel ... configure: error: Cannot find OpenSSL\'s <evp.h>
# 安装 openssl 库
$ yum -y install openssl openssl-devel ... checking for cURL 7.10.5 or greater... configure: error: cURL version 7.10.5 or later is required to compile php with cURL support
# 安装 curl 库
$ yum -y install libcurl libcurl-devel ... configure: error: jpeglib.h not found.
# 安装 libjpeg 顺便 把 libpng 也装上
$ yum -y install libjpeg libjpeg-devel libpng libpng-devel ... configure: error: freetype-config not found.
# 安装 freetype 库
$ yum -y install freetype freetype-devel

3. 安装mysql

  因为编译安装mysql较为复杂,这里先使用yum进行安装,之后会专门开一篇记录编译安装mysql

wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum --installroot=/usr/local/mysql --releasever=/ -y install mysql-server

  使用yum安装之后,可以执行使用systemctl命令进行操作

开启MySQL服务器: systemctl start mysqld
关闭MySQL服务器: systemctl stop mysqld
。。。

  mysql第一次登录会生成随机密码:

grep "password" /var/log/mysqld.log

  登录并重置密码:

alter user 'root'@'localhost' identified by '123456';

flush privileges;
注意: 默认它的密码安全级别为中等,需要使用大小写字母+数字+特殊字符 组合

  开启远程连接:

grant all privileges on *.* to root@'%' identified by "password";

flush privileges;

  

  

Lnmp编译安装(2020)的更多相关文章

  1. LNMP编译安装教程

    LNMP编译安装教程 此次安装在Centos上,我采用的CentOS的版本是:CentOS release 6.5 (Final) 可以通过以下命令查看:lsb_release -a 一.准备工作: ...

  2. LNMP编译安装(centos7+nginx1.9+mysql5.6+php5.5)

    LNMP编译安装 # 需先配置IP # 软件包的路径 /usr/local/src yum install -y libjpeg-devel libpng-devel freetype-devel c ...

  3. lnmp编译安装

    lnmp超详细编译安装教程 linux采用的是centos,软件包统一放在/usr/local/src目录下.由于 centos源比较老,而且更新起来也比较慢,此处建议你换成163源.提示:如果你真打 ...

  4. linux lnmp编译安装

    关闭SELINUX vi /etc/selinux/config #SELINUX=enforcing #注释掉 #SELINUXTYPE=targeted #注释掉 SELINUX=disabled ...

  5. LNMP编译安装基于centos7.2

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止fir ...

  6. CentOS6.8 x64+Nginx1.3.8/Apache-httpd 2.4.3+PHP5.4.8(php-fpm)+MySQL5.5.28+CoreSeek4.1源码编译安装

    系统为CentOS6.8 x64服务器版精简安装. 准备工作 部署安装目录 /usr/local/* /var/lib/* /var/lib64/* 下载源文件 #cd /usr/local/src ...

  7. centos下编译安装lnmp

    centos下编译安装lnmp 本文以centos为背景在其中编译安装nginx搭建lnmp环境. 编译安装nginx时,需要事先安装 开发包组"Development Tools" ...

  8. 在树莓派1B上编译安装lnmp服务器

    最近一周给部门内部搭建考试系统,选择使用PHPEMS.这是个开源的系统,唯一缺点是PHP的版本比较低,只能使用5.2或5.3.而我的树莓派系统更新后使用apt-get安装得到的PHP版本为5.4.由于 ...

  9. CentOS编译安装LNMP环境

    这里是教大家如何在centos下利用源码编译安装LNMP环境. 工具/原料 centos服务器一台 自用电脑一台 准备篇 配置好IP.DNS .网关,确保使用远程连接工具能够连接服务器 配置防火墙,开 ...

  10. LNMP之编译安装PHP出现的问题

    2010年以前,互联网公司最常用的Web服务组合就是LAMP(即Linux.Apache.MySQL.PHP),近几年随着Nginx Web服务的逐渐流行,又出现了新的Web服务环境组合--LNMP ...

随机推荐

  1. 一步一步将PlantUML类图导出为自定义格式的XMI文件

    一步一步将PlantUML类图导出为自定义格式的XMI文件 说明: 首次发表日期:2024-09-08 PlantUML官网: https://plantuml.com/zh/ PlantUML命令行 ...

  2. github代理加速

    终端命令行 支持终端命令行 git clone , wget , curl 等工具下载.支持 raw.githubusercontent.com , gist.github.com , gist.gi ...

  3. Angular Material 18+ 高级教程 – CDK Overlay

    Overlay, Dialog, Modal, Popover 傻傻分不清楚 参考: Medium – Modal?Dialog?你真的知道他們是什麼嗎? Popups, dialogs, toolt ...

  4. ASP.NET Core – 操作 Uri 和 Query

    前言 以前就有写过了 Asp.net core 学习笔记 (操作 URL 和 Query), 但很乱, 这篇作为整理. Uri 介绍 结构: [Scheme]://[Host]:[Port][/Pat ...

  5. 利用PaddleHub 进行人脸检测识别、并对图片进行抠图

    利用PaddleHub 进行人脸检测识别.并对图片进行抠图   本文是利用百度的飞桨平台的paddle进行人脸的检测和抠图,但是里面也有一些小问题,特记录一下笔记,以便以后观看学习. 环境:pytho ...

  6. 使用阿里云 SpringBoot 仓库初始化项目

    本文基于:https://www.bilibili.com/video/BV15b4y1a7yG?p=5&vd_source=cf8900ba33d057d422c588abe5d5290d ...

  7. 我们如何在 vue 应用我们的权限

    权限可以分为用户权限和按钮权限: 用户权限,让不同的用户拥有不同的路由映射 ,具体实现方法: 1. 初始化路由实例的时候,只把静态路由规则注入 ,不要注入动态路由规则 : 2. 用户登录的时候,根据返 ...

  8. C#使用 MailKit 收发邮件

    目录 获取QQ邮箱授权码 安装 MailKit 配置邮件服务器信息 实现邮件收发方法 测试邮件收发 参考文章 获取QQ邮箱授权码 打开QQ邮箱,进入 设置->账号 页面: 在 POP3/IMAP ...

  9. SQLServer数据库日志太大处理方式

    SQLServer数据库日志太大处理方式 1.1 如下图,点击连接登陆数据库 1.2 如下图,打开数据库属性窗口 1.3 如下图,更改数据库恢复模式 1.4 如下图,收缩数据库日志 到这里已经完成了, ...

  10. Fluent Operator v2.0 发布:Fluent Bit 新的部署方式——Fluent Bit Collector

    2019 年 1 月 21 日,KubeSphere 社区为了满足以云原生的方式管理 Fluent Bit 的需求开发了 FluentBit Operator.此后产品不断迭代,在 2021 年 8 ...