Centos7下lamp环境搭建的小笔记

刚刚把校赛弄完,赛前在环境搭建上花了蛮多时间,也正好记一下笔记

0.首先更新源

清华大学开源镜像站的源

https://mirrors.tuna.tsinghua.edu.cn/help/centos/

首先备份 CentOS-Base.repo

sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

将源内容写入

/etc/yum.repos.d/CentOS-Base.repo

更新软件包缓存

sudo yum makecache

yum -y update

成了

---

1.安装apache服务

安装apache

yum install httpd httpd-devel

启动apache服务

systemctl start httpd

设置开机启动

systemctl enable httpd

Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

查看服务状态

systemctl status httpd

防火墙开启服务端口

firewall-cmd --permanent --zone=public --add-service=http

firewall-cmd --permanent --zone=public --add-service=https

firewall-cmd --reload

确认服务

netstat -tulp

访问localhost或者127.0.0.1或者ip返回成功说明服务安装成功

---

2.安装mysql

安装mysql

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

rpm -qa |grep maria
mariadb-libs-5.5.52-1.el7.i686
mariadb-5.5.52-1.el7.i686
mariadb-server-5.5.52-1.el7.i686
mariadb-devel-5.5.52-1.el7.i686

开启服务 设置开机启动 检查状态

systemctl start mariadb

systemctl enable mariadb

systemctl status mariadb

确认服务

netstat -tulp

数据库安全配置

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...

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!

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!

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] n
 ... skipping.

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] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

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!

登录

mysql -uroot -p


2.1数据库用户的权限配置

如果未安装phpmyadmin这类软件

在搭建环境中需要通过sql语句来完成不同用户的权限配置

查看用户

select user from mysql.user;

创建用户

创建用户名为test密码为test的用户

create user‘test‘@‘localhost‘identified by‘test‘;

可以利用password(‘passwd‘)来对密码进行加密

create user ‘test‘@‘localhost‘identified by password‘被加密后的值‘;

删除用户

删除用户需要带有明确的用户名以及主机名

drop user [email protected];

修改账号

rename user‘test‘@‘localhost‘to‘test1‘@‘localhost‘;

修改密码

新密码必须传递到password()中进行加密,或者是已经加密过的密码值(此时要加上引号)。

将用户test的密码从原本的‘test‘修改成明文‘test‘对应的散列值

set password for ‘test‘@‘localhost‘=password(‘test‘);

用户权限管理

查看权限

show grants for ‘test‘@‘localhost‘;

权限赋予

grant select(cust_id,cust_name)
    on mysql_test.customers
    to‘test‘@‘localhost‘;

授予在数据库mysql_test的表customers上拥有对列cust_id和列cust_name的select权限

grant select ,update
    on mysql_test.customers
    to ‘test22‘@‘localhost‘identified by‘123‘; 

新建一个用户为test22,并授予其在数据库mysql_test的表customers上拥有select和update的权限

grant all
    on mysql_test.*
    to‘test‘@‘localhost‘;

授予可以在数据库mysql_test中执行所有操作的权限

grant create user
    on *.*
    to‘test‘@‘localhost‘;
    

授予系统中已存在用户test拥有创建用户的权限

权限的转移与限制

授予当前系统中一个不存在的用户admin在数据库mysql_test的表customers上拥有select 和update 的权限,并允许其将自身的这个权限授予其他用户(通过with grant option):

grant select,update
    on mysql_test.customers
    to‘admin‘@‘localhost‘identified by‘admin‘
    with grant option;

如果上面with子句后面跟的是max_queries_per_hour count、

max_updates_per_hour count、

max_connections_per_hour count、

max_user_connections count

中的某一项,则该grant语句可用于限制权限

grant delete
    on mysql_test.customers
    to ‘admin6‘@‘localhost‘
    with max_queries_per_hour 1;--每小时只能处理一条delete语句的权限 

权限的撤销

使用revoke可以实现权限的撤销,而不会删除用户

revoke select
    on mysql_test.customers
    from‘test‘@‘localhost‘;--回收用户test在数据库mysql_test的表customers上的select权限

---

安装php

安装php

yum -y install php

执行rpm -ql php
/etc/httpd/conf.d/php.conf
/etc/httpd/conf.modules.d/10-php.conf
/usr/lib/httpd/modules/libphp5.so
/usr/share/httpd/icons/php.gif
/var/lib/php/session

关联mysql和php

yum install php-mysql

查看

rpm -ql php-mysql
/etc/php.d/mysql.ini
/etc/php.d/mysqli.ini
/etc/php.d/pdo_mysql.ini
/usr/lib/php/modules/mysql.so
/usr/lib/php/modules/mysqli.so
/usr/lib/php/modules/pdo_mysql.so

安装php扩展

yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath

