用yum快速搭建LAMP平台

用yum快速搭建LAMP平台

实验环境:

[root@nmserver-7 html]# cat  /etc/redhat-release 
CentOS release 7.3.1611 (AltArch) 
[root@nmserver-7 html]# uname -a
Linux nmserver-7.test.com 3.10.0-514.el7.centos.plus.i686 #1 SMP Wed Jan 25 12:55:04 UTC 2017 i686 i686 i386 GNU/Linux

1、安装apache

1.1 安装apache

[root@nmserver-7 ~]# yum install httpd httpd-devel

1.2 启动apache服务

[root@nmserver-7 ~]# systemctl start  httpd

1.3 设置httpd服务开机启动

[root@nmserver-7 ~]# systemctl enable  httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

1.4 查看服务状态

[root@nmserver-7 ~]# 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-07-21 17:21:37 CST; 6min ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 2449 (httpd)
   Status: "Total requests: 11; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─2449 /usr/sbin/httpd -DFOREGROUND
           ├─2450 /usr/sbin/httpd -DFOREGROUND
           ├─2451 /usr/sbin/httpd -DFOREGROUND
           ├─2452 /usr/sbin/httpd -DFOREGROUND
           ├─2453 /usr/sbin/httpd -DFOREGROUND
           ├─2454 /usr/sbin/httpd -DFOREGROUND
           ├─2493 /usr/sbin/httpd -DFOREGROUND
           ├─2494 /usr/sbin/httpd -DFOREGROUND
           └─2495 /usr/sbin/httpd -DFOREGROUND

7月 21 17:21:35 nmserver-7.test.com systemd[1]: Starting The Apache HTTP Server...
7月 21 17:21:36 nmserver-7.test.com httpd[2449]: AH00558: httpd: Could not reliably determine the server's fully q...ssage
7月 21 17:21:37 nmserver-7.test.com systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

1.5 防火墙设置开启80端口

[root@nmserver-7 ~]# firewall-cmd --permanent --zone=public  --add-service=http
success
[root@nmserver-7 ~]# firewall-cmd --permanent --zone=public  --add-service=https
success
[root@nmserver-7 ~]# firewall-cmd --reload
success

1.6确认80端口监听中

[root@nmserver-7 ~]# 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:ssh             0.0.0.0:*               LISTEN      1084/sshd           
tcp        0      0 localhost:smtp          0.0.0.0:*               LISTEN      1486/master         
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      1084/sshd           
tcp6       0      0 localhost:smtp          [::]:*                  LISTEN      1486/master         
tcp6       0      0 [::]:http               [::]:*                  LISTEN      2449/httpd          
udp        0      0 localhost:323           0.0.0.0:*                           592/chronyd         
udp6       0      0 localhost:323           [::]:*                              592/chronyd

1.8 查服务器IP

[root@nmserver-7 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:56:bc:cf brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.9/24 brd 192.168.8.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe56:bccf/64 scope link 
       valid_lft forever preferred_lft forever
3: bridge0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
    link/ether ea:89:d5:c7:32:73 brd ff:ff:ff:ff:ff:ff

1.9 浏览器登陆

image

2、安装mysql

2.1安装mysql

[root@nmserver-7 ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel
root@nmserver-7 ~]# rpm -qa |grep maria
mariadb-libs-5.5.52-1.el7.i686
mariadb-5.5.52-1.el7.i686
mariadb-server-5.5.52-1.el7.i686
mariadb-devel-5.5.52-1.el7.i686

2.2 开启mysql服务,并设置开机启动,检查mysql状态

[root@nmserver-7 ~]# systemctl start  mariadb 
[root@nmserver-7 ~]# systemctl enable  mariadb 
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@nmserver-7 ~]# systemctl status  mariadb 
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2017-07-22 21:19:20 CST; 21s ago
 Main PID: 9603 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─9603 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─9760 /usr/libexec/mysqld --basedir=/usr --datadir=/v...

7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:16 nmserver-7.test.com mysqld_safe[9603]: 170722 21...
7月 22 21:19:16 nmserver-7.test.com mysqld_safe[9603]: 170722 21...
7月 22 21:19:20 nmserver-7.test.com systemd[1]: Started MariaDB ...
[root@nmserver-7 ~]# 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:ssh             0.0.0.0:*               LISTEN      1084/sshd           
tcp        0      0 0.0.0.0:mysql           0.0.0.0:*               LISTEN      9760/mysqld         
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      1084/sshd           
tcp6       0      0 [::]:http               [::]:*                  LISTEN      2449/httpd          
udp        0      0 localhost:323           0.0.0.0:*                           592/chronyd         
udp6       0      0 localhost:323           [::]:*                              592/chronyd

2.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!

2.4 登陆数据库测试

[root@nmserver-7 ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, 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 |
+--------------------+
rows in set (0.02 sec)

MariaDB [(none)]>

3、安装PHP

3.1 安装php

[root@nmserver-7 ~]# yum -y install php
[root@nmserver-7 ~]# rpm -ql php
/etc/httpd/conf.d/php.conf
/etc/httpd/conf.modules.d/10-php.conf
/usr/lib/httpd/modules/libphp5.so
/usr/share/httpd/icons/php.gif
/var/lib/php/session

3.2 将php与mysql关联起来

[root@nmserver-7 ~]# yum install php-mysql
[root@nmserver-7 ~]# rpm -ql php-mysql
/etc/php.d/mysql.ini
/etc/php.d/mysqli.ini
/etc/php.d/pdo_mysql.ini
/usr/lib/php/modules/mysql.so
/usr/lib/php/modules/mysqli.so
/usr/lib/php/modules/pdo_mysql.so

3.3 安装常用PHP模块

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

3.4 测试PHP

[root@nmserver-7 ~]# cd  /var/www/html/
[root@nmserver-7 html]# ls
[root@nmserver-7 html]# pwd
/var/www/html
[root@nmserver-7 html]# vi info.php

<?php
        phpinfo();
?>
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                            
:wq

3.5重启apache服务器

[root@nmserver-7 html]# systemctl restart http

3.6测试PHP

在自己电脑浏览器输入 192.168.8.9/info.php,你可以看到已经安装的模块;

image
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,716评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,558评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,431评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,127评论 0 209
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,511评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,692评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,915评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,664评论 0 202
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,412评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,616评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,105评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,424评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,098评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,096评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,869评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,748评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,641评论 2 271

推荐阅读更多精彩内容

  • 1.LAMP介绍  LAM(M)P:L: linuxA: apache (httpd)M: mysql, mar...
    尛尛大尹阅读 1,022评论 0 1
  • 一、LAMP环境的介绍 1.LAMP环境的重要性 思索许久,最终还是决定写一篇详细的LAMP的源码编译安装的实验文...
    endmoon阅读 2,542评论 4 26
  • 一、MemCache简介 session MemCache是一个自由、源码开放、高性能、分布式的分布式内存对象缓存...
    李伟铭MIng阅读 3,651评论 2 13
  • 有人赞美柳树的婀娜多姿,有人赞美梅花的美丽与清香,而我却喜欢松树,喜欢它坚强、勇敢的性格。 春天,...
    梦的潇洒阅读 424评论 0 0
  • 过了大暑,炫目的阳光在巨大的梧桐树下投下斑斑驳驳的阴影,炙热的温度蒸发着汗水,蝉声、冰淇淋、西瓜一起构成了...
    mango大人阅读 167评论 0 0