关于redis:Docker安装LNMPubuntu1804nginx114mysql57php73

Docker镜像筹备

拉取ubuntu18.04镜像

docker pull ubuntu18.04

启动ubuntu容器

docker run -it --name="php7.3" --privileged=true ubuntu:18.04 /bin/bash

ubuntu更换阿里云源

备份源

mv /etc/apt/sources.list /etc/apt/sources.list.bak

更换源

    echo -e "deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe \n
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse \n
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse \n
    deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse \n
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse \n
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse \n
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse \n
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse \n
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse \n
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse" >> /etc/apt/sources.list

更新源

apt-get update

装置罕用的软件

软件装置过程中遇到:Do you want to continue? [Y/n]对立输出y而后回车

vim(必须,且必须会应用上面四个命令)

apt-get install -y vim

须要把握的vim命令

关上文件:vim 文件名

输出内容:关上文件后间接按i

退出编辑状态:按esc

敞开并保留文件:先退出编辑状态,而后按shift+:输出wq而后回车

curl(可选)

apt-get install -y curl

装置wget(可选)

apt-get install -y wget

装置niginx1.14.0

装置niginx

apt-get install -y nginx

启动nginx

service nginx start

配置nginx

创立配置目录

mkdir -p /data/nginx/conf

创立寄存网站代码目录

mkdir -p /data/nginx/code

给目录增加权限

chown :www-data -R /data/nginx

批改nginx配置,将创立的配置目录加载到配置中

vim /etc/nginx/nginx.conf

在http配置中增加 include /data/nginx/conf/*;

测试增加一个网站

创立配置文件

vim /data/nginx/conf/test.net

增加内容,保留退出

server {
    listen 80;
    server_name test.net;
    index index.html index.htm;
    root /data/nginx/code/test.net;
    
    location / {
        try_files $uri $uri/ =404;
    }
    
    location ~ /\.ht {
        deny all;
    }
}

创立代码文件

mkdir  /data/nginx/code/test.net
vim /data/nginx/code/test.net/index.html

增加内容,保留退出

<html>
    <head>
        <title>test.com</title>
    </head>
    <body>
        test build web success!
    </body>
</html>

重启nginx

service nginx restart

批改本机hosts

vim /etc/hosts

在文件开端增加 127.0.0.1 test.net ,保留退出

测试拜访

#此操作须要装置curl
curl test.net

至此nginx装置实现

装置PHP7.3

增加PPA源反对

apt-get install software-properties-common

源增加php

add-apt-repository ppa:ondrej/php

更新源

apt-get update

装置PHP

装置php7.3

apt-get install php7.3-fpm

抉择时区步骤一:输出6 + 回车

抉择时区步骤二:输出70 + 回车

装置php扩大

以后命令装置了全副扩大,能够按需装置

apt-get install php7.3-bz2 php7.3-curl php7.3-fileinfo php7.3-gd php7.3-gettext php7.3-gmp php7.3-intl php7.3-imap php7.3-interbase php7.3-ldap php7.3-mbstring php7.3-exif php7.3-mysqli php7.3-odbc php7.3-pgsql php7.3-shmop php7.3-snmp php7.3-soap php7.3-sockets php7.3-sqlite3 php7.3-tidy php7.3-xmlrpc php7.3-xsl php7.3-redis php7.3-pdo

验证PHP是否装置胜利

php -v

能够输出php -m 查看已装置扩大

装置mysql5.7

装置mysql

apt-get install mysql-server-5.7

启动mysql服务

service mysql start

查看mysql账户明码

cat /etc/mysql/debian.cnf

应用账号密码登陆

mysql -h localhost -u debian-sys-maint -p

批改root明码

use mysql;
update user set authentication_string=PASSWORD("root") where user='root';
update user set plugin="mysql_native_password";
flush privileges;

批改数据库编码格局

vim /etc/mysql/mysql.conf.d/mysqld.cnf
#在文件开端增加
character_set_server=utf8
collation_server=utf8_general_ci
vim /etc/mysql/my.cnf
#在文件开端增加
[mysql]
default-character-set=utf8

重启mysql服务

service mysql restart

开启近程拜访

#连贯mysql
mysql -u root -p
#抉择数据库
use mysql;
#开启近程受权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
#刷新权限
FLUSH PRIVILEGES; 
#退出
exit

批改配置文件

vim /etc/mysql/mysql.conf.d
#将bind-address正文掉
#重启mysql
service mysql restart

启动报错No directory, logging in with HOME=/

usermod -d /var/lib/mysql/ mysql

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

chown -R mysql:mysql /var/lib/mysql

解决工夫戳格局报错

vim /etc/mysql/mysql.conf.d/mysqld.cnf

在文件开端增加

sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

nginx增加php反对

启动php-fpm

service php7.3-fpm start

test.net站点的nginx配置批改

server {
    listen 80;
    server_name test.net;
    index index.php index.html index.htm;
    root /data/nginx/code/test.net;
    
    location / {
        try_files $uri $uri/ =404;
    }
    
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #次要代码
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    
    location ~ /\.ht {
        deny all;
    }
}

站点增加php文件

vim /data/nginx/code/test.net/index.php

文件内容

<?php
    phpinfo();

装置composer(可选)

#下载安装文件
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

#验证安装文件
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

#下载composer
php composer-setup.php --install-dir=/usr/local/bin --filename=composer

#删除安装文件
php -r "unlink('/usr/local/bin/composer-setup.php');"

验证composer:composer -v

装置git(可选)

apt-get install git

装置nodejs(可选)

#...
curl -sL https://deb.nodesource.com/setup_14.x | bash -
#更新源
apt-get update
#装置nodejs
apt-get install -y nodejs

装置redis6.2(可选)

装置

#增加源
add-apt-repository ppa:redislabs/redis
#更新源
apt-get update
#装置
apt-get install redis

启动

service redis-server start

连贯redis

redis-cli

redis开启近程拜访

vim /etc/redis/redis.conf

正文掉bind行,在行头增加#
protected-mode 批改为no

【腾讯云】轻量 2核2G4M,首年65元

阿里云限时活动-云数据库 RDS MySQL  1核2G配置 1.88/月 速抢

本文由乐趣区整理发布,转载请注明出处,谢谢。

您可能还喜欢...

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据