Centos7部署LAMP+PHPmyadmin

版权声明:著作权归作者所有,转载请联系作者获得授权,并标注文章作者、出处及原文连接。 https://blog.csdn.net/qq_42512892/article/details/90051672

LAMP是指Web应用软件组合,一般是Linux+Apache+MySQL+PHP,从Centos7开始,系统默认MariaDB而不再是MySQL,具体原因就不再赘述,MariaDB是完全兼容MySQL的。这里我们就用MariaDB来代替MySQL。

一、系统设置修改

关闭防火墙

systemctl stop firewalld.service

禁止防火墙开机自启

systemctl disable firewalld.service

二、配置yum源

博主使用的是国内镜像站作为yum源,当然也可以使用centos系统镜像来配置本地yum源,这个是无关紧要的,根据个人实际情况来选择。与此同时,我们需要额外安装EPEL以便安装源以外的软件,如phpMyAdmin等工具。
安装EPEL源

yum -y install epel-release

备注:EPEL (Extra Packages for Enterprise Linux)是基于Fedora的一个项目,为“红帽系”的操作系统提供额外的软件包,适用于RHEL、CentOS和Scientific Linux.

三、安装配置Apache服务器

Apache的网站默认根目录是/var/www/html文件夹,之后的网页文件都将存放在这里。
安装Apache服务器

yum -y install httpd

启动Apache服务器

systemctl start httpd

查看Apache服务器运行状态

systemctl status httpd

允许Apache服务器开机自启

systemctl enable httpd

到此Apache的安装配置已经结束,如果Apache服务器正常运行,此时在浏览器地址栏输入http://服务器IP地址你将会访问到如下界面:
在这里插入图片描述

四、安装并配置MariaDB

安装MariaDB数据库

yum -y install mariadb mariadb-server

启动MariaDB数据库

systemctl start mariadb

查看MariaDB数据库运行状态

systemctl status mariadb

允许MariaDB数据库开机自启

systemctl enable mariadb

在完成安装后,需要对MariaDB进行配置

mysql_secure_installation

此时会返回如下一段文字,点击回车即可

[root@bogon yum.repos.d]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 

回车后会提示是否设置root账户的密码,输入y并回车,按照提示输入密码和重复输入密码即可完成密码设置

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

剩下的输入y回车即可,当然,也可以根据个人需求来选择y或者n,y就是yes,n就是no,每个选项的用处已在下面代码块中注释

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y		#删除匿名用户?
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y		#不允许远程root登录?
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y		#删除测试数据库并访问它?
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y		#现在重新加载权限表?
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

重启MariaDB数据库

systemctl restart mariadb.service

现在已经完成对MariaDB的安装和配置,接下来登录数据库

mysql -uroot -p

登录成功

[root@bogon yum.repos.d]# 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.60-MariaDB MariaDB Server

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

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

MariaDB [(none)]> 

输入一条SQL语句测试一下

MariaDB [(none)]> show databases;		#查看所有数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> 

退出MariaDB数据库

MariaDB [(none)]> quit;
Bye
MariaDB [(none)]> exit;
Bye

退出数据库使用quit和exit命令都可以。

五、安装PHP及其相关拓展

安装PHP及其相关拓展

yum -y 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

在Apache的网站根目录下写一个PHP测试页面,文件名暂且命名为index.php代码如下:

<?php
        phpinfo();
?>

在浏览器地址栏输入http://服务器IP地址,你会看到如下界面:
在这里插入图片描述
如果没有访问到该页面在浏览器地址栏输入http://服务器IP地址/index.php即可,该界面包含你的lamp环境的部分参数。至此lamp环境的配置部署已经完成。

六、安装并配置PHPmyadmin

安装PHPmyadmin及其相关拓展

yum -y install phpmyadmin php-mcrypt

PHPmyadmin默认安装路径是/usr/share/phpMyAdmin,安装时会在 Apache 的配置文件目录中自动创建虚拟主机配置文件phpMyAdmin.conf,该文件位于/etc/httpd/conf.d目录下。PHPmyadmin在Centos7下默认是只允许本地访问的,所以要对phpMyAdmin.conf配置文件进行相对应的修改。

# phpMyAdmin - Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

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

配置文件修改完成后保存配置文件,重启Apache服务器

systemctl restart httpd

至此PHPmyadmin就安装配置完成了,在浏览器地址栏输入http://服务器IP的地址/PHPmyadmin就可以登录PHPmyadmin。
在这里插入图片描述
至此在Centos7下的LAMP+PHPmyadmin环境搭建就完成了。

七、存在的问题以及疑难解答

由于是yum源安装,所以环境中的组件并不是最新的,因为yum源的更新并非实时更新,如果希望用到最新的组件,可以通过tar包的安装方式。例如我们这里的PHPmyadmin版本就有点老,我们可以去PHPmyadmin官网下载自己需要的版本对应的tar包进行编译安装。其他组件同理。

猜你喜欢

转载自blog.csdn.net/qq_42512892/article/details/90051672