0%

Linux学习(二)

lamp环境搭建
使用的是centos7系统

安装Apache&Nginx

升级一下yum源(非必须)

1
yum update

Apache安装与配置

Apache下载安装

1
yum list |grep httpd    //查看有哪些Apache可以安装
2
yum install -y httpd    //安装Apache指令
3
http -v               //安装完成后查看Apache版本指令
4
显示内容如下
5
Server version: Apache/2.4.6 (CentOS)
6
Server built:   Apr 12 2017 21:03:28

关闭防火墙

1
[root@localhost /]# systemctl systemctl stop firewalld   //关闭防火墙
2
[root@localhost /]# systemctl systemctl status firewalld //查看防火墙状态
3
[root@localhost /]# systemctl systemctl restart httpd    //重启Apache

如果不想关闭防火墙,那我们可以在防火墙上允许访问80端口(这是Apache默认的端口)

防火墙上开启80端口

1
[root@localhost /]# firewall-cmd --permanent --zone=public --add-port=80/tcp //开启80端口并且永久生效
2
success
3
[root@localhost /]# firewall-cmd --reload  //重新载入防火墙配置
4
success
5
[root@localhost /]# systemctl status firewalld
6
● firewalld.service - firewalld - dynamic firewall daemon
7
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
8
 Active: active (running) since Sun 2017-06-11 13:08:10 CST; 8s ago  //防火墙的状体是开启的

Ngixn安装与配置

Ngixn安装

1
[root@localhost /]# yum search nginx  //搜索没有nginx这个安装包 很遗憾的是没有
2
[root@localhost /]# yum install nginx  //尝试安装
3
Loaded plugins: fastestmirror
4
Loading mirror speeds from cached hostfile
5
 * base: mirrors.tuna.tsinghua.edu.cn
6
 * extras: mirrors.tuna.tsinghua.edu.cn
7
 * updates: mirrors.tuna.tsinghua.edu.cn
8
No package nginx available.   //还是没有nginx的安装包
9
//将nginx放到yum repro库中
10
[root@localhost /]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
11
[root@localhost /]# yum search nginx  //再次搜索nginx安装包
12
======================================================== N/S matched: nginx =========================================================
13
nginx-debug.x86_64 : debug version of nginx
14
nginx-debuginfo.x86_64 : Debug information for package nginx
15
nginx-module-geoip.x86_64 : nginx GeoIP dynamic modules
16
nginx-module-geoip-debuginfo.x86_64 : Debug information for package nginx-module-geoip
17
nginx-module-image-filter.x86_64 : nginx image filter dynamic module
18
nginx-module-image-filter-debuginfo.x86_64 : Debug information for package nginx-module-image-filter
19
nginx-module-njs.x86_64 : nginx nginScript dynamic modules
20
nginx-module-njs-debuginfo.x86_64 : Debug information for package nginx-module-njs
21
nginx-module-perl.x86_64 : nginx Perl dynamic module
22
nginx-module-perl-debuginfo.x86_64 : Debug information for package nginx-module-perl
23
nginx-module-xslt.x86_64 : nginx xslt dynamic module
24
nginx-module-xslt-debuginfo.x86_64 : Debug information for package nginx-module-xslt
25
nginx-nr-agent.noarch : New Relic agent for NGINX and NGINX Plus
26
nginx-release-centos.noarch : nginx repo configuration and pgp public keys
27
pcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metrics for the Nginx Webserver
28
nginx.x86_64 : High performance web server   //是存在nginx安装包的
29
[root@localhost /]# yum install nginx   //安装nginx
30
[root@localhost /]# nginx -v     //查看nginx版本
31
nginx version: nginx/1.12.0
32
[root@localhost /]# systemctl restart nginx     // 重启nginx

我希望通过80端口访问的是Apach服务器,通过8080端口访问的是nginx服务器,这么做?

1
[root@localhost /]# firewall-cmd --permanent --zone=public --add-port=8080/tcp   
2
success
3
[root@localhost /]# firewall-cmd --reload
4
success
5
[root@localhost /]# firewall-cmd --zone=public --list-ports  //查看所有打开的端口
6
80/tcp 8080/tcp    //80,8080已经打开
7
[root@localhost /]# cd /etc/nginx/conf.d
8
[root@localhost conf.d]# vim default.conf  //将其中的listen 80;修改为 listen 8080;
9
[root@localhost conf.d]# systemctl restart nginx  //重启nginx

