源码部署LNMP

源码部署LNMP

主机名ip系统版本nginx版本php版本MySQL版本
kiwi123192.168.234.123CentOS81.22.18.2.10mariad-10.3

1. 源码编译安装nginx

//关闭防火墙以及SELinux
[root@kiwi123 nginx-1.22.1]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@kiwi123 nginx-1.22.1]# setenforce 0
[root@kiwi123 nginx-1.22.1]# sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config


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


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


//下载安装包
[root@kiwi123 ~]# wget http://nginx.org/download/nginx-1.22.1.tar.gz

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

//开始解压并编译安装
[root@kiwi123 ~]# tar xf nginx-1.22.1.tar.gz && cd nginx-1.22.1
[root@kiwi123 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 && make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install


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

//配置systemctl文件
[root@kiwi123 nginx-1.22.1]# vim /usr/lib/systemd/system/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

[Install]
WantedBy=multi-user.target

[root@kiwi123 nginx-1.22.1]# systemctl daemon-reload


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

2. 源码编译安装php

//获取php安装包
[root@kiwi123 ~]# wget https://www.php.net/distributions/php-8.2.10.tar.gz


//安装php依赖环境,要配置epel源
[root@kiwi123 ~]# yum install -y libzip libzip-devel sqlite-devel oniguruma* libxml2-devel 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
[root@kiwi123 ~]# yum install -y http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

//解压安装包并进入
[root@kiwi123 ~]# tar xf php-8.2.10.tar.gz 
[root@kiwi123 ~]# cd php-8.2.10
[root@kiwi123 php-8.2.10]# 


//开始预编译
[root@kiwi123 ~]# ./configure --prefix=/usr/local/php  \
             --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   &&\
make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install

//添加环境变量
[root@kiwi123 php-8.2.10]# echo 'export PATH=/usr/local/php/bin:$PATH' > /etc/profile.d/php.sh

//复制php.ini
[root@kiwi123 php-8.2.10]# cp php.ini-production /etc/php.ini

//配置php-fpm
[root@kiwi123 php-8.2.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

//添加执行权限
[root@kiwi123 php-8.2.10]# chmod +x /etc/rc.d/init.d/php-fpm

//配置php-fpm.conf
[root@kiwi123 php-8.2.10]# cd /usr/local/php/etc
[root@kiwi123 etc]# cp php-fpm.conf.default php-fpm.conf

//配置php-fpm.d/www.conf
[root@kiwi123 etc]# cp php-fpm.d/www.conf.default php-fpm.d/www.conf

//添加优化配置
[root@kiwi123 etc]# cat >> /usr/local/php/etc/php-fpm.conf<<EOF
> pm.max_children = 50
> pm.start_servers = 5
> pm.min_spare_servers = 2
> pm.max_spare_servers = 8
> EOF
[root@kiwi123 etc]# 

//创建php页面
[root@kiwi123 ~]# cd /usr/local/nginx/html
[root@kiwi123 html]# vim index.php
[root@kiwi123 html]# cat index.php 
<?php
   phpinfo();
?>
[root@kiwi123 html]# ls
50x.html  index.html  index.php

//修改nginx配置文件
[root@kiwi123 ~]# cd /usr/local/nginx/
[root@kiwi123 nginx]# vim conf/nginx.conf
[root@kiwi123 nginx]# cat conf/nginx.conf

·······································略

    server {
        listen       80;
        server_name  www.kiwi123.com;   ## 修改这一行

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        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;      ## 取消注释
        }                                       ## 取消注释
 
 ·····································略
 
//启动nginx
[root@kiwi123 ~]# nginx 

//启动php
[root@kiwi123 ~]# /etc/rc.d/init.d/php-fpm start

3.安装mariadb

[root@kiwi123 ~]# yum install -y mariadb*

//启动mariadb
[root@kiwi123 ~]# systemctl enable --now mariadb

查看页面,部署成功

image-20231018162927425

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值