CentOS 搭建php环境

安装MySQL

一、系统环境

#yum update升级以后的系统版本为

[root@localhost etc]# cat ./redhat-release
CentOS Linux release 7.4.1708 (Core) 

二、mysql安装

执行以下命令即可完成安装

#yum install mysql-server  //MySQL服务端
#yum install mysql-devel   //MySQL客户端

如果#yum install mysql-server执行失败,则须做以下操作

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server

安装成功后重启mysql服务

# service mysqld restart

操作mysql,初次安装无密码

无密码:[root@yl-web yl]# mysql -u root  

有密码:[root@yl-web yl]# mysql -u root -p

查看数据库

mysql> show databases;

设置密码

mysql> set password for 'root'@'localhost' =password('password');

三、配置mysql

扫描二维码关注公众号,回复: 545975 查看本文章

1.mysql的配置文件为/etc/my.cnf

添加字符编码

[mysql]
default-character-set =utf8

2.远程连接设置

把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。

mysql> grant all privileges on *.* to root@'%'identified by 'password';

如果是新用户而不是root,则要先新建用户

mysql>create user 'username'@'%' identified by 'password';  

此时就可以进行远程连接了。


安装 apache 和 php

  • 安装httpd以配置Web服务器, HTTP使用80 / TCP
[1] 安装 httpd.
[root@linuxprobe ~]# yum -y install httpd
# 删除默认欢迎页面
[root@linuxprobe ~]# rm -f /etc/httpd/conf.d/welcome.conf
[2] 配置httpd,将服务器名称替换为您自己的环境
[root@linuxprobe ~]# vi /etc/httpd/conf/httpd.conf
# line 86: 改变管理员的邮箱地址
ServerAdmin root@linuxprobe.org
# line 95: 改变域名信息
ServerName www.linuxprobe.org:80
# line 151: none变成All
AllowOverride All
# line 164: 添加只能使用目录名称访问的文件名
DirectoryIndex index.html index.cgi index.php
# add follows to the end
# server's response header(安全性)
ServerTokens Prod
# keepalive is ON
KeepAlive On
[root@linuxprobe ~]# systemctl start httpd
[root@linuxprobe ~]# systemctl enable httpd
[3] 如果Firewalld正在运行,请允许HTTP服务。,HTTP使用80 / TCP
[root@linuxprobe ~]# firewall-cmd --add-service=http --permanent
success
[root@linuxprobe ~]# firewall-cmd --reload
success
[4] 创建一个HTML测试页,并使用Web浏览器从客户端PC访问它。如果显示以下页面,是正确的
[root@linuxprobe ~]# vi /var/www/html/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Welcome access LinuxProbe.org,This is Test Page!
</div>
</body>
</html>
  • 配置httpd以使用PHP脚本
[1] 安装PHP.
[root@linuxprobe ~]# yum -y install php php-mbstring php-pear
[root@linuxprobe ~]# vi /etc/php.ini
# line 878: 取消注释,设置时区
date.timezone = "Asia/Shanghai"
[root@linuxprobe ~]# systemctl restart httpd

[2] 创建一个PHP测试页面,并使用Web浏览器从客户端PC访问它。如果显示以下页面,它是确定。
[root@linuxprobe ~]# vi /var/www/html/index.php
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
<?php
   print Date("Y/m/d");
?>
</div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_39251267/article/details/80029401