LANMP笔记
更换aliyun的yum源、添加 epel源
# 更换aliyun的yum源
[root@VM_0_4_centos ~]# cd /etc/yum.repos.d/
[root@VM_0_4_centos ~]# cp CentOS-Base.repo CentOS-Base.repo.bak
[root@VM_0_4_centos ~]# wget -O CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 添加 epel源
[root@VM_0_4_centos ~]# yum install -y epel-release # 命令行安装
// 手动安装 rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@VM_0_4_centos ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# 更新
[root@VM_0_4_centos ~]# yum clean all && yum makecache
[root@VM_0_4_centos ~]# yum -y update
预装libunwind
# 对于64位的linux系统,部分工具需要在libunwind环境下运行,如用于优化系统运行效率的tcmalloc、堆外内存分析工具google-perftools在64位linux系统下都需要libunwind才能运行
[root@VM_0_4_centos ~]# yum install libunwind
安装依赖文件
//yum install gcc gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel apr apr-util pcre
//当前使用的CentOS Linux release 7.5.1804版本需要安装的依赖文件(大部分已经有了,devel版在这里不安装)
//查看下需要安装的依赖文件版本
[root@VM_0_4_centos ~]# yum list gcc gcc-c++ libmcrypt
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages
gcc.x86_64 4.8.5-28.el7_5.1 updates
gcc-c++.x86_64 4.8.5-28.el7_5.1 updates
libmcrypt.x86_64 2.5.8-13.el7 epel
[root@VM_0_4_centos ~]# yum -y install gcc gcc-c++ libmcrypt
yum源安装php7.2 安装php扩展的参考链接
添加epel源后可以使用yum源安装php5.5+的版本
[root@VM_0_4_centos ~]# yum -y install mod_php72w php72w-common php72w-fpm php72w-opcache php72w-gd php72w-mysqlnd php72w-mbstring php72w-pecl-redis php72w-pecl-memcached php72w-devel php72w-ldap php72w-mcrypt php72w-pdo php72w-xml
安装memcached 和 redis
yum install -y memcached redis
查看当前系统的release版本
[root@VM_0_4_centos ~]# more /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
或者
[root@VM_0_4_centos ~]# yum install redhat-lsb -y
[root@VM_0_4_centos ~]# lsb_release -a
安装lrzsz工具
用于windows和linux间传输文件
# yum -y install lrzsz
防火墙设置开启80端口433端口8080端口
[root@VM_0_4_centos ~]# systemctl start firewalld
[root@VM_0_4_centos ~]# firewall-cmd --permanent --zone=public --add-service=http
[root@VM_0_4_centos ~]# firewall-cmd --permanent --zone=public --add-service=https
[root@VM_0_4_centos ~]# firewall-cmd --permanent --zone=public --add-port=8080/tcp
[root@VM_0_4_centos ~]# firewall-cmd --permanent --zone=public --add-port=3306/tcp
[root@VM_0_4_centos ~]# firewall-cmd --reload
防火墙详细配置可以参考:Linux下Centos7对外开放端口
安装apache
[root@VM_0_4_centos ~]# yum list install httpd
[root@VM_0_4_centos ~]# yum -y install httpd
[root@VM_0_4_centos ~]# httpd -v
[root@VM_0_4_centos ~]# systemctl enable httpd
//httpd-devel版本就不安装了,还不需要用到去编译httpd或开发额外模块的程度
添加CentOS 7 Nginx yum资源库
默认yum源里的Nginx版本到1.12.2,也可以直接安装,不过配置文件都放/etc/nginx/nginx.conf里面配置
[root@VM_0_4_centos ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@VM_0_4_centos ~]# yum -y install nginx
nginx配置,设置8080端口来访问nginx服务器
[root@VM_0_4_centos ~]# vim /etc/nginx/conf.d/default.conf //将 listen 80;修改为 listen 8080;
[root@VM_0_4_centos ~]# systemctl enable nginx
[root@VM_0_4_centos ~]# systemctl restart nginx
nginx 的配置见文章
LNMP 下 Nginx 和 php-fpm 的配置、
Centos 7 nginx 配置
云服务器端口的开放
云服务器上开放指定端口开放8080端口后,一直无法访问。防火墙排查,web服务器排查都没有问题,试了下用内网访问8080端口的地址,可以正常访问。确认应该是云服务器上做的限制,找到安全组配置了8080端口,马上可以访问。
放通3306端口
放通3306端口
安装mysql
[root@VM_0_4_centos ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm //下载mysql5.7的rpm文件
[root@VM_0_4_centos ~]# yum localinstall mysql57-community-release-el7-8.noarch.rpm //安装rmp文件
[root@VM_0_4_centos ~]# yum install mysql-community-server //安装MySQL数据库 约190M左右
[root@VM_0_4_centos ~]# systemctl start mysqld //启动数据库
[root@VM_0_4_centos ~]# grep 'temporary password' /var/log/mysqld.log //查看MySQL数据的原始密码文件
2018-06-26T03:09:32.292434Z 1 [Note] A temporary password is generated for root@localhost: xkHC:7-*axp1
[root@VM_0_4_centos ~]# mysql -u root -p //进入数据库系统
mysql> set password for 'root'@'localhost'=password('Aa@123456'); //重新为数据库设置密码
//将MySQL设置为开机启动项
[root@VM_0_4_centos ~]# systemctl enable mysqld
[root@VM_0_4_centos ~]# systemctl daemon-reload
//设置数据的默认字符集(非必须的)
[root@VM_0_4_centos ~]# vim /etc/my.cnf
//将下面两行配置代码加入到my.cnf最后面
character_set_server=utf8
init_connect='SET NAMES utf8'
//开启mysql远程登录权限
mysql> use mysql;
mysql> grant all privileges on *.* to 'root'@'%' identified by "Aa@123456";
mysql> flush privileges;
[root@VM_0_4_centos ~]# systemctl restart mysqld //重启MySQL
安装ssl
证书,使用https
协议
https://cloud.tencent.com/document/product/400/4143
参考摘录的网站有:
http://www.cnblogs.com/jimboi/p/8437788.html
https://blog.csdn.net/zhezhebie/article/details/73325663
https://www.jianshu.com/p/ed2d1820bd3e
https://www.cnblogs.com/weifeng1463/p/7941625.html
https://www.jianshu.com/p/8c9a0fabed68