一、实验环境

操作系统IP地址相关软件包
Centos7.2_x6410.0.0.10http、php、mariadb
Windows10_enterprise10.0.0.2Google浏览器


二、服务搭建


2.安装Apache


2.1.安装Apache

[root@localhost ~]# yum -y install httpd httpd-devel


2.2.启动Apache服务

[root@localhost ~]# systemctl start httpd


2.3.设置开机自启

[root@localhost ~]# systemctl enable httpd

Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.


2.4.查看服务状态

[root@localhost ~]# systemctl status httpd

● httpd.service - The Apache HTTP Server

   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)

   Active: active (running) since 三 2017-11-01 20:32:28 CST; 1h 20min ago

     Docs: man:httpd(8)

           man:apachectl(8)

 Main PID: 3909 (httpd)

   Status: "Total requests: 56; Current requests/sec: 0; Current traffic:   0 B/sec"

   CGroup: /system.slice/httpd.service

           ├─3909 /usr/sbin/httpd -DFOREGROUND

           ├─3911 /usr/sbin/httpd -DFOREGROUND

           ├─3912 /usr/sbin/httpd -DFOREGROUND

           ├─3913 /usr/sbin/httpd -DFOREGROUND

           ├─3914 /usr/sbin/httpd -DFOREGROUND

           ├─3915 /usr/sbin/httpd -DFOREGROUND

           ├─3928 /usr/sbin/httpd -DFOREGROUND

           ├─3932 /usr/sbin/httpd -DFOREGROUND

           ├─3933 /usr/sbin/httpd -DFOREGROUND

           ├─3934 /usr/sbin/httpd -DFOREGROUND

           └─3935 /usr/sbin/httpd -DFOREGROUND


11月 01 20:32:28 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...

11月 01 20:32:28 localhost.localdomain httpd[3909]: AH00558: httpd: Could not reliably determine the server's fully qualifie...ssage

11月 01 20:32:28 localhost.localdomain systemd[1]: Started The Apache HTTP Server.

Hint: Some lines were ellipsized, use -l to show in full.


2.5.防火墙允许80端口通过


[root@localhost ~]# firewall-cmd --permanent --zone=public  --add-service=http

success

[root@localhost ~]# firewall-cmd --permanent --zone=public  --add-service=https

success

[root@localhost ~]# firewall-cmd --reload

success


2.6.确定80端口监听中

[root@localhost ~]# netstat -tulp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    

tcp        0      0 0.0.0.0:mysql           0.0.0.0:*               LISTEN      2292/mysqld         

tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN      721/sshd            

tcp        0      0 localhost:smtp          0.0.0.0:*               LISTEN      1321/master         

tcp6       0      0 [::]:http               [::]:*                  LISTEN      3909/httpd          

tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      721/sshd            

tcp6       0      0 localhost:smtp          [::]:*                  LISTEN      1321/master


2.7.Windows10中打开浏览器访问:http://10.0.0.10/

Centos7.1(1151)使用Yum搭建LAMP+phpMyAdmin_php

#注:出现如上内容证明Apache服务已经可以正常访问了


三、安装Mariadb


3.1.安装mariadb

[root@localhost ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel -y


3.2.开启mysql服务,并设置卡机启动,检查mysql状态

[root@localhost ~]# systemctl start mariadb.service

[root@localhost ~]# systemctl enable mariadb.service

[root@localhost ~]# systemctl status mariadb.service

● mariadb.service - MariaDB database server

   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)

   Active: active (running) since 三 2017-11-01 19:32:49 CST; 3h 38min ago

 Main PID: 2130 (mysqld_safe)

   CGroup: /system.slice/mariadb.service

           ├─2130 /bin/sh /usr/bin/mysqld_safe --basedir=/usr

           └─2292 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/va...


11月 01 19:32:47 localhost.localdomain mariadb-prepare-db-dir[2051]: MySQL manual for more instructions.

11月 01 19:32:47 localhost.localdomain mariadb-prepare-db-dir[2051]: Please report any problems at http://mariadb.org/jira

11月 01 19:32:47 localhost.localdomain mariadb-prepare-db-dir[2051]: The latest information about MariaDB is available at htt...rg/.

11月 01 19:32:47 localhost.localdomain mariadb-prepare-db-dir[2051]: You can find additional information about the MySQL part at:

11月 01 19:32:47 localhost.localdomain mariadb-prepare-db-dir[2051]: http://dev.mysql.com

11月 01 19:32:47 localhost.localdomain mariadb-prepare-db-dir[2051]: Consider joining MariaDB's strong and vibrant community:

