虚拟机安装支持php的apache,虚拟机下安装Centos7并配置Apache+PHP+Mysql+phpmyadmin+wordpress...

一、安装Apache

yum install httpd

安装成功后,Apache操作命令:

systemctl start httpd //启动apache

systemctl stop httpd //停止apache

systemctl restart httpd //重启apache

systemctl enable httpd //设置apache开机启动

访问服务器Apache可能需要如下操作:

(1)在防火墙中开放80端口

需要将 http 服务加入防火墙以允许外部访问,

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

–permanent 参数表示这是一条永久防火墙规则,如果不加则重启系统后就没有这条规则了。

而对于自定义的端口(如81),也需要添加防火墙规则,

firewall-cmd --zone=public --add-port=81/tcp --permanent

重启 Firewalld 使该规则生效,

systemctl restart firewalld

二、 安装MariaDB (MySQL的一个开源分支)

yum install mariadb mariadb-server

MariaDB安装成功后,需要配置MySQL的root密码,此外,备注一下启动关闭MariaDB的常用命令

systemctl start mariadb //启动MariaDB

systemctl stop mariadb //停止MariaDB

systemctl restart mariadb //重启MariaDB

systemctl enable mariadb //设置开机启动

设置root账户密码

mysql_secure_installation

Enter current password for root (enter for none):

Set root password? [Y/n]

点击回车然后提示是否设置root账号密码,输入y

New password:

Re-enter new password:

Password updated successfully!

提示输入新密码和重复输入新密码,重复输入两次后,出现更新密码成功提示。

然后一路输入y就可以。

Remove anonymous users? [Y/n] y

... Success!

Disallow root login remotely? [Y/n] y

... Success!

Remove test database and access to it? [Y/n] y

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reload privilege tables now? [Y/n] y

... Success!

Thanks for using MariaDB!

设置root密码后,重启MariaDB生效

systemctl restart mariadb.service

测试访问数据库:

mysql -uroot -p

输入如下命令,查看数据库服务器的数据库

show databases;

退出命令:

exit;

三、安装PHP以及PHP拓展

yum install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

安装完成后,重启Apache服务器

systemctl restart httpd.service

测试PHP安装结果

vi /var/www/html/index.php

输入如下内容

phpinfo();?>

输入

:wq!

保存退出

在浏览器中输入服务器地址,查看是否成功安装

四、安装phpmyadmin

先安装Remi源,

yum install epel-release

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

再使用yum安装phpmyadmin

yum install phpmyadmin php-mcrypt

phpMyAdmin 的默认安装目录是 /usr/share/phpMyAdmin,同时会在 Apache 的配置文件目录中自动创建虚拟主机配置文件 /etc/httpd/conf.d/phpMyAdmin.conf(区分大小写)。默认情况下,CentOS 7上的phpMyAdmin只允许从回环地址(127.0.0.1)访问。为了能远程连接,你需要改动它的配置。

vi /etc/httpd/conf.d/phpMyAdmin.conf

修改配置文件,如下:

AddDefaultCharset UTF-8# Apache 2.4# Require ip 127.0.0.1 #注释掉

# Require ip ::1 #注释掉

Require all granted #新添加

# Apache 2.2

Order Deny,Allow

Deny from All

Allow from 127.0.0.1

Allow from ::1

# Apache 2.4#Require ip 127.0.0.1 #注释掉

#Require ip ::1 #注释掉

Require all granted #新添加

# Apache 2.2

Order Deny,Allow

Deny from All

Allow from 127.0.0.1

Allow from ::1

然后重启Apache服务器

systemctl restart httpd

然后就可以通过浏览器访问http://服务器ip地址/phpmyadmin访问

四、安装wordpress

安装wget:

yum install wget

下载wordpress

wget http://cn.wordpress.org/wordpress-4.9.1-zh_CN.zip

安装:unzip

yum install unzip

使用 unzip 来解压文件:

unzip wordpress-4.9.1-zh_CN.zip

在 Mysql 中新建数据库

mysql -u root -p

通过上面的命令进入数据库,然后输入密码:password

然后创建一个叫 wordpress 的数据库

create database wordpress;

cd 进入wordpress 目录

修改wordpress配置文件wp-config.php

(

p.s.1:默认这个文件没有,需重命名wp-config-sample.php

mv wp-config-sample.php wp-config.php

)

根据服务器信息修改以下几处内容

/** MySQL数据库名:wordpress */

define(‘DB_NAME‘, ‘wordpress‘);

/** MySQL数据库用户名 :root*/

define(‘DB_USER‘, ‘root‘);

/** MySQL数据库密码 :password*/

define(‘DB_PASSWORD‘, ‘password‘);

/** MySQL主机(不用修改) */

define(‘DB_HOST‘, ‘localhost‘);

修改完成后,

把文件复制到 /var/www/html 目录下

cp -rf wordpress/* /var/www/html/

然后输入服务器地址访问wordpress进行安装

p.s.2:安装完wordpress,后台管理插件时,需要输入FTP问题

解决方法:

chown -R apache:apache /var/www/html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值