侧边栏

LNMP环境搭建(失败篇)

总的来说,虽然最后失败了,但是还花了一天时间,但过程中积累的经验还是有必要的.

教程:http://c.biancheng.net/linux_tutorial/16/

任务:配置Linux服务器(lnmp或lamp环境)

LAMP 环境搭建指的是在 Linux 操作系统中分别安装 Apache 网页服务器、MySQL 数据库服务器和 PHP 开发服务器,以及一些对应的扩展软件。

LNMP 环境搭建指的是在 Linux 操作系统中分别安装 Nginx 网页服务器、MySQL 数据库服务器和 PHP 开发服务器,以及一些对应的扩展软件。

打算安装LNMP的环境.

系统:Centos-8

手工安装LAMP需要19个源码包,安装LNMP 环境,那么同样需要安装大概 14 个源码包.
但是现在网上非常流行的 LNMP 环境的搭建过程是采用 LNMP 一键安装包直接安装。
既然是一键安装包,所以我们就不用去下载单个的源码包了,只要在 http://soft.vpser.net/lnmp/lnmp1.0-full.tar.gz 这个地址中下载 LNMP 一键安装包即可。

我们应该把软件放置在 Linux 服务器的什么位置呢?
Linux 中的 /usr/local/src/ 目录是系统默认的放置下载软件源代码的位置
所以我们就把搭建 LNMP 环境所需的所有软件包都传递到这个位置

WinSCP传输软件

WinSCP 是在 Windows 中安装,使用 SFTP 协议向 Linux 服务器传递文件的工具。它的特点是使用简单、图形化操作,而且数据传递过程是加密的,较为安全,是 Windows 和 Linux 之间进行数据传递的常用软件。

在启动界面的“主机名”文本框中输入 Linux 服务器的 IP 地址,如 192.168.0.210,在“用户名”文本框中输入 Linux 的用户名,在“密码”文本框中输入正确的密码,单击“登录”按钮,就会见到如图 3 所示的界面。

B计划:

cd /usr/local/src/
wget http://soft.vpser.net/lnmp/lnmp1.0-full.tar.gz
mv ~/lnmp1.0-full.tar.gz /usr/local/src/

yum换源

把原本的源移走备份