11月 01 19:32:47 localhost.localdomain mariadb-prepare-db-dir[2051]: https://mariadb.org/get-involved/

11月 01 19:32:47 localhost.localdomain mysqld_safe[2130]: 171101 19:32:47 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.

11月 01 19:32:47 localhost.localdomain mysqld_safe[2130]: 171101 19:32:47 mysqld_safe Starting mysqld daemon with databases ...mysql

11月 01 19:32:49 localhost.localdomain systemd[1]: Started MariaDB database server.

Hint: Some lines were ellipsized, use -l to show in full.


[root@localhost ~]# netstat -tulp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    

tcp        0      0 0.0.0.0:mysql           0.0.0.0:*               LISTEN      2292/mysqld         

tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN      721/sshd            

tcp        0      0 localhost:smtp          0.0.0.0:*               LISTEN      1321/master         

tcp6       0      0 [::]:http               [::]:*                  LISTEN      3909/httpd          

tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      721/sshd            

tcp6       0      0 localhost:smtp          [::]:*                  LISTEN      1321/master



3.3.初始化数据库

[root@nmserver-7 ~]# 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): 

OK, successfully used password, moving on...


Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.


Set root password? [Y/n] y

New password: 

Re-enter new password: 

Password updated successfully!

Reloading privilege tables..

 ... Success!



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

 ... skipping.


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!


3.4.登陆数据库测试

[root@localhost ~]# mysql -u root -p

Enter password: 

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 37

Server version: 5.5.56-MariaDB MariaDB Server


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


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


MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

+--------------------+

3 rows in set (0.00 sec)



四、安装PHP


4.1.安装php

[root@localhost ~]# yum -y install php 


4.2.安装php与mysql连接组件

[root@localhost ~]# yum install php-mysql


4.3.安装PHP常用模块

[root@localhost ~]# yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath


4.4.测试PHP

命令行中输入:

echo "<?php

phpinfo();

?>" > /var/www/html/test.php


#注:以上内容的意思是将双引号里面的内容打印到/var/www/html/test.php,这个test.php就是我们创建的PHP测试页,也可以使用vim创建该文件并添加内容。


4.5.重启Apahce服务

[root@localhost ~]# systemctl restart httpd.service


4.6.浏览器测试PHP

浏览器中输入:http://10.0.0.10/test.php

Centos7.1(1151)使用Yum搭建LAMP+phpMyAdmin_php_02



五、安装phpMyAdmin


5.1.安装epel源

[root@localhost ~]# yum install -y epel-release

[root@localhost ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm


5.2.安装phpmyadmin并编辑phpmyadmin.conf文件

[root@localhost ~]# yum install -y phpmyadmin


#复制phpmyadmin.conf文件

cp /etc/httpd/conf.d/phpMyAdmin.conf /etc/httpd/conf.d/phpMyAdmin.conf.bak


#编辑/etc/httpd/conf.d/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#注释掉

     Allow from All granted#新增

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

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


# These directories do not require access over HTTP - taken from the original

# phpMyAdmin upstream tarball

#

<Directory /usr/share/phpMyAdmin/libraries/>

    Order Deny,Allow

    Deny from All

    Allow from None

</Directory>


<Directory /usr/share/phpMyAdmin/setup/lib/>

    Order Deny,Allow

    Deny from All

    Allow from None

</Directory>


<Directory /usr/share/phpMyAdmin/setup/frames/>

    Order Deny,Allow

    Deny from All

    Allow from None

</Directory>


# This configuration prevents mod_security at phpMyAdmin directories from

# filtering SQL etc.  This may break your mod_security implementation.

#

#<IfModule mod_security.c>

#    <Directory /usr/share/phpMyAdmin/>

#        SecRuleInheritance Off

#    </Directory>

#</IfModule>



5.3.修改完phpmyadmin配置文件后重启Apache。

[root@localhost ~]# systemctl restart httpd


5.4.使用浏览器打开http://10.0.0.10/phpMyAdmin

#用户名密码就是数据库的用户名密码

Centos7.1(1151)使用Yum搭建LAMP+phpMyAdmin_myadmin_03


#输入用户名密码之后进入到首页就可以使用phpmyadmin管理数据库了。

Centos7.1(1151)使用Yum搭建LAMP+phpMyAdmin_php_04



参考文章:http://www.cnblogs.com/me80/p/7218883.html

#注:除去上方链接中的文章以外还参考了网上其他文章,由于浏览器开启了无痕模式找不到链接,没法标注在此,如有侵权请联系我删除。