lnmp搭建

关闭防火墙

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# 
#创建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++ wget make
[root@localhost ~]# yum -y groups mark install 'Development Tools'
#创建日志存放目录
[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.20.1.tar.gz
#编译安装
[root@localhost ~]# tar xf nginx-1.20.1.tar.gz
[root@localhost ~]# 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 nginx-1.20.1]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost nginx-1.20.1]# . /etc/profile.d/nginx.sh
#启动nginx
[root@localhost ~]# nginx 
[root@localhost ~]# ss -antl
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port       Process        
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                         [::]:*

安装mysql

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

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

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

#解压到/usr/local/里
[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql-5.7.33-linux-glibc2.12-x86_64  sbin  share  src
[root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src

#修改属主和属组
[root@localhost local]# chown -R mysql.mysql mysql/

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

#给头文件做软连接
[root@localhost ~]# ln -s /usr/local/mysql/include /usr/include/mysql

#库文件
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib		#添加这个
[root@localhost ~]# ldconfig 

#man文档
[root@localhost ~]# vim /etc/man_db.conf 
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man
MANDATORY_MANPATH                       /usr/local/mysql/man		#添加这一行内容

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

#初始化数据库
root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/
2021-05-12T14:25:38.875806Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-12T14:25:39.516844Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-12T14:25:39.602382Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-12T14:25:39.658834Z 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: ed087633-b32d-11eb-b3ef-000c29a3d1ed.
2021-05-12T14:25:39.666061Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-12T14:25:40.418925Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-12T14:25:40.521392Z 1 [Note] A temporary password is generated for root@localhost: D!;GR)Q%o8Cs		#记住这个密码后面会用到
[root@localhost ~]# 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								#注意,这里如果这个文件里有实质性的内容,建议备份一下,再覆盖。

#配置启动脚本
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/opt/data

#启动脚本并修改密码
[root@localhost ~]# service mysqld start 
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 
[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                                  *:80                                *:*                            
LISTEN          0               128                               [::]:22                             [::]:*                            
[root@localhost ~]# dnf -y install ncurses-compat-libs
[root@localhost ~]# mysql -uroot -p'D!;GR)Q%o8Cs'
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 2
Server version: 5.7.33

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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

#设置开机自启
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

安装php

[root@localhost ~]# yum install -y php*
查看版本号
[root@localhost ~]# php -v
PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend Technologies
[root@localhost ~]#
启动php
[[root@localhost ~]# systemctl start php-fpm.service 
[root@localhost ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port Peer Address:Port Process 
LISTEN 0      128          0.0.0.0:111       0.0.0.0:*            
LISTEN 0      32     192.168.122.1:53        0.0.0.0:*            
LISTEN 0      128          0.0.0.0:22        0.0.0.0:*            
LISTEN 0      5          127.0.0.1:631       0.0.0.0:*            
LISTEN 0      128             [::]:111          [::]:*            
LISTEN 0      128             [::]:22           [::]:*            
LISTEN 0      5              [::1]:631          [::]:*            
[root@z3 ~]# ps -aux | grep php
root        3818  0.1  2.8 549564 37932 ?        Ss   05:59   0:00 php-fpm: master process (/etc/php-fpm.conf)
apache      3819  0.0  1.6 565900 21704 ?        S    05:59   0:00 php-fpm: pool www
apache      3820  0.0  1.6 565900 21708 ?        S    05:59   0:00 php-fpm: pool www
apache      3821  0.0  1.6 565900 21708 ?        S    05:59   0:00 php-fpm: pool www
apache      3822  0.0  1.6 565900 21708 ?        S    05:59   0:00 php-fpm: pool www
apache      3823  0.0  1.6 565900 21708 ?        S    05:59   0:00 php-fpm: pool www
root        3830  0.0  0.0  12112  1040 pts/1    S+   05:59   0:00 grep --color=auto php
#有php的进程但是没有php的端口

php配置


[root@localhost ~]# vim /etc/php-fpm.d/www.conf
 38  listen = /run/php-fpm/www.sock     #注释此行
 39  listen = 0.0.0.0:9000              #添加此行
 
[root@localhost ~]# systemctl restart php-fpm.service
[root@localhost ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port Peer Address:Port Process 
LISTEN 0      128          0.0.0.0:111       0.0.0.0:*            
LISTEN 0      32     192.168.122.1:53        0.0.0.0:*            
LISTEN 0      128          0.0.0.0:22        0.0.0.0:* 
LISTEN 0      128                *:80              *:*    
LISTEN 0      5          127.0.0.1:631       0.0.0.0:*            
LISTEN 0      128          0.0.0.0:9000      0.0.0.0:*            
LISTEN 0      128             [::]:111          [::]:*            
LISTEN 0      128             [::]:22           [::]:*            
LISTEN 0      5              [::1]:631          [::]:*

在nginx的访问页面目录里添加一个php的语法

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

配置nginx

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
 43         location / {
 44             root   html;
 45             index index.php index.html index.htm;
 46 


 66         location ~ \.php$ {
 67             root           /usr/local/nginx/html;
 68             fastcgi_pass   127.0.0.1:9000;
 69             fastcgi_index  index.php;
 70             fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 71             include        fastcgi.conf;
 72         }
[root@localhost ~]# nginx -s reload  重启

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值