lnmp

lnmp=linux+nginx+mysql+php

1.nginx的安装

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

//创建用户
[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 ~]# cd /usr/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.18.0.tar.gz

//编译安装
[root@localhost src]# ls
debug  kernels  nginx-1.18.0.tar.gz
[root@localhost src]# tar xf nginx-1.18.0.tar.gz 
[root@localhost src]# cd nginx-1.18.0
[root@localhost nginx-1.18.0]# ./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.18.0]# make && make install

//设置环境变量
[root@localhost nginx-1.18.0]#  echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost nginx-1.18.0]# . /etc/profile.d/nginx.sh 
[root@localhost nginx-1.18.0]# nginx
[root@localhost nginx-1.18.0]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     *:80                  *:*                  
LISTEN      0      128     *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128    :::22                 :::*                  
LISTEN      0      100       ::1:25                 :::*                  

2.mysql安装

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

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


//下载二进制格式的mysql软件包
[root@localhost ~]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

//解压软件至/usr/local/
[root@localhost ~]# ls
anaconda-ks.cfg                             original-ks.cfg
mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# tar xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.7.30-linux-glibc2.12-x86_64 mysql

//修改目录/usr/local/mysql的属主属组
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql

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

//建立数据存放目录
[root@localhost ~]# mkdir mysqldata
[root@localhost ~]#  chown -R mysql.mysql mysqldata/

//初始化数据库
[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/root/mysqldata
2020-07-30T11:07:13.585807Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-07-30T11:07:14.450868Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-07-30T11:07:14.485195Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-07-30T11:07:14.564024Z 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: d2e6acbd-d254-11ea-8e0a-000c29296d75.
2020-07-30T11:07:14.581412Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-07-30T11:07:15.179895Z 0 [Warning] CA certificate ca.pem is self signed.
2020-07-30T11:07:15.388582Z 1 [Note] A temporary password is generated for root@localhost: UslArIp7zd=C
[root@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# ldconfi -l
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /mysqldata
socket = /tmp/mysql.sock
port = 3306
pid-file = /mysqldata/mysql.pid
user = mysql
skip-name-resolve
[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(datadir=).*#\1/mysqldata#g' /etc/init.d/mysqld
[root@localhost ~]# vim /etc/in
init.d/  inittab  inputrc  
[root@localhost ~]# vim /etc/init.d/mysqld 
[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/mysqldata/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost ~]# ss -antl
State      Recv-Q Send-Q       Local Address:Port                      Peer Address:Port              
LISTEN     0      128                      *:22                                   *:*                  
LISTEN     0      128                     :::80                                  :::*                  
LISTEN     0      128                     :::22                                  :::*                  
LISTEN     0      80                      :::3306                                :::*                  
[root@localhost ~]# 

// 设置数据库密码
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.30 MySQL Community Server (GPL)

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

mysql> exit

3 安装php

//配置yum源
[root@localhost ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm

//安装依赖包
[root@localhost ~]# 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 php74-php-mysqlnd libsqlite3x-devel oniguruma-devel

//下载php
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://cn.php.net/distributions/php-7.4.7.tar.xz

//编译安装
[root@localhost src]# cd php-7.4.7
[root@localhost php-7.4.7]# ./configure --prefix=/usr/local/php7  \
 --with-config-file-path=/etc \
 --enable-fpm \
 --enable-inline-optimization \
 --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-json \
 --enable-mbstring \
 --enable-pdo \
 --with-mysqli=mysqlnd \
 --with-pdo-mysql=mysqlnd \
 --with-readline \
 --enable-shmop \
 --enable-simplexml \
 --enable-sockets \
 --enable-mysqlnd-compression-support \
 --with-pear \
 --enable-pcntl \
 --enable-posix
[root@localhost php-7.4.7]# make && make install

//安装后配置
[root@localhost php-7.4.7]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost php-7.4.7]# source /etc/profile.d/php7.sh 
[root@localhost php-7.4.7]# php -v
PHP 7.4.7 (cli) (built: Aug  7 2020 03:15:04) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

//配置php-fpm
[root@localhost php-7.4.7]# cp php.ini-production /etc/php.ini
[root@localhost php-7.4.7]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.4.7]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-7.4.7]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-7.4.7]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[root@localhost php-7.4.7]# service php-fpm start
Starting php-fpm  done
[root@localhost php-7.4.7]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128     *:80                  *:*                  
LISTEN     0      128     *:22                  *:*                  
LISTEN     0      100    127.0.0.1:25                  *:*                  
LISTEN     0      128    127.0.0.1:9000                *:*                  
LISTEN     0      128    :::22                 :::*                  
LISTEN     0      100       ::1:25                 :::*                  
[root@localhost php-7.4.7]# 

4.配置虚拟主机

//创建虚拟主机目录并生成php测试页面
[root@localhost ~]# vim /usr/local/nginx/html/index.php
[root@localhost ~]# cat /usr/local/nginx/html/index.php 
<?php
   phpinfo();
?>
[root@localhost ~]# chown -R nginx.nginx /usr/local/nginx/html/

//编辑nginx的配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
index  index.php index.htm;   //添加一个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;   //web页面存放路径的变量
            include        fastcgi_params;  
        }

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值