lnmp部署

lnmp部署

先关闭防火墙selinux,命令略

nginx编译安装

创建nginx系统用户

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

安装依赖包

[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make
[root@localhost ~]# yum -y groups mark install 'Development Tools'

下载nginx

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.20.1.tar.gz
--2021-10-26 02:43:57--  http://nginx.org/download/nginx-1.20.1.tar.gz
Resolving nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5704::6, ...
Connecting to nginx.org (nginx.org)|52.58.199.22|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1061461 (1.0M) [application/octet-stream]
Saving to: ‘nginx-1.20.1.tar.gz’

nginx-1.20.1.tar.gz       100%[====================================>]   1.01M   368KB/s    in 2.8s    

2021-10-26 02:44:01 (368 KB/s) - ‘nginx-1.20.1.tar.gz’ saved [1061461/1061461]

编译安装

[root@localhost src]# ls
debug  kernels  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.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 \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[root@localhost nginx-1.20.1]# make && make install

修改日志存放目录的属组

[root@localhost ~]# chown -R nginx.nginx /var/log/nginx/

添加环境变量

[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost ~]# bash
mysql安装

将mysql5.7的二进制安装包放到/usr/src/目录下

[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels  mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz  nginx-1.20.1  nginx-1.20.1.tar.gz
[root@localhost src]#

安装登陆mysql的依赖包

[root@localhost ~]# yum -y install ncurses-compat-libs

创建mysql系统用户

[root@localhost src]# useradd -M -r -s /sbin/nologin mysql

解压并改名

[root@localhost src]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# mv /usr/local/mysql-5.7.31-linux-glibc2.12-x86_64/ /usr/local/mysql

添加环境变量

[root@localhost src]# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
[root@localhost src]# bash

创建数据存放目录并修改属组

[root@localhost src]# mkdir /opt/data
[root@localhost src]# chown -R mysql.mysql /usr/local/mysql/
[root@localhost src]# chown -R mysql.mysql /opt/data/

初始化mysql

[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data
2021-10-26T07:01:35.623869Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-10-26T07:01:35.780799Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-10-26T07:01:35.837323Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-10-26T07:01:35.905471Z 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: 8f1a9b17-362a-11ec-8412-000c2977cc9a.
2021-10-26T07:01:35.906503Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-10-26T07:01:36.432053Z 0 [Warning] CA certificate ca.pem is self signed.
2021-10-26T07:01:36.522683Z 1 [Note] A temporary password is generated for root@localhost: bo*f<rkt4djW		 ##注意保存好此处的密码
[root@localhost ~]#

写入配置文件

[root@localhost ~]# vim /etc/my.cnf
[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

配置服务启动脚本

[root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysql server daemon
After=network.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

启动mysql并修改root用户密码

[root@localhost ~]# systemctl enable --now mysqld
[root@localhost ~]# 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           80                           *:3306                      *:*
LISTEN     0           128                       [::]:22                     [::]:*
[root@localhost ~]#
[root@localhost ~]# mysql -uroot -p'bo*f<rkt4djW'  ##此处密码为刚刚初始化完成后的默认密码
[root@localhost ~]# mysql -uroot -p'bo*f<rkt4djW'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.31

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> set password = password('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye
[root@localhost ~]#
php编译安装

将php安装包放到/usr/src/目录下

[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug    mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz  nginx-1.20.1.tar.gz
kernels  nginx-1.20.1                                php-8.0.11.tar.gz
[root@localhost src]#

安装依赖包

[root@localhost src]# 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 src]# yum -y install libxml2 libxml2-devel sqlite sqlite-devel libcurl-devel readline-devel libzip libzip-devel

编译安装

[root@localhost php-8.0.11]# ./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
[root@localhost php-8.0.11]# make && make install

添加环境变量

[root@localhost php-8.0.11]# echo "export PATH=/usr/local/php/bin:$PATH" > /etc/profile.d/php.sh
[root@localhost php-8.0.11]# bash

配置并启动php

[root@localhost ~]# cp /usr/src/php-8.0.11/php.ini-production /etc/php.ini
[root@localhost ~]# cp /usr/src/php-8.0.11/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost ~]# chmod +x /etc/init.d/php-fpm
[root@localhost ~]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost ~]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[root@localhost ~]# service php-fpm start 
Starting php-fpm  done
[root@localhost ~]#
安装完成后配置

修改nginx配置文件

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
……………………略
		#access_log  logs/host.access.log  main;

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

……………………略

		# 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;									##取消注释
        }
……………………略

创建php默认页文件

[root@localhost ~]# vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>

重新加载nginx服务

[root@localhost ~]# nginx -s reload
[root@localhost ~]# ss -antl
State      Recv-Q      Send-Q           Local Address:Port           Peer Address:Port     Process     
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                     [::]:*
[root@localhost ~]#

访问web页面

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值