目录
3、lnmp采用的软件版本:Debian 12,MySQL 5.7.44,PHP 8,nginx 1.26.2
博客网站:ayue520.cn
一、前期准备工作
1、配置Debian12的软件源
#换源前先进行备份
mv /etc/apt/sources.list /etc/apt/sources.list_bak
vim /etc/apt/sources.list
#复制下面的内容进去
deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
#保存退出
apt update
2、安装相关工具
apt install lrzsz bash-completion
lrzsz是配合xshell可以拖拽传输文件,bash-completion有些最小量安装系统是没有tab补全命令的,所以安装这个软件重新打开ssh会话就可以了。
3、lnmp采用的软件版本:Debian 12,MySQL 5.7.44,PHP 8,nginx 1.26.2
MySQL 5.7.44:https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.44.tar.gz
nginx 1.26.2:https://nginx.org/download/nginx-1.26.2.tar.gz
PHP 8:https://www.php.net/distributions/php-8.4.1.tar.gz
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.44.tar.gz https://nginx.org/download/nginx-1.26.2.tar.gz https://www.php.net/distributions/php-8.4.1.tar.gz
二、MySQL数据库编译安装
1、安装各种依赖件:
apt install gcc cmake make openssl developers-reference libssl-dev libncurses5-dev pkg-config libpcre3-dev g++ zlib1g-dev
2、配置编译安装过程:
tar -xf mysql-boost-5.7.44.tar.gz
cd 解压后的MySQL路径
vim cmake.sh
#粘贴下面的配置命令进去
cmake . \
-DCMAKE_INSTALL_PREFIX=/mysqld \
-DMYSQL_DATADIR=/mysqld/data \
-DSYSCONFDIR=/etc \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/mysqld/mysql.sock \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_SSL=system \
-DWITH_BOOST=boost
#保存退出
chmod +x cmake.sh
./cmake.sh && make && make install
eg:编译时make -j #j后面加cpu核数,例如2核就是make -j2
groupadd -g 2233 mysql
useradd -g 2233 -u 2233 -s /sbin/nologin -M mysql
chown -R mysql:mysql /mysqld
echo "export PATH=$PATH:/mysqld/bin" >> /etc/profile
source /etc/profile
cd /mysqld
mysqld --initialize --user=mysql --basedir=/mysqld --datadir=/mysqld/data
cp support-files/mysql.server /etc/init.d/mysql.server
update-rc.d mysql.server defaults #使用该命令添加服务
service mysql.server start
ss -ntulp | grep mysql
三、部署Nginx 1.26.2
tar -xf nginx-1.26.2.tar.gz
cd nginx-1.26.2
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_realip_module --with-http_ssl_module --with-pcre --with-stream --with-http_stub_status_module
make && make install
groupadd -g 8888 nginx
useradd -g 8888 -s /sbin/nologin -u 8888 -M nginx
echo "export PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile
source /etc/profile
chown -R nginx:nginx /usr/local/nginx
#输入nginx启动服务nginx重载的命令为nginx -s reload
nginx
ss -ntulp | grep nginx
#在安装好nginx的路径下/usr/local/nginx
mkdir conf.d #创建用来存放网页配置文件
#nginx.conf引入上面文件夹路径,在server{}里添加下面命令
vim /usr/local/nginx/conf/nginx.conf
include /usr/local/nginx/conf.d/*.conf #在nginx.conf配置文件里加入这调命令,保存退出
四、编译安装PHP8
tar -xf php-8.4.1.tar.gz
apt install libxml2-dev libsqlite3-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libfreetype6-dev libavif-dev libwebp-dev libxpm-dev libonig-dev libzip-dev -y
cd php-8.4.1
#配置命令
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli=mysqlnd --with-pdo-mysql --enable-opcache --enable-gd --with-iconv --with-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg --with-freetype --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm --enable-fast-install --disable-fileinfo --enable-bcmath --with-openssl --with-xpm --with-webp --with-avif
#编译安装
make -j2 && make install
#在解压的PHP8目录复制php.ini-development到安装后/usr/local/php/etc/目录下
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
chown -R nginx:nginx /usr/local/php
echo "PATH=$PATH:/usr/local/php/bin:/usr/local/php/sbin" >> /etc/profile
source /etc/profile
#配置php-fpm.conf文件
vim /usr/local/php/etc/php-fpm.conf
#定义一下日志的路径,保存退出
error_log = /var/log/php-fpm.log
#在解压的PHP8目录下sapi/fpm/php-fpm.service路径,复制
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
systemctl start php-fpm.service
ss -ntulp | grep php
五、配置nginx调动php
mkdir /php #创建一个存放index.php源码的目录
vim /php/index.php #复制下面的代码进去
<?php
phpinfo();
?>
#wq 保存退出,接下来在nginx的conf.d下创建配置文件
chown -R nginx:nginx /php
vim /usr/local/nginx/conf.d/php.conf
server {
listen 80;
server_name 192.168.10.10; #输入服务器自身的ip
root /php;
location / {
index index.php;
}
location ~ \.php$ {
root /php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_buffering on;
fastcgi_buffers 64 64k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#重载nginx服务
chown -R nginx:nginx /usr/local/nginx
nginx -s reload
#在浏览器输入192.168.10.10测试,显示PHP的功能页面就表示LNMP部署完成,PHP调用完毕