mkdir /opt/centos-yum.bak
mv /etc/yum.repos.d/* /opt/centos-yum.bak/

查看系统版本

cat /etc/redhat-release

下载aliyun yum源repo文件(对应CentOS-8)

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

清除缓存

yum clean all
yum makecache        //把yum源缓存到本地,加快软件的搜索好安装速度
yum list

检查硬盘的剩余空间

df -h
注意挂载点""
先留出4G的空间

配置防火墙,开启80端口、3306端口(mysql)和11211(memcache)端口

systemctl start firewalld 开启防火墙
systemctl status firewalld 查看防火墙状态
firewall-cmd --list-all 查看开放端口
发现一个都没开hhh
下面来添加端口

// Step1: 加入开放端口到配置文件

# firewall-cmd --zone=public --add-port=80/tcp --permanent

--zone=public 添加时区

--add-port=80/tcp 添加端口

--permanent 永久生效

// 加载防火墙新配置文件( 以 root 身份输入以下命令,重新加载防火墙,并不中断用户连接,即不丢失状态信息. )

firewall-cmd --reload

记得重载后再查看开放的端口

关闭SELinux安全子系统

我们还需要关闭 SELinux 安全子系统。因为这个子系统会对我们的安装过程产生影响,所以先关闭它。关闭 SELinux 之后,必须重启 Linux 系统,修改才会生效。

vi /etc/selinux/config

#把 SELINUX=enforcing改为 SELINUX=disabled

shutdown -r now

B计划:直接禁用防火墙
systemctl stop firewalld 关闭防火墙

安装gcc

安装 gcc 编译工具。如果没有安装 gcc 编译工具,那么 LNMP 一键安装包会尝试自动 yum 安装,但是要保证 yum 源是可用的。

停用 RPM 包安装的 apache 和 MySQL

service httpd stop
service mysqld stop
#停止apache和mysql服务
chkconfig httpd off
chkconfig mysqld off
#关闭apache和mysql的自启动

解压

cd /usr/local/src/
tar -zxvf lnmp1.0-full.tar.gz

执行安装脚本安装 LNMP 一键安装包

cd lnmp1.0-full
./centos.sh

起飞!
回车之后安装就会继续,会看到如下界面:

==========================================================
LUMP V1.0 for CentOS/RadHat Linux VPS Written by Licess
==========================================================
A tool to auto-compile & install Nginx+MySQL+PHP on Linux
For more information please visit http://www.lnmp.org/
==========================================================
Please input the root password of mysql:
(Default password: root) : 123  #设定MySQL 的密码,这里设为 123
==========================================================
Do you want to install the InnoDB Storage Engine?
(Default no,if you want please input: y , if not please press the enter button):y
#是否需要安装MySQL InnoDB,如果需要安装则输入y

Install PHP 5.3.17,Please input y
Install PHP 5.2.17,Please input n or press Enter
(Please input y or n) :y
#选择安装PHP的版本,输入y安装的是5.3.17
Install MySQL 5.5.27,Please input y
Install MySQL 5.1.60,Please input n or press Enter
(Please input y or n) :y
#选择安装MySQL的版本,输入y安装的是5.5.27
Press any key to start. . .or Press Ctrl+c to cancel #按任意鍵开始安装

如果在安装过程中输入错误,则可以按“Ctrl+Backspace”组合键来进行删除。
如果看到以下界面,则证明安装成功。

=========================================================
Manager for LNMP VI.0 , Written by Licess
=========================================================
LNMP is a tool to auto-compile & install Nginx+MySQL+PHP on Linux
This script is a tool to Manage status of lnmp
For more information please visit http://www.lnmp.org
Usage: /root/lnmp {start|stop|reload|restart|kill|status}
=========================================================
Nginx is runing!
php-fpm is runing!
MySQL running (12489)   [确定]
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address   Foreign Address State
tcp 0 0 0.0.0.0:53575   0.0.0.0:*   LISTEN
tcp 0 0 0.0.0.0:3306    0.0.0.0:*   LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:*   LISTEN
tcp 0 0 0.0.0.0:80  0.0.0.0:*   LISTEN
tcp 0 0 0.0.0.0:22  0.0.0.0:*   LISTEN
tcp 0 0 127.0.0.1:631   0.0.0.0:*   LISTEN
tcp 0 0 127.0.0.1:25    0.0.0.0:*   LISTEN
tcp 0 0 :::57454    :::*    LISTEN
tcp 0 0 :::111  :::*    LISTEN
tcp 0 0 :::22   :::*    LISTEN
tcp 0 0 ::1:631 :::*    LISTEN
tcp 0 0 ::1:25  :::*    LISTEN

LNMP一键安装包安装的软件及具体位置

既然是一键安装,那么默认安装的软件和软件的安装位置都是事先设定好的,在安装过程中不能更改。具体安装了哪些软件及其位置如表 1 所示。

也就是说,LNMP 一键安装只安装了基本的 Nginx、MySQL、PHP、phpMyAdmin 和 Zend Optimizer。

....

===================================== Check install ===================================

Checking...
Error: /usr/local/nginx not found!!!Nginx install failed.
Error: /usr/local/php not found!!!PHP install failed.
Error: /usr/local/mysql not found!!!MySQL install failed.
Sorry,Failed to install LNMP!
Please visit http://bbs.vpser.net/forum-25-1.html feedback errors and logs.
You can download /root/lnmp-install.log from your server,and upload lnmp-install.log to LNMP Forum.
[root@localhost-localdomain]在[/usr/local/src/lnmp1.0-full]笑着说:
​



竟然失败了
重来
这次分来装
教程:https://blog.csdn.net/qq_24447851/article/details/106316944

先是安装Nginx
yum install -y nginx
安装nginx后可以访问服务器的ip进行查看
nginx

创建用户组www

groupadd www
 
useradd -g www www

在php-7.3.18里配置pm的用户组和用户

./configure --prefix=/usr/local/php \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--with-mcrypt \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm

嗯,过程中出现四五次报错,不过问题不大,直接百度就行
成功的话能看到这里

Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

接下来编译
make && make install

cp php.ini-development /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
vim /usr/local/php/etc/php-fpm.conf
 
# 进入文件后找到下面的内容并更改目录
pid = /usr/local/php/var/run/php-fpm.pid 
vim /usr/lib/systemd/system/php-fpm.service
#添加
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=notify
PIDFile=/var/opt/remi/php73/run/php-fpm/php-fpm.pid
ExecStart=/opt/remi/php73/root/usr/sbin/php-fpm --nodaemonize  --fpm-config /etc/opt/remi/php73/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

注意: 需要根据自己环境情况 填写 PIDFile、ExecStart; PIDFile为pid文件, ExecStart 为可执行文件和 php-fpm.conf 配置文件地址

加个权限:

chmod +x /etc/init.d/php-fpm

现在试一下,/etc/init.d/php-fpm start

systemctl重载
systemctl daemon-reload

# 设置开机自启
 
systemctl enable php-fpm.server
# 重启php-fpm
 
systemctl restart php-fpm.server
# 重启后可以查看php-fpm状态
 
systemctl status php-fpm.server

然后是安装mysql

# 安装
 
yum install -y mariadb-server
 
# 启动
 
systemctl start mariadb
 
# 查看状态
 
systemctl status mariadb
 
# 开机启动
 
systemctl  enable  mariadb
 
# 设置密码
 
mysqladmin -uroot  password  'yourpassword'

/usr/share/nginx/html
/etc/nginx/nginx.conf

https://lnmp.org/install.html

posted @ 2021-07-21 10:26  探针一号  阅读(581)  评论(0编辑  收藏  举报