centos7.2快速搭建LAMP平台

本文详细介绍如何在CentOS系统上安装配置LAMP(Linux、Apache、MySQL、PHP)环境,包括各组件的安装步骤、配置方法及基本的安全设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#查看linux系统版本信息

cat /etc/redhat-release 

 

以上是操作系统的所有信息,补充下内核信息参数介绍:

3.10.0-514.26.2.el7.x86_64  

3表示主版本号,有结构性变化才更改;10表示次版本号,新增功能才变化,一般奇数表示测试版,偶数表示开发板

0表示对版本的修订次数或者补丁包数;514代表编译的次数,每次编译可对少数程序优化或修改;el7用来表示版本的特殊信息,有较大的随意性;

x86_64表示64位.

 

#安装apache

 

yum install httpd http-devel

 

#启动apache服务

 

systemctl start httpd

 

#设置httpd服务器开机自启

 

[root@VM_0_8_centos local]# systemctl enable  httpd

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

[root@VM_0_8_centos local]# 

 

#查看服务状态

 

systemctl status httpd  加-l会有详细信息

 

[root@VM_0_8_centos local]# systemctl status httpd -l

httpd.service - The Apache HTTP Server

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

   Active: active (running) since 二 2018-10-30 11:40:10 CST; 1h 23min ago

     Docs: man:httpd(8)

           man:apachectl(8)

 Main PID: 22527 (httpd)

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

   CGroup: /system.slice/httpd.service

           ├─22527 /usr/sbin/httpd -DFOREGROUND

           ├─22528 /usr/sbin/httpd -DFOREGROUND

           ├─22529 /usr/sbin/httpd -DFOREGROUND

           ├─22530 /usr/sbin/httpd -DFOREGROUND

           ├─22531 /usr/sbin/httpd -DFOREGROUND

           ├─22532 /usr/sbin/httpd -DFOREGROUND

           └─25691 /usr/sbin/httpd -DFOREGROUND

 

10月 30 11:40:10 VM_0_8_centos systemd[1]: Starting The Apache HTTP Server...

10月 30 11:40:10 VM_0_8_centos httpd[22527]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

10月 30 11:40:10 VM_0_8_centos systemd[1]: Started The Apache HTTP Server.

[root@VM_0_8_centos local]# 

 

#开启防火墙

 

systemctl restart firewalld

 

当然,没有的话需要安装一下

 

yum install firewall

 

[root@VM_0_8_centos local]# firewall-cmd --permanent --zone=public  --add-service=http

success

 

[root@VM_0_8_centos local]# firewall-cmd --permanent --zone=public  --add-service=https

success

 

设置开机启动

 

systemctl enable firewalld

 

关闭防火墙

 

systemctl stop firewalld

 

取消开启启动

 

systemctl disable firewalld

 

查看状态

 

firewall-cmd --state

 

还有别的请查看帮助

 

firewall-cmd --help

最后所有的就绪后重新加载下

 

[root@VM_0_8_centos local]# firewall-cmd --reload

success

 

#确认80端口监听中

 

netstat -tulp

 

netstat -pan|grep 8080  查看8080端口被哪个进程所占用

 

netstat -aux|grep 2222 看到该端口被2222这个id的进程占用后,可以继续查看到底是什么程序占用的

 

后面的工作你懂得?

 

#查看服务器ip

 

[root@VM_0_8_centos local]# 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

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    link/ether 52:54:00:fd:c3:24 brd ff:ff:ff:ff:ff:ff

    inet 172.21.0.8/20 brd 172.21.15.255 scope global eth0

       valid_lft forever preferred_lft forever

[root@VM_0_8_centos local]# 

 

#安装mysql (mariaDB)

 

yum install mariadb mariadb-server mariadb-libs mariadb-devel

 

查看安装包

 

[root@VM_0_8_centos local]# rpm -qa |grep maria

mariadb-server-5.5.60-1.el7_5.x86_64

