阿里云ECS服务器安装纯净版centos7.4 LNMP教程
yum 安装依赖(很重要)yum -y install php-mcrypt libmcrypt-devel libxml2 libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt libxslt-devel cyrus-sasl-plain cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib m4 autoconf gcc gcc-c++ openssl openssl-devel pcre pcre-devel zlib zlib-devel wget net-tools zip unzip bzip2 下载必要安装包wget -O nginx-1.12.1.tar.gz https://nginx.org/download/nginx-1.12.1.tar.gz //nginx 安装包 wget -O php-7.2.tar.gz http://cn2.php.net/get/php-7.2.3.tar.gz/from/this/mirror //php7.2安装1 安装nginx1.1 解压编译安装nginx(安装在/server/nginx目录下)tar zxvf nginx-1.12.1.tar.gz //解压 cd nginx-1.12.1/ //进入解压后的目录,###下面的代码复制每行行尾会有空格,请自行复制到文本编辑中去掉 ./configure \ --prefix=/server/nginx \ --pid-path=/server/var/nginx/nginx.pid \ --lock-path=/server/var/nginx/nginx.lock \ --error-log-path=/server/var/nginx/error.log \ --http-log-path=/server/var/nginx/access.log \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-http_ssl_module 1.2安装make && make install1.3 安装完成后,开启nginx 服务/server/nginx/sbin/nginx1.3.1 可以将nginx 命令加入环境变量中,方便使用(此三步可以忽略)vi /etc/profile1.3.2 在文件末尾加入export PATH="$PATH:/server/nginx/sbin"1.3.3 保存退出后,使之立即生效source /etc/profile1.4 访问IP地址,如果没出现nginx欢迎页面,则开通防火墙80端口查看防火墙状态firewall-cmd --state打开80端口firewall-cmd --zone=public --add-port=80/tcp --permanent命令含义:--zone #作用域 --add-port=80/tcp #添加端口,格式为:端口/通讯协议 --permanent #永久生效,没有此参数重启后失效 重启防火墙firewall-cmd --reload防火墙常用命令介绍firewall-cmd --state ##查看防火墙状态,是否是running firewall-cmd --reload ##重新载入配置,比如添加规则之后,需要执行此命令 firewall-cmd --get-zones ##列出支持的zone firewall-cmd --get-services ##列出支持的服务,在列表中的服务是放行的 firewall-cmd --query-service ftp ##查看ftp服务是否支持,返回yes或者no firewall-cmd --add-service=ftp ##临时开放ftp服务 firewall-cmd --add-service=ftp --permanent ##永久开放ftp服务 firewall-cmd --remove-service=ftp --permanent ##永久移除ftp服务 firewall-cmd --add-port=80/tcp --permanent ##永久添加80端口 iptables -L -n ##查看规则,这个命令是和iptables的相同的 man firewall-cmd ##查看帮助 firewall-cmd --list-ports ##查看防火墙开启的端口 至此nginx安装完成 2 安装PHP7 2.1 解压编译安装php7(安装目录/server/php7) tar zxvf php-7.2.tar.gz //解压cd php-7.2.3 //进入安装目录 ###下面的代码复制每行行尾会有空格,请自行复制到文本编辑中去掉./configure --prefix=/server/php7 \ --with-config-file-path=/server/php7/etc \ --with-curl \ --with-gd \ --with-gettext \ --with-iconv-dir \ --with-kerberos \ --with-libdir=lib64 \ --with-libxml-dir \ --with-openssl \ --with-pcre-regex \ --with-pdo-sqlite \ --with-pear \ --with-xmlrpc \ --with-xsl \ --with-zlib \ --enable-fpm \ --enable-bcmath \ --enable-libxml \ --enable-inline-optimization \ --enable-mbregex \ --enable-mbstring \ --enable-opcache \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvsem \ --enable-xml \ --enable-zip \ --enable-static \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --disable-debug \ --disable-fileinfo \ --enable-maintainer-zts 2.2 安装make && make install时间较长(根据机器性能决定,1G1核 大概在15分钟) 2.3 安装完成后,将php加入环境变量,添加php配置文件cp php.ini-production /server/php7/etc/php.ini //添加配置文件vi /etc/profile //编辑环境变量文件在文件中添加export PATH="$PATH:/server/php7/bin"使改动立即生效source /etc/profile 查看php版本php -v2.4 配置php-fpmcp /server/php7/etc/php-fpm.conf.default /server/php7/etc/php-fpm.conf cp /server/php7/etc/php-fpm.d/www.conf.default /server/php7/etc/php-fpm.d/www.conf cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm //添加执行权限 启动php-fpm/etc/init.d/php-fpm start至此php7安装完成 3 yum安装mariadb 10 3.1 添加仓库vi /etc/yum.repos.d/MariaDB.repo文件中添加代码[mariadb] name = MariaDB baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64 gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck=1 注:以上的源,如果无效,则使用下方官网的源[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.2/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=13.2 编辑保存退出后,安装yum install -y MariaDB-server MariaDB-client3.3 安装成功后启动systemctl start mariadb //启动程序systemctl enable mariadb // 自启动systemctl status mariadb //查看状态3.4 配置mariadb设置Root 用户的登陆密码mysql_secure_installation根据命令提示,主要是做以下几件事情: 设置root密码 是否禁止远程 root访问 是否禁止 test数据库的访问 是否禁用匿名用户 是否重新加载privilleges-table信息 初始化完成后,登录测试mysql -uroot -p //代表你之前初始化设置的密码 exit命令可以退出配置字符集vi /etc/my.cnf在[mysqld]标签下添加init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake vi /etc/my.cnf.d/mysql-clients.cnf在[mysql]中添加default-character-set=utf8全部配置完成,重启mariadbsystemctl restart mariadb之后进入MariaDB查看字符集mysql -uroot -p //代表密码mysql> show variables like "%character%";show variables like "%collation%"; //至此mariadb 安装完成。但是如果想要外面能访问此数据库,如想使用navicat来连接到这个数据库,则还要其它的配置,您往下看 首先开放防火墙端口,开启后要重启防火墙:firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload mysql>create user username@localhost identified by 'password';直接创建用户并授权的命令mysql>grant all on . to username@localhost identified by 'password';授予外网登陆权限 ,这里授权用户可以外网访问此数据库,如用数据库连接工具navicat连接mysql>grant all privileges on . to username@'%' identified by 'password';授予权限并且可以授权mysql>grant all privileges on . to username@'hostname' identified by 'password' with grant option;简单的用户和权限配置基本就这样了。 其中只授予部分权限把 其中 all privileges或者all改为select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分。