LNMP 部署安装

LNMP概述
LNMP代表的就是:Linux系统下Nginx

文章目录

  • LNMP编译安装
    • 安装 Nginx
    • Mysql 编译安装
    • PHP安装
    • 测试
    • 构成 Discuz 论坛

LNMP编译安装

安装 Nginx

编译安装

[root@5centos ~]# mkdir /bianyi
[root@5centos ~]# cd /bianyi/
[root@5centos bianyi]# rz -E
rz waiting to receive.
[root@5centos bianyi]# tar zxvf nginx-1.12.2.tar.gz
[root@5centos nginx-1.12.2]# yum -y install gcc gcc-c++ make pcre-devel expat-devel perl zlib-devel pcre
[root@5centos nginx-1.12.2]# useradd -M -s /sbin/nologin nginx
[root@5centos nginx-1.12.2]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module
> [root@5centos nginx-1.12.2]# make && make install

路径优化 增添系统控制

[root@5centos /]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@5centos /]# vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
PIDFile =/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/bin/kill -S HUP $MAINPID
ExecStop=/usr/bin/kill -S QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
##具体解释看我上一篇安装 nginx 的blog
[root@5centos /]# systemctl start nginx
[root@5centos /]# chmod 754 /lib/systemd/system/nginx.service 

LNMP 部署安装_第1张图片

Mysql 编译安装

依赖安装

[root@5centos /]# yum -y install ncurses ncurses-devel bison cmake

编译安装 Mysql

[root@5centos /]# useradd -s /usr/sbin/nologin mysql
[root@5centos bianyi]# rz -E
rz waiting to receive.
[root@5centos bianyi]# ls
mysql-boost-5.7.20.tar.gz  nginx-1.12.2  nginx-1.12.2.tar.gz
[root@5centos bianyi]# tar zxvf mysql-boost-5.7.20.tar.gz
[root@5centos mysql-5.7.20]# cmake \
> -DCMKAE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
> -DSYSCONFIDIR=/etc \
> -DSYSTEMD_PID_DIR=/usr/local/mysql \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_INNOBASE_STORAGE_ENGING=1 \
> -DWITH_ARCHIVE_STORAGE_ENGING=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGING=1 \
> -DWITH_PERFSCHEMA_STORAGE_ENGING=1 \
> -DMYSQL_DATADIR=/usr/local/mysql/data \
> -DWITH_BOOST=boost \
> -DWITH_SYSTEMD=1
[root@5centos mysql-5.7.20]# make && make install
[root@5centos /]# chown -R mysql:mysql /usr/local/mysql/

编辑配置文件

[root@5centos /]# vim /etc/my.cnf
##删除源文件全部内容,手敲如下
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

设置环境变量

[root@5centos /]# echo "PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH" >> /etc/profile
[root@5centos /]# echo 'export PATH' >> /etc/profile
[root@5centos /]# source /etc/profile

初始化数据库

