Linux-Nginx-MySQL-PHP编译安装保姆级教程,LNMP基础架构手动编译安装

部署nginx

// 创建系统用户nginx
[root@JLin ~]# useradd -r -M -s /sbin/nologin nginx

// 安装依赖环境
[root@JLin ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[root@JLin ~]# yum -y groups mark install 'Development Tools'

// 创建日志存放目录
[root@JLin ~]# mkdir -p /var/log/nginx
[root@JLin ~]# chown -R nginx.nginx /var/log/nginx

// 下载nginx软件包
[root@JLin ~]# cd /usr/src/
[root@JLin src]# wget http://nginx.org/download/nginx-1.20.1.tar.gz
[root@JLin src]# ls
debug  kernels  nginx-1.20.1.tar.gz
[root@JLin src]# tar xf nginx-1.20.1.tar.gz
[root@JLin src]# cd nginx-1.20.1
[root@JLin nginx-1.20.1]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_v2_module \
--http-log-path=/var/nginx/access.log \
--error-log-path=/var/nginx/error.log

// 编译安装
[root@JLin nginx-1.20.1]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install

// 配置环境变量
[root@JLin ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@JLin ~]# . /etc/profile.d/nginx.sh

// 服务控制方式,使用nginx命令
    -t  //检查配置文件语法
    -v  //输出nginx的版本
    -c  //指定配置文件的路径
    -s  //发送服务控制信号,可选值有{stop|quit|reopen|reload}

// 启动nginx
[root@JLin ~]# nginx
[root@JLin ~]# ss -antlup | grep nginx
tcp    LISTEN     0      128       *:80		*:*		users:("nginx",pid=8472,fd=7)

部署mysql

// 安装依赖包
[root@JLin ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs

// 创建用户和组
[root@JLin src]# useradd -r -M -s /sbin/nologin  mysql

// 下载二进制格式的mysql软件包
[root@JLin ~]# cd /usr/src/
[root@JLin src]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz

// 解压软件至/usr/local/
// 解压
[root@JLin src]# ls
debug  kernels  mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
[root@JLin src]# tar xf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@JLin ~]# ls /usr/local/
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.35-linux-glibc2.12-x86_64  share
// 软连接
[root@JLin ~]# cd /usr/local/
[root@JLin local]# ln -sv mysql-5.7.35-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.35-linux-glibc2.12-x86_64/'

// 修改目录/usr/local/mysql的属主属组
[root@JLin ~]# chown -R mysql.mysql /usr/local/mysql
[root@JLin ~]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 9月  23 16:39 /usr/local/mysql -> mysql-5.7.35-linux-glibc2.12-x86_64/

// 添加环境变量
[root@JLin ~]# ls /usr/local/mysql
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@JLin ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@JLin ~]# ./etc/profile.d/mysql.sh
[root@JLin ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

// 创建数据存放目录
[root@JLin ~]# mkdir -p /opt/data
[root@JLin ~]# chown -R mysql.mysql /opt/data/
[root@JLin ~]# ll /opt/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 9月  23 16:46 data

// 初始化数据库
// 请注意这种方法初始化完成后是没有密码的
[root@JLin ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data/
2021-09-23T08:48:41.261781Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-23T08:48:41.438873Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-23T08:48:41.459162Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-23T08:48:41.527098Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0d70e7f6-1c4b-11ec-a20e-000c2984a301.
2021-09-23T08:48:41.528205Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-09-23T08:48:42.036191Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-09-23T08:48:42.036204Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-09-23T08:48:42.036605Z 0 [Warning] CA certificate ca.pem is self signed.
2021-09-23T08:48:42.238241Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

// 配置mysql
[root@JLin ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[root@JLin ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@JLin ~]# ldconfig

// 生成配置文件
[root@JLin ~]# cat > /etc/my.cnf <<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF

// 配置service服务启动文件

[root@JLin ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /usr/local/mysql/support-files/mysql.server
[root@JLin ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /usr/local/mysql/support-files/mysql.server

[root@JLin ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=Mysqld server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop

[Install]
WantedBy=multi-user.target

// 重新加载
[root@JLin ~]# systemctl  daemon-reload

// 启动mysql
[root@JLin ~]# systemctl  start mysqld
[root@JLin ~]# ss -anltup | grep mysql
tcp    LISTEN     0      80       :::3306                 :::*                   users:(("mysqld",pid=1466,fd=23))

// 修改密码
// 登录
[root@JLin ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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> 

// 设置新密码
mysql> set password = password('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye

部署php

PHP7或PHP8

// 安装依赖包
[root@JLin ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp   gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt      libxslt-devel mhash mhash-devel php-mysqlnd libzip-devel libsqlite3x libsqlite3x-devel oniguruma   libzip-devel    https://repo.almalinux.org/almalinux/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

# 先卸载已有
[root@JLin ~]# yum remove libzip
# 然后安装
[root@JLin ~]# wget http://libzip.org/download/libzip-1.2.0.tar.gz --no-check-certificate
[root@JLin ~]# tar -zxvf libzip-1.2.0.tar.gz
[root@JLin ~]# cd libzip-1.2.0
[root@JLin libzip-1.2.0]# ./configure && make && make install
[root@JLin libzip-1.2.0]# export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"

// 下载php7软件包
[root@JLin ~]# cd /usr/src/
[root@JLin src]# wget https://www.php.net/distributions/php-7.4.5.tar.gz
[root@JLin src]# tar xf php-7.4.5.tar.gz
[root@JLin src]# cd php-7.4.5
[root@JLin php-7.4.5]#./configure --prefix=/usr/local/php7 \
--with-config-file-path=/etc \
--enable-fpm \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif  \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix


// 下载php8软件包
[root@JLin ~]# cd /usr/src/
[root@JLin src]# wget https://www.php.net/distributions/php-8.0.10.tar.gz
[root@JLin ~]# tar -xf  php-8.0.10.tar.gz

// 编译
[root@JLin ~]# cd /usr/src/php-8.0.10
[root@JLin php-8.0.10]# ./configure --prefix=/usr/local/php7 \
--with-config-file-path=/etc \
--enable-fpm \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif  \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix

// 安装
[root@JLin php-8.0.10]# make install

// 配置环境变量
// 下面配置为8,切忌直接cp,安装PHP7直接将路径改为7的路径
[root@JLin ~]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh 
[root@JLin ~]# source /etc/profile.d/php.sh

// 生成配置文件
[root@JLin ~]# cd /usr/src/php-8.0.10
[root@JLin php-8.0.10]# cp php.ini-production  /etc/php.ini
[root@JLin php-8.0.10]# cp sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm
[root@JLin ~]# chmod +x /etc/rc.d/init.d/php-fpm
[root@JLin ~]# cd /usr/local/php8/etc/
[root@JLin etc]# cp php-fpm.conf.default  php-fpm.conf
[root@JLin etc]# cd php-fpm.d/
[root@JLin php-fpm.d]# cp www.conf.default  www.conf

// 配置service文件
[root@JLin ~]# vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=Php-fpm server daemon
After=network.target

[Service]
Type=forking
ExecStart=service php-fpm start
ExecStop=service php-fpm stop

[Install]
WantedBy=multi-user.target

// 重新加载
[root@JLin ~]# systemctl  daemon-reload

// 启动服务
[root@JLin ~]# systemctl start php-fpm.service
[root@JLin ~]# ss -antl

// 创建php访问界面
[root@JLin ~]# vim /usr/local/nginx/html/index.php
<?php
   phpinfo();
?>

// 修改nginx配置文件
[root@JLin ~]# vim /usr/local/nginx/conf/nginx.conf
    server {
        listen       80;   #端口自行修改
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            #index  index.html index.htm index.php;
            index index.php;
        }

        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;
        }
        
// 重启服务访问
[root@JLin ~]# nginx -s reload

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汉只只

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值