重启apache服务器

systemctl restart http

随便写个phpinfo然后去看看就知道成功与否

这就基本ok了

---

之前准备环境时的参考文章

原文地址:https://www.cnblogs.com/slpawn/p/9003970.html

时间: 2024-08-01 12:16:22

Centos7下lamp环境搭建的小笔记的相关文章

centos7下 LAMP环境搭建--mysql安装

安装MySQL MySQL的几个常用安装包:rpm.源码.二进制免编译 cd /usr/local/src wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql cd

转载自php100中文网 centos下lamp 环境搭建

学习PHP脚本编程语言之前,必须先搭建并熟悉开发环境,开发环境有很多种,例如LAMP.WAMP.MAMP等.这里我介绍一下LAMP环境的搭建,即Linux.Apache.MySQL.PHP环境. 一.首先安装操作系统 操作系统:centos6.3 IP地址:192.168.146.129 网关: DNS: 操作系统安装步骤,此处不在给出截图. 备注:服务器系统采用最小化安装,安装一下GCC编译工具和一个桌面即可.如下图所示: <a href="http://www.php100.com/u

ubuntu12.04下lamp环境搭建步骤

1 .安装apache2:sudo apt-get install apache2 安装完成后,运行如下命令重启apache:sudo /etc/init.d/apache2 restart,在浏览器中输入http://localhost或者http://127.0.0.1,会看到"It works!"说明apache安装成功. 2.安装php: sudo apt-get install libapache2-mod-php5 php5; 安装扩展php5-gd:sudo apt-ge

基于centOs7下appium环境搭建

事件背景: 前几日在群里看到关总说他的server端是搭建在linux环境下,包括对客户端与服务端的交互处理,感觉整体思路清晰可鉴,于是就想尝试,动手实践,接着从环境搭建开始搞起,于是就有了这篇文章,不得不吐槽下,这是段很深刻的回忆呀,历时1.5工作日,终于搞定环境搭建!! 依赖关联: ps:以我现在的为例,个别根据自己情况调整 JDK 1.8 Android SDK 1.0.40 nodejs 8.7 appium 1.9.1 一.安装jdk: 参考我之前写过的<ubuntu12.04 安装配

linux下lamp环境搭建(apache安装,mysql安装,php安装)

1.卸载系统内置的LAMP环境 1)卸载httpd服务(内置Apache) ① 使用rpm指令查询安装的httpd服务 ② 卸载httpd服务 如果出现以上提示,代表系统默认不允许我们卸载软件,使用强制卸载 - - nodeps 依次卸载其他软件 2)卸载mysql服务 3)卸载php服务 2.LAMP环境安装注意事项 ① 必须把Linux系统中的内置AMP卸载干净 ② 注意软件的安装顺序 第一步:首先安装Apache环境 第二步:安装MySQL环境 第三步:安装PHP环境 3.Apache软件

Centos7下LNMMP环境搭建

实验环境: Centos7_64 实验目的:在Centos7下实现源码安装nginx+mariadb+memcache+php均为最新版本 --2015.10.10 一.解决依赖关系yum install -y openssl-devel pcre-devel cmake 二.安装nginx groupadd -r nginx useradd -r -g nginx nginx tar -zxvf nginx-1.9.5.tar.gz cd nginx-1.9.5 ./configure --p

linux下LAMP环境搭建尝试

最近,学习搭建了LAMP服务环境,中间遇到了很多问题,经过不断摸索总算得以解决.为了大家少走弯路,现将相关经验进行总结. linux下软件安装分为自动安装和手动安装两种,自动安装借助工具如yum等,自动安装的文件往往分散在各个目录,为了便于管理,这里选择手动安装     1.安装apache     1.1 将apache解压到/usr/local/services目录 tar zxvf httpd-2.0.63.tar.gz      1.2 进入httpd-2.0.63目录,生成makefi

Linux下LAMP环境搭建

LAMP(Linux- Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据 库,Perl.PHP或者Python编程语言,所有组成产品均是开源软件,是 国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和 Java/J2EE架构相比,LAMP具有Web资源丰富.轻量.快速开发等特点,微软的.NET架构相比,LAMP具有通用.跨平台.高性能.低价格的 优势, 因此LAMP无论是性能.质量还是价格都是企

Mac 下LAMP环境搭建

在本地搭建LAMP Apache Mac OS自带Apache,所以只需要修改一些配置即可,配置文件为/etc/apache2/httpd.conf 修改根目录 DocumentRoot 添加 AddType Application/ x-httpd-php .php 用以支持php 支持后缀,端口等 php Mac自带php,起配置文件在/private/etc/php.ini,可以根据自身需要,修改配置文件等 mysql mysql需要自己下载安装,可以去其官网下载 安装之后默认root帐号