[root@5centos /]# cd /usr/local/mysql/
[root@5centos mysql]# bi
bind         biosdecode   biosdevname  bison        
[root@5centos mysql]# bin/mysqld \
> --initialize-insecure \
> --user=mysql \
> --basedir=/usr/local/mysql \
> --datadir=/usr/local/mysql/data
[root@5centos mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[root@5centos mysql]# systemctl start mysqld
[root@5centos mysql]# netstat -natp |grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      87537/mysqld

设置mysql密码

[root@5centos /]# mysqladmin -u root -p password
Enter password: 
New password: 
Confirm new password: 
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@5centos mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 Source distribution
……省略部分……
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

PHP安装

安装依赖

[root@5centos /]# yum -y install \
> libjpeg \
> libjpeg-devel \
> libpng \
> libpng-devel \
> freetype \
> freetype-devel \
> libxml2 \
> libxml2-devel \
> zlib \
> zlib-devel \
> curl \
> curl-devel \
> openssl \
> openssl-devel

编译安装

[root@5centos /]# cd /bianyi/
[root@5centos bianyi]# rz -E
rz waiting to receive.
[root@5centos bianyi]# ls
mysql-5.7.20               nginx-1.12.2         php-7.1.10.tar.bz2
mysql-boost-5.7.20.tar.gz  nginx-1.12.2.tar.gz
[root@5centos bianyi]# tar jxvf php-7.1.10.tar.bz2 
[root@5centos php-7.1.10]# ./configure \
> --prefix=/usr/local/php \
> --with-mysql-sock=/usr/local/mysql/mysql.sock \
> --with-mysqli \
> --with-zlib \
> --with-curl \
> --with-gd \
> --with-jpeg-dir \
> --with-png-dir \
> --with-freetype-dir \
> --with-openssl \
> --enable-fpm \
> --enable-mbstring \
> --enable-xml \
> --enable-session \
> --enable-ftp \
> --enable-pdo \
> --enable-tokenizer \
> --enable-zip

配置 文件
php有三个配置文件 php.ini核心配置文件 php-fpm.conf进程服务配置文件www.conf 扩展配置文件’

[root@5centos php-7.1.10]# cp -p php.ini-development /usr/local/php/lib/php.ini
[root@5centos php-7.1.10]# vim /usr/local/php/lib/php.ini
1170 mysqli.default_socket = /usr/local/mysql/mysql.sock
 939 date.timezone = Asia/Shanghai

启动服务

[root@5centos etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
[09-Aug-2020 18:47:39] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)
[09-Aug-2020 18:47:39] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
[09-Aug-2020 18:47:39] ERROR: FPM initialization failed

报错,进行查错

[root@5centos /]# cd /usr/local/php/etc/
[root@5centos etc]# cp php-fpm.conf.default php-fpm.conf
[root@5centos etc]# cd /usr/local/php/etc/php-fpm.d/
[root@5centos php-fpm.d]# cp www.conf.default www.conf
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
[root@5centos etc]# netstat -ntap |grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      96964/php-fpm: mast 
[root@5centos /]# ln -s /usr/local/php/bin/* /usr/local/bin/

测试

让 Nginx 支持 PHP

[root@5centos /]# vim /usr/local/nginx/conf/nginx.conf
        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@5centos /]# vim /usr/local/nginx/html/index.php

~      
[root@5centos /]# systemctl restart nginx

LNMP 部署安装_第2张图片创建数据库

[root@5centos /]# mysql -u root -p
mysql> CREATE DATABASE ORA;
Query OK, 1 row affected (0.01 sec)

mysql> GRANT ALL ON ORA.* TO 'orauser'@'%' IDENTIFIED BY 'user123'
    -> ;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> GRANT ALL ON ORA.* TO 'orauser'@'localhost' IDENTIFIED BY 'user123';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges
    -> ;
Query OK, 0 rows affected (0.01 sec)


[root@5centos /]# vim /usr/local/nginx/html/index.php 
Success!!";
else echo "Fail!!";
?>
~   
[root@5centos /]# systemctl restart nginx.service

LNMP 部署安装_第3张图片

构成 Discuz 论坛

  144  cd /bianyi/
  145  rz -E
  146  ls
  147  unzip Discuz_X3.4_SC_UTF8.zip
 [root@5centos bianyi]# cd dir_SC_UTF8/
cd/opt
unzip Discuz_X3.4_SC_UTF8.zip -d /tmp
cd /tmp/dir_SC_UTF8/
[root@5centos ora]# chown -R root:nginx ./config/
[root@5centos ora]# chown -R root:nginx ./data/
[root@5centos ora]# chown -R root:nginx ./uc_client/
[root@5centos ora]# chown -R root:nginx ./uc_server/
[root@5centos ora]# 
[root@5centos ora]# chmod -R 777 ./config/
[root@5centos ora]# chmod -R 777 ./data/
[root@5centos ora]# chmod -R 777 ./uc_client/
[root@5centos ora]# chmod -R 777 ./uc_server/

LNMP 部署安装_第4张图片

LNMP 部署安装_第5张图片
LNMP 部署安装_第6张图片

你可能感兴趣的:(网页网站服务,linux,mysql,nginx,html)