Blogger Information
Blog 39
fans 0
comment 2
visits 47220
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Centos7PHP环境搭建
Tlilam的PHP之路
Original
3333 people have browsed it

Apache安装

yum install httpd


Apache操作命令:

systemctl start httpd.service #启动
systemctl stop httpd.service #停止
systemctl restart httpd.service #重启


第二、设置开机启动/关闭
systemctl enable httpd.service #开机启动
systemctl disable httpd.service #开机不启动


第三、检查httpd状态
systemctl status httpd.service


关闭防火墙
关闭:systemctl stop firewalld.service
查看状态:systemctl status firewalld.service

 

PHP安装
yum -y install php

php各项服务安装:
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-mysql


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

systemctl restart httpd.service

测试PHP安装结果

vi /var/www/html/index.php

输入如下内容

<?php
 phpinfo();?>

输入:wq! 保存退出
在浏览器中输入服务器地址,查看是否可以看到:phpinfo信息


安装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

然后输入密码,登录成功后显示如下:

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

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

show databases;

退出命令:

exit;

四、安装phpmyadmin

使用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

修改配置文件,如下:

<Directory /usr/share/phpMyAdmin/>
  AddDefaultCharset UTF-8   <IfModule mod_authz_core.c>
    # Apache 2.4     <RequireAny>
     # Require ip 127.0.0.1  #注释掉
     # Require ip ::1   #注释掉
     Require all granted   #新添加     </RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
    # Apache 2.2
    Order Deny,Allow
    Deny from All
    Allow from 127.0.0.1
    Allow from ::1   </IfModule></Directory><Directory /usr/share/phpMyAdmin/setup/>
  <IfModule mod_authz_core.c>
    # Apache 2.4     <RequireAny>
     #Require ip 127.0.0.1  #注释掉
     #Require ip ::1   #注释掉
     Require all granted   #新添加     </RequireAny>
  </IfModule>
  <IfModule !mod_authz_core.c>
    # Apache 2.2
    Order Deny,Allow
    Deny from All
    Allow from 127.0.0.1
    Allow from ::1   </IfModule></Directory>

然后重启Apache服务器

systemctl restart httpd.service #重启

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



异常处理
我再阿里云上配置并出现启动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

(2)关闭SELINUX

vi /etc/selinux/config

注释掉如下两句,添加最后一项

\#SELINUX=enforcing #注释掉

\#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq! 保存退出

输入如下命令

setenforce 0 #使配置立即生效

原文查看链接:

https://www.jianshu.com/p/bc14ff0ab1c7

https://www.cnblogs.com/chaochao00o/p/6842753.html



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post