1.编译安装LNMP---重点
了解
静态网站:.html htm jpg mp4
动态网站: .php .jsp
L Linux
N nginx
M 数据库
P php
1.yum方式
2.编译方式
环境:虚拟机
ip:10.0.1.0
网关:10.0.1.2
子网掩码:255.255.255.0
测试机器ip:10.0.1.102
tips:机器不可以有nginx,所以这里建议你重新开个新机器或者克隆一个模版机
tips:安装时如果没有依赖包,这时就要更新一下yum源了
没有更新yum源的,可以更新一下
1. 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
2.1各版本
centos8
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
centos6
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
3.各版本epel源
3.1 备份(如有配置其他epel源)
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
3.2 下载新repo 到/etc/yum.repos.d/
epel(RHEL 8)
1)安装 epel 配置包
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
2)将 repo 配置中的地址替换为阿里云镜像站地址
sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
epel(RHEL 7)
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
epel(RHEL 6) (epel6官方源已下线,建议切换epel-archive源)
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-archive-6.repo
4.更新缓存和软件
yum clean all
yum makecache
yum update
tips:建议在这里设置一下虚拟机快照,不然每次都要这样,会很耽误时间
编译安装--lnmp
yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel
1.1
yum -y install pcre-devel openssl-devel zlib-devel gcc
1.2
groupadd nginx
useradd -g nginx -s /sbin/nologin nginx
1.3
切换到解压后的nginx目录中执行:
cd /usr/local/src
wget http://nginx.org/download/nginx-1.18.0.tar.gz
解压压缩包
tar zxvf nginx-1.18.0.tar.gz (解压)
tar zcvf nginx-1.18.0.tar.gz (压缩)
1.4
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
注解:
您提供的命令是对 ./configure 脚本的调用,该脚本通常位于采用 GNU Autotools 构建系统的软件项目源代码目录中。这个脚本用于为项目的编译和安装做前期准备,根据用户提供的配置选项生成相应的 Makefile 文件。具体到您给出的命令:
[root@node-1 ~]
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx \
--with-http_ssl_module --with-http_stub_status_module
各个选项含义如下:
- --user=nginx: 指定编译安装后,Nginx 服务运行时所属的系统用户为 nginx。这意味着当 Nginx 服务启动时,将以 nginx 用户的身份运行。
- --group=nginx: 指定编译安装后,Nginx 服务运行时所属的系统组为 nginx。这意味着当 Nginx 服务启动时,将以 nginx 组的成员身份运行。
- --prefix=/usr/local/nginx: 设置 Nginx 的安装目录为 /usr/local/nginx。这意味着编译完成后,Nginx 的可执行文件、配置文件、库文件、文档等将被安装到这个路径下。例如,Nginx 主程序通常会被安装到 /usr/local/nginx/sbin/nginx,配置文件则位于 /usr/local/nginx/conf/nginx.conf。
- --with-http_ssl_module: 启用 SSL/TLS 支持模块。配置此项后,编译出的 Nginx 将具备处理 HTTPS 请求的能力,允许网站提供安全的加密通信。
- --with-http_stub_status_module: 启用 stub_status 模块。该模块提供了一个简单的 HTTP 接口,可以用来查询 Nginx 服务器的基本状态信息,如当前活动连接数、处理过的请求总数等。这对于监控 Nginx 服务器的运行状态非常有用。
执行以上命令后,./configure 脚本将检查系统环境,确认依赖项是否满足,并根据指定的选项生成相应的 Makefile。接下来,用户通常会执行 make 命令编译源代码,然后执行 make install 命令将编译好的程序安装到指定的位置。这样,一个带有 SSL 支持和 stub_status 模块的 Nginx 服务器就安装完成了,并将以 nginx 用户和组的身份运行。
make
make install
启动nginx:/usr/local/nginx/sbin/nginx
关闭nginx:/usr/local/nginx/sbin/nginx -s stop
检查nginx 是否异常:/usr/local/nginx/sbin/nginx -t
重启nginx: nginx -s reload
1.5
每次都需要输入路径才可以重启 检查等操作比较繁琐
用软连接定义
ln -s /usr/local/nginx/sbin/nginx /bin/nginx
这样就可以了
启动 : nginx
停止:nginx -t stop
重启 : nginx -s reload
检查: nginx -t
1.6
cd /usr/local/src/
rz命令上传
tar zxvf php-7.2.29.tar.gz
cd ./php-7.3.9
./configure --prefix=/usr/local/php --exec-prefix=/usr/local/php --with-mysqli --with-pdo-mysql --with-gd --bindir=/usr/local/php/bin --sbindir=/usr/local/php/sbin --includedir=/usr/local/php/include --libdir=/usr/local/php/lib/php --mandir=/usr/local/php/php/man --with-config-file-path=/usr/local/php/etc --with-openssl --enable-mbstring --enable-fpm
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
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
ln -s /usr/local/php/bin/php /usr/local/bin
echo -e "\033[31m php部署成功 \033[0m"
启动php: /etc/init.d/php-fpm start
使用netstat -tuln 查看 如果有 9000 端口就是正常
1.7 安装数据库
----------yum方式
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum -y install mysql-community-server
[root@node-1 ~]
[root@node-1 ~]
[root@node-1 ~]
ss -tulpn |grep mysql
数据库接口 3306
--------编译安装mysql 数据库
基于CentOS7 二进制安装MySQL8.0(5.7+适用)
1、创建用户
[root@node-1 ~]
[root@node-1 ~]
2、创建目录
[root@node-1 ~]
[root@node-1 ~]
3、准备二进制程序
[root@node-1 ~]
--2023-06-07 10:54:29-- https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.32-linux-glibc2.12-x86_64.tar
正在解析主机 cdn.mysql.com (cdn.mysql.com)... 104.70.237.54
正在连接 cdn.mysql.com (cdn.mysql.com)|104.70.237.54|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1005660160 (959M) [application/x-tar]
正在保存至: “mysql-8.0.32-linux-glibc2.12-x86_64.tar”
100%[====================================================================================================>] 1,005,660,160 26.6MB/s 用时 29s
2023-06-07 10:54:58 (32.8 MB/s) - 已保存 “mysql-8.0.32-linux-glibc2.12-x86_64.tar” [1005660160/1005660160])
[root@node-1 ~]
mysql-test-8.0.32-linux-glibc2.12-x86_64.tar.xz
mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
mysql-router-8.0.32-linux-glibc2.12-x86_64.tar.xz
[root@node-1 ~]
[root@node-1 ~]
[root@node-centos7-70 local]
"mysql" -> "mysql-8.0.32-linux-glibc2.12-x86_64"
4、安装依赖包
[root@node-1 ~]
5、设置PATH环境变量
[root@node-1 ~]
[root@node-1 ~]
6、创建配置文件
[root@node-1 ~]
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
pid-file=/data/mysql/mysql.pid
log-error=/data/mysql/mysql.log
[client]
socket=/data/mysql/mysql.sock
EOF
7、创建数据库文件,并提取root密码
[root@node-1 ~]
[root@node-1 ~]
2023-06-07T03:20:09.342795Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ,*9LyAr6wrr
[root@node-1 ~]
,*9LyAr6wrr
8、创建服务脚本,并启动服务
[root@node-1 ~]
[root@node-1 ~]
[root@node-1 ~]
Starting MySQL... SUCCESS!
9、修改初始密码,测试访问数据库
[root@node-1 ~]
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@node-1 ~]
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
为root账户设置数据库密码
[root@node-1 ~]
Enter current password for root (enter for none): <---输入现在的root密码,因为我们还没设置,直接回车
Set root password? [Y/n] Y <---是否设定root密码,当然设置了,输入Y回车
New password: <---输入root密码,并回车,输入的过程中不会有任何显示
Re-enter new password: <---再次输入root密码,并回车,输入的过程中不会有任何显示
Remove anonymous users? [Y/n] Y <---是否删除匿名用户,删除,输入Y回车
Disallow root login remotely? [Y/n] Y <---是否删禁止root用户远程登录,当然禁止,输入Y回车
Remove test database and access to it? [Y/n] <---是否删除测试数据库test,看个人喜好
Reload privilege tables now? [Y/n] Y <---刷新权限,输入Y回车
最后出现:Thanks for using MySQL!
MySql密码设置完成,重新启动 MySQL:
tips:数据库密码一般设置就比较复杂的,在生产环境中,不过这里就不设置复杂的了,直接123
mysql -uroot -p"123"
create database wordpress;
show databases;
1.8
cd /usr/local/nginx/conf
打开 多域名配置如下:
vi /usr/local/nginx/conf/nginx.conf
vim nginx.conf
参考这个配置文件
[root@web3 conf]
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 81;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include /usr/local/nginx/conf/vhost/*.conf;
}
重启nginx
在cd /usr/local/nginx/conf/vhost 目录新建配置文件
vi www.conf 添加如下
server {
listen 80;
server_name www.it.com localhost;
location / {
root /html/www;
index index.html index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /html/www$fastcgi_script_name;
include fastcgi_params; }
}
nginx -t 检查一下
nginx -s relaod 重启启动nginxls
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel
yum install -y libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel
yum install -y glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel
yum install -y e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
1.9
vi index.php
<?php
phpinfo();
?>
nginx -t
nginx -s reload
或者
/usr/local/nginx/sbin/nginx -s reload
查看index.php页面显示
http://10.0.1.102
2.0
vim test_mysql.php
<?php
$servername = "localhost";
$username = "root";
$password = "oldboy123";
//$link_id=mysql_connect('主机名','用户','密码');
//mysql -u用户 -p密码 -h 主机
$conn = mysqli_connect($servername, $username, $password);
if ($conn) {
echo "mysql successful by root !\n";
}else{
die("Connection failed: " . mysqli_connect_error());
}
?>
Nginx访问PHP文件的File not found错误处理,两种情况
转载 2017年05月09日 14:05:27
标签:
php /
nginx
这个错误很常见,原有有下面两种几种
php-fpm找不到SCRIPT_FILENAME里执行的php文件
php-fpm不能访问所执行的php,也就是权限问题
第一种情况
更改配置文件nginx.conf
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
替换成下面
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
然后重新加载nginx配置文件
/etc/init.d/nginx reload
如果你只能用ip访问,就需要站是把其他网站的配置文件删掉,做个备份,只用一个测试网站的配置文件
发布一个博客
1.
cd /html/www
rz 上传你的源码包
tar 格式
tar zxvf 源码包 解压
tar zcvf 源码包 压缩
zip 格式
unzip 源码包
2.配置nginx.conf ---发布目录
cd /usr/local/nginx/conf/vhost/
ls
vim www.conf
3.安装论坛
tips:如果输入ip地址或者域名无法跳转的的话,那就复制下面我这段地址,把其他的ip地址替换你自己的就可以了或者域名
http://10.0.1.102/upload/install/
chmod -R 777 upload/
如果出现无法连接数据库,在数据库服务器哪里输入127.0.0.1,就可以了
效果如下图

2.部署搭建yum--lnmp
tips:安装时如果没有依赖包,这时就要更新一下yum源了
没有更新yum源的,可以更新一下
1. 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
2.1各版本
centos8
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
centos6
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
3.各版本epel源
3.1 备份(如有配置其他epel源)
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
3.2 下载新repo 到/etc/yum.repos.d/
epel(RHEL 8)
1)安装 epel 配置包
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
2)将 repo 配置中的地址替换为阿里云镜像站地址
sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
epel(RHEL 7)
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
epel(RHEL 6) (epel6官方源已下线,建议切换epel-archive源)
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-archive-6.repo
4.更新缓存和软件
yum clean all
yum makecache
yum update
tips:建议在这里设置一下虚拟机快照,不然每次都要这样,会很耽误时间
yum install epel-release -y
yum install nginx -y
[root@node-1 ~]
[root@node-1 ~]
[root@node-1 ~]
yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel
[root@node-1 ~]
[root@node-1 ~]
[root@node-1 ~]
tips:如果你有就不用设置了
为root账户设置密码
[root@node-1 ~]
Enter current password for root (enter for none): <---输入现在的root密码,因为我们还没设置,直接回车
Set root password? [Y/n] Y <---是否设定root密码,当然设置了,输入Y回车
New password: <---输入root密码,并回车,输入的过程中不会有任何显示
Re-enter new password: <---再次输入root密码,并回车,输入的过程中不会有任何显示
Remove anonymous users? [Y/n] Y <---是否删除匿名用户,删除,输入Y回车
Disallow root login remotely? [Y/n] Y <---是否删禁止root用户远程登录,当然禁止,输入Y回车
Remove test database and access to it? [Y/n] <---是否删除测试数据库test,看个人喜好
Reload privilege tables now? [Y/n] Y <---刷新权限,输入Y回车
最后出现:Thanks for using MySQL!
MySql密码设置完成,重新启动 MySQL:
tips:数据库密码一般设置就比较复杂的,在生产环境中,不过这里就不设置复杂的了,直接123
yum -y install php php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap
[root@node-1 ~]
[root@node-1 ~]
[root@node-1 ~]
[root@node-1 ~]
tips:有一个9000端口代表php启动了
[root@node-1 www]
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 127.0.0.1:9000 *:*
进入nginx 配置文件目录
tips:由于我们是yum安装的,所以配置文件都在etc下面,如果这个conf.d这个文件夹,可以新建一下,再进去创建www.conf配置文件,将内容填充进去
cd /etc/nginx/conf.d
vi www.conf 添加如下
server {
listen 80;
server_name www.it.com;
location / {
root /html/www;
index index.html index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /html/www$fastcgi_script_name;
include fastcgi_params;
}
}
如果多域名配置没有打开 ,在这/etc/nginx/conf.d新建配置是不会生效的
在 vi /etc/nginx/nginx.conf配置文件需要有这个配置文件才会生效 检查下
include /etc/nginx/conf.d/*.conf;
配置文件详细内容
cd /etc/nginx/
vim nginx.conf
[root@node-1 nginx]
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf; 重点就是这个位置
tips:如果没有这个目录自己新建一下mkdir -p /html/www
cd /html/www
vi index.php
将以下内容填充进去
<?php
phpinfo();
?>
效果图如下
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!