Home  >  Article  >  Backend Development  >  Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

王林
王林forward
2019-08-23 14:48:023853browse

Many times for convenience, when using wamp or wnmp environment, just build it directly on the windows system, and it is more convenient to directly use the integrated environment phpstudy, which is straightforward. For beginners, you can do this like this, but for some students who have been exploring PHP for a long time, it is actually not challenging. What's more, if you don't learn Linux, it will be easier to forget. Speaking of lamp or lnmp, some students said that I can just use one-click installation. Indeed, it is indeed very convenient now. There is a one-click installation package,

Address: https://lnmp.org/ , just follow the installation steps on this website.

But I still want to experience installing LAMP or LNMP on CentOS7.0, and I have been exploring it recently. According to personal preferences, you can also learn if you need it.

Installation of CentOS7

1) Create a virtual machine through VMware (this step is not explained)

After the system is successfully booted, the following interface will appear

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Interface description:

Install CentOS 7 Install CentOS 7

Test this media & install CentOS 7 Test the installation file and install CentOS 7
Troubleshooting Repairing faults

Select the first item here, install CentOS 7, press Enter, and enter the following interface

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Select language: Chinese-Simplified Chinese (China) #Formal production servers are recommended to install the English version

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Continue

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Select-System-Installation Location, Enter the disk partition interface

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Select-Other storage options-Partition-I want to configure the partition, click "Finish" in the upper left corner, and enter the following interface

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Plan before partitioning
swap #Swap partition, generally set to 2 times the memory
/ #All remaining space
Note: It is recommended that the production server be divided into a separate / The data partition stores data

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Click the " " sign in the lower left corner

Mount point: swap

Expected capacity: 2048

Add a mount point, as shown in the figure below

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Click "Finish" in the upper left corner to enter the following interface

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Accept the changes and enter the following interface

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Start the installation#Note that "Software"-"Software Selection", the default is minimal installation, that is, the desktop environment is not installed. You can set it yourself.

It is recommended to choose the minimum installation. After the minimum installation is completed, the computer will boot into the command line mode

Set the network

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Click, Open the network. Note that you must first set the virtual machine's network to bridge mode.

Enter the following interface

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Select-User Settings-ROOT Password and enter the following interface

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Set Root password

If the password length is less than 8 characters, you will be prompted to press "Finish" twice to confirm and the installation will continue

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Installation completed After that, you will enter the following interface

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Click restart

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

System restart

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Enter the login interface

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Enter root for account number and press Enter

Enter the root password set above and press Enter

System login successful

Remote login, here I use the Xsell tool

and enter the command ifconfig, and the following information comes out. The red box is the IP address you want to log in remotely

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Open Xsell tool, open a new connection, enter the host address

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Enter the user name

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environmentEnter the password

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

Remote login is now available.

Next, install Apache, php, mysql. I installed lamp here.

1), Install Apache

The software package name of Apache software is called httpd. Therefore, to install Apache software, use The following command:

[root@localhost ~]# yum install httpd

When prompted, press y all the way and press Enter.

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

As shown in the picture above, the installed Apache software version is version 2.4. According to Red Hat's official documentation, the Apache version available on RHEL 7 (or CentOS 7) is version 2.4.

After the installation is completed, Apache exists in the form of httpd service. Therefore, to start Apache and set it to start at boot, use the command:

[root@localhost ~]# systemctl start httpd.service[root@localhost ~]# systemctl enable httpd.service

Then, check the httpd service status:

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

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

as shown above display, "enabled" means that the httpd service has been set to start at boot, and "active (running)" means that the httpd service is running.

In this case, the HTTP protocol has been started. Since the HTTP protocol uses tcp port 80, the firewall needs to open tcp port 80:

[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent

Restart the firewall to make the changes take effect immediately :

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

Use the following command to check whether the configuration is successful:

[root@localhost ~]# firewall-cmd --list-all

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

As shown in the figure above, tcp port 80 has been opened.

然后这个时候,就可以在物理机上使用浏览器来访问刚刚搭建的web服务器了。不过,因为这个时候还未创建任何页面,所以它显示的是Apache软件自带的测试页面:

通过命令ip addr查询当前系统的ip地址,得到ip地址后再物理机浏览器地址栏输入该ip地址

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

2)安装PHP

使用以下命令安装PHP软件:

[root@localhost ~]# yum install php

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

从上图可以看到,安装的PHP版本为5.4版。这个是centOS7自带的版本,这里我把它升级到5.6版本,你们也可以升级为PHP7版本的。

进入终端后查看php版本

php -v

PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01) Copyright (c) 1997-2013 The PHP GroupZend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

执行下面的命令升级软件仓库

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpmrpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

执行下面的命令删除php

yum remove php-common

然后像安装那样问你是否继续的,输入yes即可

安装php 5.6版本(php56w-devel这个不是必需的)

yum install -y php56w php56w-opcache php56w-xml php56w-mcrypt php56w-gd php56w-devel php56w-mysql php56w-intl php56w-mbstring

重启httpd

service httpd restart

查看最新的版本

php -v

现在应该是5.6了!

安装mysql

新开的云服务器,需要检测系统是否自带安装mysql

# yum list installed | grep mysql

如果发现有系统自带mysql,果断这么干

# yum -y remove mysql-libs.x86_64

随便在你存放文件的目录下执行,这里解释一下,由于这个mysql的yum源服务器在国外,所以下载速度会比较慢,还好mysql5.6只有79M大,而mysql5.7就有182M了,所以这是我不想安装mysql5.7的原因

# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

接着执行这句,解释一下,这个rpm还不是mysql的安装文件,只是两个yum源文件,执行后,在/etc/yum.repos.d/ 这个目录下多出mysql-community-source.repo和mysql-community.repo

# rpm -ivh mysql-community-release-el6-5.noarch.rpm

这个时候,可以用yum repolist mysql这个命令查看一下是否已经有mysql可安装文件

#yum repolist all | grep mysql

安装mysql 服务器命令(一路yes):

# yum install mysql-community-server

安装成功后

# service mysqld start

由于mysql刚刚安装完的时候,mysql的root用户的密码默认是空的,所以我们需要及时用mysql的root用户登录(第一次回车键,不用输入密码),并修改密码

# mysql -u root# use mysql;# update user set password=PASSWORD("这里输入root用户密码") where User='root';# flush privileges;

查看mysql是否自启动,并且设置开启自启动命令

# chkconfig --list | grep mysqld# chkconfig mysqld on

mysql安全设置(系统会一路问你几个问题,看不懂复制之后翻译,基本上一路yes):

# mysql_secure_installation

以下是讲解授权远程登录,以Navicat工具为主

[root@MiWiFi-R1CL-srv ~]# mysql -u root -pEnter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)[root@MiWiFi-R1CL-srv ~]# mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.6.40 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

使用mysql数据库(真正的数据库,而非数据库软件),将所有数据库的所有表(.)的所有权限(all privileges),授予通过任何ip(%)访问的root用户,密码为123456,最后刷新(flush privileges)即可。

开放防火墙端口:

通过vim修改/etc/sysconfig/iptables,添加一行(这里是为了简单添加一行,更多防火墙知识请自行学习):

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

重启防火墙:

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

在windows下,我用 navicat测试:

Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment

远程连接成功。以上就是LAMP服务配置的详细信息。

更多相关资料请访问PHP中文网:linux视频教程

The above is the detailed content of Detailed explanation of installing CentOS 7 using a virtual machine and building a LAMP server environment. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jianshu.com. If there is any infringement, please contact admin@php.cn delete