mariadb-libs-5.5.60-1.el7_5.x86_64

mariadb-5.5.60-1.el7_5.x86_64

mariadb-devel-5.5.60-1.el7_5.x86_64

 

#开启mysql服务,设置开机自启,查看状态

 

[root@VM_0_8_centos local]# systemctl start mariadb

 

[root@VM_0_8_centos local]# systemctl enable mariadb

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

 

[root@VM_0_8_centos local]# systemctl status mariadb

mariadb.service - MariaDB database server

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

   Active: active (running) since 二 2018-10-30 14:10:39 CST; 32s ago

 Main PID: 30630 (mysqld_safe)

   CGroup: /system.slice/mariadb.service

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

           └─30792 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysq...

 

10月 30 14:10:37 VM_0_8_centos mariadb-prepare-db-dir[30551]: MySQL manual f...

10月 30 14:10:37 VM_0_8_centos mariadb-prepare-db-dir[30551]: Please report ...

10月 30 14:10:37 VM_0_8_centos mariadb-prepare-db-dir[30551]: The latest inf...

10月 30 14:10:37 VM_0_8_centos mariadb-prepare-db-dir[30551]: You can find a...

10月 30 14:10:37 VM_0_8_centos mariadb-prepare-db-dir[30551]: http://dev.mys...

10月 30 14:10:37 VM_0_8_centos mariadb-prepare-db-dir[30551]: Consider joini...

10月 30 14:10:37 VM_0_8_centos mariadb-prepare-db-dir[30551]: https://mariad...

10月 30 14:10:37 VM_0_8_centos mysqld_safe[30630]: 181030 14:10:37 mysqld_sa...

10月 30 14:10:37 VM_0_8_centos mysqld_safe[30630]: 181030 14:10:37 mysqld_sa...

10月 30 14:10:39 VM_0_8_centos systemd[1]: Started MariaDB database server.

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

[root@VM_0_8_centos local]# 

 

#数据库安全设置

 

[root@VM_0_8_centos local]# 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] no

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

[root@VM_0_8_centos local]# 

 

#登录mysql试试

 

[root@VM_0_8_centos local]# mysql -uroot -pgao512

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

Your MariaDB connection id is 9

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)]> show databases;

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

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

3 rows in set (0.00 sec)

 

MariaDB [(none)]> 

 

#安装php

 

目前php最高稳定版本是7.2,

若直接采用centos中的yum安装:sudo yum -y install php,版本是5.4,远远不够,因此我们要手动更新rpm即可.

首先我们先获取rpm

  1. rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  2. rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum -y install php72w

但安装完毕后,输入php -v发现并没有该命令,因为php72w只是安装了php最小的库,一些应用还未安装,因此安装一些拓展包即可:

yum -y install php72w-cli php72w-common php72w-devel php72w-mysql

 [root@VM_0_8_centos local]# rpm -qa|grep php

php72w-pdo-7.2.11-1.w7.x86_64

mod_php72w-7.2.11-1.w7.x86_64

php72w-cli-7.2.11-1.w7.x86_64

php72w-mysql-7.2.11-1.w7.x86_64

php72w-common-7.2.11-1.w7.x86_64

php72w-devel-7.2.11-1.w7.x86_64

[root@VM_0_8_centos local]# 

 

sudo yum -y install php72w-gd php72w-imap php72w-ldap php72w-odbc php72w-pear php72w-xml php72w-xmlrpc

 

将php与mysql关联起来

 

yum -y install php-mysql(安装这里报错,清除yum缓存就好了,yum clean all)

 

查看 

rpm -sql php-mysql

 

 

#最后测试

 

重启apache     systemctl restart httpd

 

然后再/var/www/html 下php文件进行测试吧

 

 

OK!Thanks!

 

 

 

 

 



 

转载于:https://www.cnblogs.com/gaosf/p/gaosf520.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值