Centos7 YUM方式安装LAMP


title: Centos7 YUM方式安装LAMP
categories: Linux
tags:
- LAMP
- httpd
- Apache
- PHP
- MySQL
- MariaDB
timezone: Asia/Shanghai
date: 2019-01-09

环境

[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core) 

[root@localhost ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built:   Jun 27 2018 13:48:59

[root@localhost ~]# mysql -V
mysql  Ver 15.1 Distrib 5.5.60-MariaDB, for Linux (x86_64) using readline 5.1

[root@localhost ~]# php -v
PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

phpMyAdmin
版本信息: 4.4.15.10

1.安装apache

安装apache
yum install httpd httpd-devel -y

启动apache服务
systemctl start httpd
systemctl enable httpd
systemctl status httpd

查看服务器IP并用浏览器登录页面
ip a
http://192.168.0.64

2.安装mysql

yum install mariadb mariadb-server mariadb-libs mariadb-devel -y

检查安装结果
rpm -qa |grep mariadb
	[root@localhost ~]# rpm -qa |grep mariadb
	mariadb-5.5.60-1.el7_5.x86_64
	mariadb-server-5.5.60-1.el7_5.x86_64
	mariadb-libs-5.5.60-1.el7_5.x86_64
	mariadb-devel-5.5.60-1.el7_5.x86_64

systemctl start mariadb
systemctl status mariadb
systemctl enable mariadb
使用 mysql_secure_installation 初始化数据库安全设置
  • 输入root密码,没有密码直接回车

      [root@localhost ~]# mysql_secure_installation
      
      NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
            SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
    
      In order to log into MariaDB to secure it, we'll need the current
      password for the root user.  If you've just installed MariaDB, and
      you haven't set the root password yet, the password will be blank,
      so you should just press enter here.
      
      Enter current password for root (enter for none): 
      OK, successfully used password, moving on...
    
  • 提示设置root user密码,Y

      Setting the root password ensures that nobody can log into the MariaDB
      root user without the proper authorisation.
      
      Set root password? [Y/n] y
      New password: 
      Re-enter new password: 
      Password updated successfully!
      Reloading privilege tables..
       ... Success!
    
  • 删除系统创建的默认匿名用户:Y

      By default, a MariaDB installation has an anonymous user, allowing anyone
      to log into MariaDB without having to have a user account created for
      them.  This is intended only for testing, and to make the installation
      go a bit smoother.  You should remove them before moving into a
      production environment.
      
      Remove anonymous users? [Y/n] y
       ... Success!
    
  • 禁止root用户远程登录:Y

      Normally, root should only be allowed to connect from 'localhost'.  This
      ensures that someone cannot guess at the root password from the network.
      
      Disallow root login remotely? [Y/n] y
       ... Success!
    
  • 是否删除系统创建的test数据库,生产环境建议删除

      By default, MariaDB comes with a database named 'test' that anyone can
      access.  This is also intended only for testing, and should be removed
      before moving into a production environment.
      
      Remove test database and access to it? [Y/n] n
       ... skipping.
    
  • 重载权限表:Y

      Reloading the privilege tables will ensure that all changes made so far
      will take effect immediately.
      
      Reload privilege tables now? [Y/n] y
       ... Success!
    
  • 完成

      Cleaning up...
      
      All done!  If you've completed all of the above steps, your MariaDB
      installation should now be secure.
      
      Thanks for using MariaDB!
    

3.Install PHP

yum install php php-mysql php-gd php-pear -y

测试PHP(需要重启httpd服务)
vi /var/www/html/info.php,并编辑以下内容

	

打开http://192.168.0.64/info.php可以看到php版本信息

4.Install phpMyAdmin(可选)

phpMyAdmin 是一个以PHP为基础,以Web-Base方式架构在网站主机上的MySQL的数据库管理工具,让管理者可用Web接口管理MySQL数据库。由于phpMyAdmin跟其他PHP程式一样在网页服务器上执行,您可以在任何地方使用这些程式产生的HTML页面,也就是于远端管理MySQL数据库,方便的建立、修改、删除数据库及资料表。也可借由phpMyAdmin建立常用的php语法,方便编写网页时所需要的sql语法正确性。

添加 EPEL repository   参照(Install EPEL Repository on RHEL/CentOS/Scientific Linux 7)
	yum install -y epel-release

安装 phpMyAdmin:
	yum install phpmyadmin -y

配置 phpMyAdmin
	phpMyAdmin默认只能由本机访问。为了能够远程访问,编辑phpmyadmin.conf file:
		vi /etc/httpd/conf.d/phpMyAdmin.conf

打开 phpMyAdmin
	http://192.168.0.61/phpMyAdmin

你可能感兴趣的:(随笔)