设为首页 收藏本站
查看: 1648|回复: 0

CentOS7 yum搭建lamp

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-12-26 10:51:18 | 显示全部楼层 |阅读模式
简易搭建lamp



环境说明:
        server:CentOS7-192.168.230.202

        client: win8.1-192.168.230.59

        Apache/2.4.6

        php Version 5.4.16
        5.5.52-MariaDB

yum group install Development Tools
#安装开发工具,GCC...


yum install httpd mariadb mariadb-server php php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt -y

#安装apache mariadb php以及各种运行库和工具

service httpd start 启动


QQ截图20161226105124.png
在本地 curl是可以的,
在其他客户端是与80无法通信

i_f29.jpg 原因好简单嘛

selinux 和firewalld


setenforce 0

#关闭selinux
systemctl stop firewalld
#关闭防火墙嘛

在客户端本地hosts添加
192.168.230.202 www.rex.com

vi /etc/httpd/conf/httpd.conf #编辑
找到 #ServerName www.example.com:80
修改为 ServerName www.rex.com:80   
找到
#<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
添加index.php


现在可以在工作目录添加网页
路径为/var/www/html
1
2
3
4
5
[iyunv@localhost ~]# vim /var/www/html/index.php
[iyunv@localhost ~]# cat /var/www/html/index.php
<?php
        phpinfo();
?>




systemctl restart httpd
#reload会报错Empty reply from server,

wKioL1hblPXyieFjAACMprmdjRI288.jpg

刷新后就会显示php 的版本及详细内容。



mysql


网上许多教程都是使用mysql
由于版本的问题,还是使用有开源协议的mariadb,使用方法与mysql一样

上面的yum已经一次性安装了

cp /usr/share/mysql/my-huge.cnf /etc/my.cnf #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)
QQ截图20161226105132.png

两个文件还是有区别的

1
2
3
4
5
6
7
service mariadb start
##让我启动服务哈
Redirecting to /bin/systemctl start  mariadb.service
[iyunv@localhost ~]# mysqladmin -u root password
##修改mysql的root密码,当然可以用
New password: rexhaha
Confirm new password: rexhaha





在一遍帖子上看到的MySQL的简单配置,我们用到主要有加密,以及授权
1
2
3
mysqladmin -u root password
grant all privileges on *.* to 'root'@'192.168.230.%';
#%指的是shell的*字符,代表所有



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
用root账号进入MySQL管理后台,它会提示你输入密码:
[iyunv@localhost ~]# mysql -u root –p
创建本地用户:
mysql> create user '用户名'@'localhost' identified by '密码';
创建新数据库:
mysql> create database 数据库名;
将指定数据库的所有权限授给指定用户:
mysql> grant all privileges on 数据库名.* to '用户名'@'localhost';
刷新系统权限表:
mysql> flush privileges;
进入mysql数据库(系统自带),并查询是否存在指定用户(如果有出现一堆东西,则表明存在):
mysql> use mysql;
mysql> select * from user where user = '用户名';
如果要删除本地用户,使用:
mysql> drop user '用户名'@'localhost';
如果要删除数据库,使用:
mysql> drop database 数据库名;
查看存在的数据库:
mysql> show databases;
退出MySQL管理后台:
mysql> exit




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[iyunv@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create user 'rex'@'localhost' identified by 'rexhaha'
    -> ;
##上面那句结尾忘记加;号了,所以到一下行才加上   
Query OK, 0 rows affected (0.02 sec)
##执行成功的反馈
MariaDB [(none)]> create database rexhome;
##创建rexhome数据库
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on *.* to 'rex' @ 'localhost';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''localhost'' at line 1
##报错提示
MariaDB [(none)]> grant all privileges on rexhome.* to 'rex' @ 'localhost' ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''localhost'' at line 1
##加数据库名测试了一下还是报错
MariaDB [(none)]> grant all privileges on rexhome.* to 'rex'@'localhost' ;  
##原来是在‘user’@‘host’地方加了空格
Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> grant all privileges on *.* to 'rex'@'localhost' ;      
##授权给rex账号,所有数据及所有表的权限
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
更新权限表
Query OK, 0 rows affected (0.00 sec)



测试数据库是否已连接
vim /var/www/html/index.php
1
2
3
4
5
<?php
$link=mysql_connect("localhost","rex","rexhaha");
if(!$link) echo "FAILD!连接错误,用户名密码不对";
else echo "OK!可以连接";
?>



QQ截图20161226105140.png


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-319596-1-1.html 上篇帖子: 基于lamp+fastcgi+https搭建phpMyAdmin和wordpress 下篇帖子: XAMPP配置httpd-vhosts.conf后无法启动
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表