源码部署lnmp

源码部署lnmp

配置yum源

[root@localhost ~]# rm -rf /etc/yum.repos.d/*
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0   4980      0 --:--:-- --:--:-- --:--:--  4980
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# yum clean all
0 files removed
[root@localhost ~]# yum makecache

源码部署nginx

//安装依赖
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++

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

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

//下载nginx源码包
[root@localhost ~]# wget https://nginx.org/download/nginx-1.22.1.tar.gz
[root@localhost ~]# tar xf nginx-1.22.1.tar.gz 
[root@localhost ~]# cd nginx-1.22.1
[root@localhost nginx-1.22.1]# 

//编译安装
[root@localhost nginx-1.22.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 \
> --http-log-path=/var/log/nginx/access.log \
> --error-log-path=/var/log/nginx/error.log
[root@localhost nginx-1.22.1]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install

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

//编写service文件
[root@localhost system]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service nginx.service
[root@localhost system]# vim nginx.service 
[root@localhost system]# cat nginx.service 
[Unit]
Description=nginx server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/usr/local/nginx/sbin/nginx -s reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@localhost ~]# ss -antl
State      Recv-Q      Send-Q           Local Address:Port           Peer Address:Port     Process     
LISTEN     0           511                    0.0.0.0:80                  0.0.0.0:*                    
LISTEN     0           128                    0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0           128                       [::]:22                     [::]:* 

部署mariadb

//解压压缩包
[root@localhost ~]# cd /opt
[root@localhost opt]# ls
[root@localhost opt]# tar xf mariadb-10.6.15-rhel-8-x86_64-rpms.tar 
[root@localhost opt]# cd mariadb-10.6.15-rhel-8-x86_64-rpms
[root@localhost mariadb-10.6.15-rhel-8-x86_64-rpms]# 

//安装mariadb
[root@localhost mariadb-10.6.15-rhel-8-x86_64-rpms]# ./setup_repository 
Repository file successfully created! Please install MariaDB Server with this command:

   yum install MariaDB-server

[root@localhost mariadb-10.6.15-rhel-8-x86_64-rpms]# yum install MariaDB-server -y

//设置mariadb密码
[root@localhost mariadb-10.6.15-rhel-8-x86_64-rpms]# systemctl enable --now mariadb
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@localhost mariadb-10.6.15-rhel-8-x86_64-rpms]# cd
[root@localhost ~]# 
[root@localhost ~]# mysql -uroot 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.6.15-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> set password = password('ayachinene');
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> exit
Bye

源码部署php

//安装依赖包
[root@localhost ~]# yum -y install libxml2-devel gcc-c++ openssl-devel sqlite-devel libcurl-devel readline-devel libpng-devel freetype-devel libzip-devel libjpeg-turbo-devel
[root@localhost ~]# yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

//下载php源码包
[root@localhost ~]# wget https://www.php.net/distributions/php-8.2.10.tar.xz
--2023-10-18 14:42:22--  https://www.php.net/distributions/php-8.2.10.tar.xz
Resolving www.php.net (www.php.net)... 185.85.0.29, 2a02:cb40:200::1ad
Connecting to www.php.net (www.php.net)|185.85.0.29|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12041348 (11M) [application/octet-stream]
Saving to: ‘php-8.2.10.tar.xz’

php-8.2.10.tar.xz         100%[====================================>]  11.48M  2.55MB/s    in 4.5s    

2023-10-18 14:42:28 (2.55 MB/s) - ‘php-8.2.10.tar.xz’ saved [12041348/12041348]

[root@localhost ~]# ls
anaconda-ks.cfg  nginx-1.22.1.tar.gz                     php-8.2.10.tar.xz
nginx-1.22.1     oniguruma-devel-6.8.2-2.el8.x86_64.rpm
[root@localhost ~]# tar xf php-8.2.10.tar.xz 
[root@localhost ~]# cd php-8.2.10
[root@localhost php-8.2.10]# 

//编译安装
[root@localhost php-8.2.10]# ./configure --prefix=/usr/local/php8 \
--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@localhost php-8.2.10]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
[root@localhost php-8.2.10]# make install

//设置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php8.sh
[root@localhost ~]# cd php-8.2.10
[root@localhost php-8.2.10]# cp php.ini-production /etc/php.ini
[root@localhost php-8.2.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-8.2.10]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-8.2.10]# cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
[root@localhost php-8.2.10]# cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf

//编写service文件
[root@localhost php-8.2.10]# cat > /usr/lib/systemd/system/php-fpm.service <<EOF
> [Unit]
> Description=php-fpm server daemon
> After=network.target
> 
> [Service]
> Type=forking
> ExecStart=/etc/init.d/php-fpm start
> ExecStop=/etc/init.d/php-fpm stop
> ExecReload=/bin/kill -HUP $MAINPID
> 
> [Install]
> WantedBy=multi-user.target
> EOF

//配置php-fpm
[root@localhost php-8.2.10]# cat <<EOF >> /usr/local/php8/etc/php-fpm.conf
> pm.max_children = 50
> pm.start_servers = 5
> pm.min_spare_servers = 2
> pm.max_spare_servers = 8
> EOF
[root@localhost php-8.2.10]# systemctl daemon-reload
[root@localhost php-8.2.10]# systemctl enable --now php-fpm
Synchronizing state of php-fpm.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@localhost php-8.2.10]# ss -antl
State      Recv-Q      Send-Q           Local Address:Port           Peer Address:Port     Process     
LISTEN     0           511                    0.0.0.0:80                  0.0.0.0:*                    
LISTEN     0           128                    0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0           2048                 127.0.0.1:9000                0.0.0.0:*                    
LISTEN     0           80                     0.0.0.0:3306                0.0.0.0:*                    
LISTEN     0           128                       [::]:22                     [::]:*                    
LISTEN     0           80                        [::]:3306                   [::]:* 

编辑测试界面

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
[root@localhost ~]# cat /usr/local/nginx/conf/nginx.conf
location / {
            root   html;
            index  index.php index.html index.htm;     //增加一条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@localhost ~]# vim /usr/local/nginx/html/index.php 
[root@localhost ~]# cat /usr/local/nginx/html/index.php
<?php
    phpinfo();
?>
[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# setenforce 0

在这里插入图片描述

访问成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值