MySql安装与配置

Mysql安装

CetOS7已使用了MariaDB替代了默认的MySQL ,所以我们想使用MySQL还得多做点事情

1
[root@localhost /]# yum install wget      //安装wget
2
[root@localhost /]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm    //下载mysql5.7的rpm文件
3
[root@localhost /]# yum localinstall mysql57-community-release-el7-8.noarch.rpm    //安装rmp文件
4
[root@localhost /]#yum install mysql-community-server  //安装MySQL数据库 约190M左右
5
[root@localhost /]# systemctl start mysqld   //启动数据库
6
[root@localhost /]# grep 'temporary password' /var/log/mysqld.log  //查看MySQL数据的原始密码文件 
7
2017-06-11T06:18:16.057811Z 1 [Note] A temporary password is generated for root@localhost: uvrpXRuul6/h    
8
[root@localhost /]# mysql -u root -p     //进入数据库系统
9
mysql> set password for 'root'@'localhost'=password('Aa@123456'); //重新为数据库设置密码
10
Query OK, 0 rows affected, 1 warning (0.01 sec)
11
//将MySQL设置为开机启动项
12
[root@localhost /]# systemctl enable mysqld
13
[root@localhost /]# systemctl daemon-reload
14
//设置数据的默认字符集(非必须的)
15
[root@localhost ~]# vim /etc/my.cnf
16
//将下面两行配置代码加入到my.cnf最后面
17
character_set_server=utf8
18
init_connect='SET NAMES utf8'
19
[root@localhost ~]# systemctl restart mysqld  //重启MySQL
20
//进入MySQL数据库
21
mysql> select version();    
22
+-----------+
23
| version() |
24
+-----------+
25
| 5.7.18    |
26
+-----------+
27
1 row in set (0.00 sec)
28
mysql> show variables like '%character%';
29
+--------------------------+----------------------------+
30
| Variable_name            | Value                      |
31
+--------------------------+----------------------------+
32
| character_set_client     | utf8                       |
33
| character_set_connection | utf8                       |
34
| character_set_database   | utf8                       |
35
| character_set_filesystem | binary                     |
36
| character_set_results    | utf8                       |
37
| character_set_server     | utf8                       |
38
| character_set_system     | utf8                       |
39
| character_sets_dir       | /usr/share/mysql/charsets/ |
40
+--------------------------+----------------------------+
41
8 rows in set (0.01 sec)

Mysql修改默认密码

如果想使用简单密码则需要修改mysql密码验证机制

1
[root@localhost /]# grep 'temporary password' /var/log/mysqld.log //默认密码存放位置
2
[root@localhost /]# mysql -u root -p  //使用获取密码登录
3
mysql> set global validate_password_policy=0;       //只验证长度
4
5
mysql> set global validate_password_length=6;      //修改密码长度,默认值是8个字符
6
7
mysql> alter user user()identified by"123456";     //修改登陆密码为123456

安装PHP7

1
//安装依赖文件
2
[root@localhost ~]# yum install 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
3
//安装php组新版本rpm
4
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
5
Retrieving https://mirror.webtatic.com/yum/el7/epel-release.rpm
6
warning: /var/tmp/rpm-tmp.F1aZTS: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
7
Preparing...                          ################################# [100%]
8
Updating / installing...
9
   1:epel-release-7-5                 ################################# [100%]
10
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
11
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
12
warning: /var/tmp/rpm-tmp.rnxYY3: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
13
Preparing...                          ################################# [100%]
14
Updating / installing...
15
   1:webtatic-release-7-3             ################################# [100%]
16
[root@localhost ~]# yum search php71   //查看有哪些php最新版的安装包文件
17
[root@localhost ~]# yum install mod_php71w php71w-mysqlnd php71w-cli php71w-fpm   //安装php7最新版
18
[root@localhost ~]# php -v    //查看php版本
19
PHP 7.1.5 (cli) (built: May 12 2017 21:54:58) ( NTS )
20
Copyright (c) 1997-2017 The PHP Group
21
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
22
[root@localhost ~]# systemctl restart httpd    //重启Apache
-------------本文结束Valent 感谢您的阅读-------------