ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

部署LNMP

2021-10-26 16:04:00  阅读:159  来源: 互联网

标签:nginx 部署 LNMP devel -- php root localhost


部署LNMP

nginx

// 关闭防火墙和selinux
[root@localhost ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config 
SELINUX=disabled
[root@localhost ~]# reboot 
[root@localhost ~]# getenforce 0
Disabled

// 创建用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx
[root@localhost ~]# id nginx
uid=994(nginx) gid=991(nginx) 组=991(nginx)

// 安装依赖环境
[root@localhost ~]# yum -y install epel-release
[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
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make  ncurses-devel cmake mariadb-devel ncurses-compat-libs  libxml2 libxml2-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 libsqlite3x-devel oniguruma libzip-devel


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

// 下载nginx
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.20.1.tar.gz


// 编译安装
[root@localhost src]# tar xf nginx-1.20.1.tar.gz 
[root@localhost src]# cd nginx-1.20.1
[root@localhost nginx-1.21.3]# ./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.21.3]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install

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


// 启动nginx
[root@localhost ~]# nginx
[root@localhost ~]# ss -anlt
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port   
LISTEN   0        128              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               [::]:*      


// 写service文件让nginx开机自启
[root@localhost ~]# cat > /usr/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable --now  nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

MySQL


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

// 解压
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels  mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz  nginx-1.20.1.tar.gz
[root@localhost src]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

// 软连接
[root@localhost local]# mv mysql-5.7.34-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# chown -R mysql.mysql mysql/
[root@localhost local]# ln -s /usr/local/mysql/include /usr/include/mysql

// 创建数据存放目录
[root@localhost local]# mkdir /opt/data 
[root@localhost local]# chown -R mysql.mysql /opt/data

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

// 初始化
[root@localhost local]# mysqld --initialize-insecure --user mysql --datadir /opt/data
2021-10-26T06:46:13.459861Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-10-26T06:46:13.592952Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-10-26T06:46:13.613937Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-10-26T06:46:13.669318Z 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: 6968897c-3628-11ec-b95c-000c29ba9d68.
2021-10-26T06:46:13.670365Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-10-26T06:46:14.690255Z 0 [Warning] CA certificate ca.pem is self signed.
2021-10-26T06:46:14.789009Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

//编写配置文件
[root@localhost local]# 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
// 写服务控制脚本
cat > /usr/lib/systemd/system/mysqld.service << EOF
[Unit]
Description=Mysql server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start 
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/usr/local/mysql/support-files/mysql.server stop

[Install]
WantedBy=multi-user.target
basedir=/usr/local/mysql
datadir=/opt/data
EOF 


// 启动服务
[root@localhost local]# systemctl daemon-reload 
[root@localhost local]# systemctl enable --now mysqld 
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost local]# ss -anlt
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port     
LISTEN     0          128                  0.0.0.0:80                0.0.0.0:*        
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*        
LISTEN     0          80                         *:3306                    *:*        
LISTEN     0          128                     [::]:22                   [::]:*   

PHP

// 解压
[root@localhost src]# tar xf php-8.0.10.tar.xz -C /usr/local/
[root@localhost src]# cd /usr/local/php-8.0.10/

// 编译安装
[root@localhost nginx]# ./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 \ 
&& make && make install 

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

// 配置php
[root@localhost php-8.0.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 
[root@localhost php-8.0.10]# chmod +x /etc/init.d/php-fpm
[root@localhost php-8.0.10]# cd /usr/local/php8 
[root@localhost php8]# cd etc/ 
[root@localhost etc]# cp php-fpm.conf.default  php-fpm.conf
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf 
[root@localhost php-fpm.d]# ls
www.conf  www.conf.default

// 启动
[root@localhost php-fpm.d]# service php-fpm start 
Starting php-fpm  done
[root@localhost php-fpm.d]# ss -antl 
State  Recv-Q Send-Q Local Address:Port  Peer Address:Port 
LISTEN 0      128        127.0.0.1:9000       0.0.0.0:*    
LISTEN 0      128          0.0.0.0:80         0.0.0.0:*    
LISTEN 0      128          0.0.0.0:22         0.0.0.0:*    
LISTEN 0      80                 *:3306             *:*    
LISTEN 0      128             [::]:22            [::]:* 

配置nginx

// 配置网页文件
[root@localhost nginx]# cd html/
[root@localhost html]# vim index.php 
<?php
phpinfo();
?>
[root@localhost html]# chown -R nginx.nginx index.php

// 修改配置文件
[root@localhost nginx]# vim conf/nginx.conf
server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }
[root@localhost ~]# nginx -s reload 

在这里插入图片描述

标签:nginx,部署,LNMP,devel,--,php,root,localhost
来源: https://blog.csdn.net/qq_58281447/article/details/120974002

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有