LNMP环境
Linux
Linux操作系统在网上下载镜像文件然后安装虚拟机软件进行安装即可
Nginx
安装形式选择
yum:自动下载软件包及其依赖关系,自动化安装,省时省力。都是默认安装路径,以及版本不容易指定,自定制化太低,无法扩展第三方新功能。弃用
rpm包:要手动解决依赖,弃用
源代码编译安装:自由下载软件版本,自定制安装路径,第三方功能扩展,源代码编译安装步骤稍微复杂。使用
- 安装nginx前的系统依赖环境检查及其安装
yum install pcre pcre-devel openssl openssl-devel gcc -y
- 进入保存下载文件的目录, 以 /usr/local/ 为例
- 下载Nginx源代码包
cd /usr/local
wget http://nginx.org/download/nginx-1.22.0.tar.gz
- 解压缩
tar -zxvf nginx-1.22.0.tar.gz
- 创建普通的nginx用户,用于运行nginx程序,降低nginx的权限
useradd nginx -u 1111 -s /sbin/nologin -M
- 编译安装nginx服务
cd /usr/local/nginx-1.22.0
./configure --user=nginx --group=nginx --prefix=/mytools/nginx/ --with-http_stub_status_module --with-http_ssl_module
make && make install
- 配置软连接
ln -s /usr/local/nginx-1.22.0 /mytools/nginx
- 配置nginx环境变量
vim /etc/profile
PATH=“$PATH:/mytools/nginx/sbin”
设置nginx开机自启动,其他开机自启动的也可以据此模仿。在/etc/systemd/system文件夹下创建nginx.service文件,执行systemctl enable nginx.service
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/localinx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
辅助命令
# 启动nginx
systemctl start nginx
# 关闭nginx
systemctl stop nginx
# 重启nginx
systemctl reload nginx
Mysql
配置mysql的步骤
- 下载mysql的rpm文件
- 执行 rpm -ivh mysql的rpm文件
- 开启对应版本的mysql,如果安装的是社区8.0版本的mysql就是:rpm enable mysql80-community
- 禁用默认的mysql 执行rpm disable mysql
- 重置密码 编辑/etc/my.cnf文件添加skip_grant_tables然后 mysql -uroot -p 然后执行 update user set authentication_string=‘new password’ where user=‘root’
- 重启mysql Systemctl restart mysql
- 设置 mysql开机自启动 把mysqld 文件复制到 /etc/rc.d/init.d 文件夹下
辅助命令
#查看安装的mysql的相关功能,根据自己的需要开启对应的服务
rpm mysqllist all | grep mysql
# 开启mysql的相关功能,功能名称可以参照上面的命令的结果列表
rpm enable mysql80-community
# 查看mysql端口
netstat -ntulp | grep mysql
# 查看mysql进程
ps -ef | grep mysql
PHP
PHP编译安装
# 检查nginx和mysql的安装状态
curl 127.0.0.1
# 安装php所必须有的依赖环境
yum install gcc gcc-c++ make zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel \ freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel -y
# 发现yum仓库缺少一个libiconv-devel软件包,因此手动下载,编译安装
wget https://forensics.cert.org/cert-forensics-tools-release-el8.rpm
# 解压缩
tar -zxvf cert-forensics-tools-release-el8.rpm
# 进入下载文件目录,编译安装
./configure --prefix=/mytools/libiconv
make && make install
# 检查编译安装的命令是否正确结束了
echo $? # 在执行上一条shell语句结束后,打印$?可以检查上一次的命令是否正确
# 安装php程序
# 下载php文件
cd /usr/local
wget http://am1.php.net/distributions/php-7.3.2.tar.gz
# 解压缩
tar -zxvf php-7.3.2.tar.gz
# 进入php源码文件位置,编译安装
cd /usr/local/php
./configure --prefix=/mytools/mysql
make && make install
部署Node
- 下载node文件
cd /usr/local
wget https://nodejs.org/dist/v16.16.0/node-v16.16.0-linux-x64.tar.xz
- 解压文件
tar -xvf
rm -f node-v16.16.0-linux-x64.tar.xz
- 配置环境变量
vim /etc/profile
添加以下内容
export PATH=$PATH:/usr/local/node-v16.16.0-linux-x64/bin
重新加载配置文件
source /etc/profile
- 测试
node -v
如果出现版本号则证明安装成功
vim /usr/local/index.js
添加以下内容
const http = require('http');
const server= http.createServer();
server.on('request', function (req,res){
res.setHeader('Content-Type', 'text/plain;charset=utf8');
res.end("hello world");
});
server.listen(3000, function (){
console.log('server runing at http://localhost:3000');
});
然后运行index.js
node /usr/local/index.js
在浏览器中访问http://<服务器公网ip>:3000,如果能够访问则说明运行成功