(VPS)Centos7 安装LNMP环境

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 就最近买了VPS,才有了这些文章.准备开始写博客了.环境我们采用比较流行的,相对百度老的资料,本文还是相对比较新的.也许希望大家给以后的小站支持.LNMP:CentOS7+PHP7+Nginx+MariaDB如果文章有错,请指出,方便修正!软件包...

就最近买了VPS,才有了这些文章.准备开始写博客了.环境我们采用比较流行的,相对百度老的资料,本文还是相对比较新的.也许希望大家给以后的小站支持.
LNMP:CentOS7+PHP7+Nginx+MariaDB
如果文章有错,请指出,方便修正!


软件包更新:

sudo yum update -y

epel,remi库登记

sudo yum -y install epel-release
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
sudo rpm -ivh remi-release-7.rpm

vim,git安装

sudo yum install vim git

修改时间(我国外的VPS,所以改不改都无所谓)

sudo timedatectl set-timezone Asia/xxx

Nginx安装

sudo rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
sudo yum -y install nginx

Nginx的设置

/etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  example.com;

    access_log  /var/log/nginx/laos.access.log;
    error_log  /var/log/nginx/laos.error.log warn;

    root   /vagrant/laos/webroot;
    index  index.html index.php;

    location / {
        try_files $uri $uri?$args $uri/ /index.php?$uri&$args /index.php?$args;
    }

    location ~ \.php$ {
        try_files      $uri =404;
        fastcgi_pass   unix:/var/run/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

目录位置:/etc/nginx/nginx.conf

user  nginx;
worker_processes  auto;
worker_rlimit_nofile 100000;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  2048;
    multi_accept on;
    use epoll;
}


http {
    server_tokens off;
    include       /etc/nginx/mime.types;
    default_type  text/html;
    charset UTF-8;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile       off;
    tcp_nopush     on;
    tcp_nodelay    on;


    keepalive_timeout 10;
    client_header_timeout 10;
    client_body_timeout 10;
    reset_timedout_connection on;
    send_timeout 10;

    limit_conn_zone $binary_remote_addr zone=addr:5m;
    limit_conn addr 100;

    gzip on;
    gzip_http_version 1.0;
    gzip_disable "msie6";
    gzip_proxied any;
    gzip_min_length 1024;
    gzip_comp_level 6;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;
    open_file_cache off;

    client_max_body_size 20m;
    server_names_hash_bucket_size 64;
    include /etc/nginx/conf.d/*.conf;
}

Nginx起動

sudo systemctl start nginx
sudo systemctl enable nginx

PHP7安装(安装必要的包)

sudo yum --enablerepo=epel,remi,remi-php70w install php70w php70w-php-mcrypt php70w-php-mbstring php70w-php-fpm php70w-php-gd php70w-php-pecl-xdebug php70w-php-pecl-redis php70w-php-pecl-imagick-devel php70w-php-pecl-imagick php70wphp-mysqlnd php70w-php-intl php70w-php-bcmath php70w-php-pecl-zip php70w-php-xmlrpc php70w-php-xml  php70w-php-pecl-http php70w-php-pecl-http-devel php70w-php-opcache

Nginx通过路劲

cat /opt/remi/php70/enable
export PATH=/opt/remi/php70/root/usr/bin:/opt/remi/php70/root/usr/sbin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/remi/php70/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/remi/php70/root/usr/share/man:${MANPATH}

~/.bashrc

export PATH=/opt/remi/php70/root/usr/bin:/opt/remi/php70/root/usr/sbin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/remi/php70/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/remi/php70/root/usr/share/man:${MANPATH}

source ~/.bashrc

確認

/etc/opt/remi/php70/php-fpm.d/www.conf

user = nginx
group = nginx
listen = /var/run/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0666

php-fpm起動

/etc/systemd/system/php-fpm.service


[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/var/run/php-fpm.pid
ExecStart=/opt/remi/php70/root/usr/sbin/php-fpm --nodaemonize --fpm-config /etc/opt/remi/php70/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID


[Install]
WantedBy=multi-user.target
sudo systemctl start php-fpm
sudo systemctl enable php-fpm

为了能够是HTTP防火墙设置访问

sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

MariaDB安装(从官方请从网站资料库)

/etc/yum.repos.d/mariadb.repo

# MariaDB 10.1 CentOS repository list - created 2017-01-16 10:19 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

MariaDB正式安装

sudo yum install MariaDB-server MariaDB-client MariaDB-devel 

设置

sudo mkdir /home/mysql
sudo chown mysql. /home/mysql

/etc/my.cnf.d/server.cnf

[mysqld]
character-set-server=utf8
plugin-load = handlersocket.so
log-bin=mysql-bin
expire_logs_days = 30
secure_file_priv=/home/mysql

起動

sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

初回设定

mysql_secure_installation

连接

mysql -u root -p
CREATE SCHEMA `laos` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
11天前
|
Linux 网络安全 Python
linux centos上安装python3.11.x详细完整教程
这篇文章提供了在CentOS系统上安装Python 3.11.x版本的详细步骤,包括下载、解压、安装依赖、编译配置、解决常见错误以及版本验证。
81 1
linux centos上安装python3.11.x详细完整教程
|
2月前
|
消息中间件 Linux API
centos7 安装rabbitmq自定义版本及配置
centos7 安装rabbitmq自定义版本及配置
|
9天前
|
Unix Linux 开发工具
centos的官网下载和vm16虚拟机安装centos8【保姆级教程图解】
本文详细介绍了如何在官网下载CentOS 8以及在VMware Workstation Pro 16虚拟机上安装CentOS 8的步骤,包括可能出现的问题和解决方案,如vcpu-0错误的处理方法。
centos的官网下载和vm16虚拟机安装centos8【保姆级教程图解】
|
9天前
|
消息中间件 Linux
centos7安装rabbitmq
centos7安装rabbitmq
|
9天前
|
Linux 虚拟化 Windows
完美解决:重新安装VMware Tools灰色。以及共享文件夹的创建(centos8)
这篇文章提供了解决VMware Tools无法重新安装(显示为灰色)问题的步骤,并介绍了如何在CentOS 8上创建和配置VMware共享文件夹。
完美解决:重新安装VMware Tools灰色。以及共享文件夹的创建(centos8)
|
10天前
|
Docker 容器
centos7.3之安装docker
centos7.3之安装docker
|
2月前
|
弹性计算 关系型数据库 MySQL
centos7 mysql安装及配置
本文详细介绍了在阿里云服务器ECS上通过yum源安装MySQL 8.0.12的过程,包括更新yum源、下载并安装MySQL源、解决安装过程中可能遇到的问题等步骤。此外,还介绍了如何启动MySQL服务、设置开机自启、配置登录密码、添加远程登录用户以及处理远程连接异常等问题。适合初学者参考,帮助快速搭建MySQL环境。
159 8
centos7 mysql安装及配置
|
10天前
|
NoSQL Linux Redis
linux之centos安装redis
linux之centos安装redis
|
1月前
|
存储 Linux Docker
CentOS 7.6安装Docker实战案例及存储引擎和服务进程简介
关于如何在CentOS 7.6上安装Docker、介绍Docker存储引擎以及服务进程关系的实战案例。
93 3
CentOS 7.6安装Docker实战案例及存储引擎和服务进程简介
|
5天前
|
缓存 Linux 开发工具
CentOS7 安装KDE报错的解决方法:Loaded plugins:fastestmirror,langpacks There is no installed group.
CentOS7 安装KDE报错的解决方法:Loaded plugins:fastestmirror,langpacks There is no installed group.
14 0
下一篇
无影云桌面