分享

CentOS7 的lamp的安装方法

 星光闪亮图书馆 2017-11-13

一、mariadb

下面的操作之前一定要记得先启动mariadb:

systemctl  start  mariadb

登录数据库:

$mysql -u root -p

初始密码为空。


注意,这里的root和linux的root没半毛钱关系.maria的初始密码默认是空的。需要你改一下的。

[root@ns ~]# mysqladmin -uroot -p password zhelitianmima  

Enter password: 

后面那个zhelitianmima是你要改的密码。Enter password那里直接回车就好了。

补充一点。mysql的密码都在mysql这个库里面,有一张表叫user,这里管理了可以登陆数据库的用户


介绍几个基本的命令

show databases;                  显示数据库
use mysql;                            进入数据库
show tables;                         显示示数据库中的表
desc user;                            查看user表的数据结构
flush privileges;                    刷新数据库信息
select host.user,password from user;     查询user表中的host,user,password字段

create database westos;                        创建westos数据库
use westos;                            
create table linux(                                   创建表,username,password字段
username varchar(15) not null,
password varchar(15) not null
);
select * from mysql.user;                           查询mysql库下的user表中的所以
alter table linux add age varchar(4);          添加age字段到linux表中
ALTER TABLE linux DROP age                删除age字段
ALTER TABLE linux ADD age  VARCHAR(5)  AFTER name        在name字段后添加字段age




为了安全,看看端口上有没有mysql的端口:

  1. [root@ns etc]# nmap localhost  
  2.   
  3. Starting Nmap 6.40 ( http:// ) at 2016-11-27 22:24 CST  
  4. Nmap scan report for localhost (127.0.0.1)  
  5. Host is up (0.000026s latency).  
  6. Other addresses for localhost (not scanned): 127.0.0.1  
  7. Not shown: 995 closed ports  
  8. PORT     STATE SERVICE  
  9. 21/tcp   open  ftp  
  10. 22/tcp   open  ssh  
  11. 25/tcp   open  smtp  
  12. 80/tcp   open  http  
  13. 3306/tcp open  mysql 

改了之后退出来杀掉所有跟mysql相关的进程。咋杀我就不说了阿。

那我要是不想别人远程登陆我的数据库怎么办呢

修改/etc/my.cnf  在第11行加上skip-networking=1,再重启mysql。

systemctl restart mariadb

  1. 1 [mysqld]  
  2.  2 datadir=/var/lib/mysql  
  3.  3 socket=/var/lib/mysql/mysql.sock  
  4.  4 # Disabling symbolic-links is recommended to prevent assorted security risks  
  5.  5 symbolic-links=0  
  6.  6 # Settings user and group are ignored when systemd is used.  
  7.  7 # If you need to run mysqld under a different user or group,  
  8.  8 # customize your systemd unit file for mariadb according to the  
  9.  9 # instructions in http:///wiki/Systemd  
  10. 10  
  11. 11 skip-networking=1  
  12. 12 [mysqld_safe]  
  13. 13 log-error=/var/log/mariadb/mariadb.log  
  14. 14 pid-file=/var/run/mariadb/mariadb.pid  
  15. 15 #  
  16. 16 # include all files from the config directory  
  17. 17 #  
  18. 18 !includedir /etc/my.cnf.d  
  19. 19   





二、关于数据库的sql语句就不在这里细说了。直接说如何直接以图形的方式管理数据库吧

1.现在网上下一个phpMyAdmin-3.4.0-all-languages.tar.bz2这个软件包

2.再在yum安装php php-mysql http 这3款软件

3.在/var/www/html下解压缩phpMyAdmin

4.在phpMyAdmin-3.4.0-all-languages这个目录中的config.sample.inc.php下找个

$cfg['blowfish_secret'] = '随便填个值’ 并将config.sample.inc.php    改名为config.inc.php

三、安装php的扩展
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

安装完扩展之后需要再次重启apache
以上命令可以激活PHP,因此phpmyadmin可用

四、关闭防火墙。

sudo systemctl stop firewalld.service



五、关闭selinux

查看SELinux状态:

(1)、/usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态

SELinux status:                 enabled

关闭SELinux:

(2)临时关闭(不用重启机器):

setenforce 0                  ##设置SELinux 成为permissive模式

                              ##setenforce 1 设置SELinux 成为enforcing模式

(3)、修改配置文件需要重启机器:

修改/etc/selinux/config 文件

将SELINUX=enforcing改为SELINUX=disabled

重启机器即可



六、APPache服务器的安装

yum install httpd

安装httpd会自动安装一下依赖包:这是要下载的依赖包

选择y及安装已下载好的安装包。安装大概需要30秒左右。

配置

进入配置界面vi httpd.conf(位置:/etc/httpd/conf/http.conf)

把里面的 AllowOverride None 全部修改为 AllowOverride All

顺便在 DirectoryIndex index.html 后面加上 index.htm index.php index.shtml

这个是配置默认首页的

:wq 保存退出 service httpd restart 重启 apache 服务,再访问一下。果然可以访问了。

重启服务器

  1. systemctl start httpd.service #启动apache

    systemctl stop httpd.service #停止apache

    systemctl restart httpd.service #重启apache

    systemctl enable httpd.service #设置apache开机启动

  2. 七、测试php是否安装成功

    #sudo vim /var/www/html/info.php

    里面写入代码

    <?php

    phpinfo();

    ?>

    然后保存退出

    :wq!

    在浏览器中输入http://your server's IP address/info.php

    就能看到自己的php信息了

  3. 八、在浏览器中输入:

  4. http://localhost/phpmyadmin/

  5. 可以管理数据库。



    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多