Centos7.2(1151)使用Yum搭建LAMP+phpMyAdmin

前端之家收集整理的这篇文章主要介绍了Centos7.2(1151)使用Yum搭建LAMP+phpMyAdmin前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、实验环境

操作系统 IP地址 相关软件包
Centos7.2_x64 10.0.0.10 http、PHP、mariadb
Windows10_enterprise 10.0.0.2 Google浏览器


二、服务搭建


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/

a5501464cb60b38ada08d8582d7c9714.jpg

#注:出现如上内容证明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.安装PHPMysqL连接组件

[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

dd3cb17878122fbf11c12b7f5b5803bf.jpg



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

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

1f314e9ba37cd518235fcf3ccc147a3b.jpg


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

ffa9531e870a13e870f8f72762e3b00e.jpg



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

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

原文链接:https://www.f2er.com/centos/375363.html

猜你在找的CentOS相关文章