首页 > 系统相关 >CentOS7服务器搭建LAMP环境

CentOS7服务器搭建LAMP环境

时间:2023-04-03 20:44:41浏览次数:49  
标签:httpd MariaDB root CentOS7 LAMP yum 服务器 php php72w


CentOS7.4上搭建LAMP环境,这里以centos7.4为例;

工具/原料

  • centos系统一台
  • 安全组放行80,22端口
  • 关闭防火墙和SELinux

安装Apache方法/步骤

使用的例子:服务器版本内核。

CentOS7服务器搭建LAMP环境_linux

2

Xshell连接到您的服务器上,使系统处于最新状态执行以下命令,

查看centos版本 lsb_release -a

更新centos系统

yum -y update 3

利用yum命令安装Apache执行命令,

查看Apache版本httpd -v

yum -y install httpd4

启动httpd并且设置为它开机启动,

systemctl start httpd 【启动httpd命令】

systemctl enable httpd 【设置httpd开机启动】

systemctl restart httpd (重启)5

我们这里可通过俩个命令查看是否启动和开机启动;

systemctl status httpd 【查看是否启动命令】

systemctl is-enabled httpd 【查看是否开机启动(输出enabled已经成功)】

注意:后续检查数据库的方法也是大同小异作不在详细解释。

安装成功后,在浏览器地址栏输入你的服务器IP地址出现下图说明你的httpd已经成功安装,例如我这里:39.104.82.85

CentOS7服务器搭建LAMP环境_centos_02

查看Apache版本httpd -v

  1. 安装数据库Mariadb它是MySQL的一个分支几乎兼容mysql所有功能,执行下面命令;

yum -y install mariadb-server mariadb

  1. 启动mariadb并且设置为它开机启动;检查是否启动和开机启动

systemctl start mariadb

systemctl enable mariadb

systemctl status mariadb

systemctl is-enabled mariadb

systemctl restart mariadb(重启)

  1. 下面配置root密码和数据库的一些安全;执行命令,

mysql_secure_installation

  1. #将会输出让输入原始密码(这里默认为空密码请直接回车Enter),

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):

按回车

这里询问我们是否设置root密码,输入y设置密码,y(设置); n(不设置)

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

root user without the proper authorisation.

Set root password? [Y/n]

输入密码再次确认密码回车

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 (询问是否移除匿名用户输入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(询问是否禁止远程root登陆我这里选择y禁止远程登录【如果您需要远程登录连接数据库可选择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(询问是否删除测试数据库【可选项随意y或n】这里我选择y)

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y (询问是否现在重新加载权限表选择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!

会自动跳到命令页面,到此我们的数据库设置了密码和一些安全。

  1. 我们可以简单登录下数据库;

mysql -uroot -p

Enter password: 【输入密码回车即可登录进去】

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

Your MariaDB connection id is 13

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 |

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

4 rows in set (0.01 sec)

MariaDB [(none)]> quit 【退出数据库】

Bye

安装php7.2

查看PHP版本 php -v

1> 、安装源

安装php72w,是需要配置额外的yum源地址的,否则会报错不能找到相关软件包。

php高版本的yum源地址,有两部分,其中一部分是epel-release,另外一部分来自webtatic。如果跳过epel-release的话,安装webtatic的时候,会有错误爆出。所以,这里需要的命令是:

yum install epel-release -y

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

2> 清除历史版本

为了防止centos上面发生php冲突,所以,这个命令还是先执行一下更好些。

yum -y remove php*

3、安装扩展包

事实上,这里面的对应扩展库很多,这里大家一定要注意cli和fpm这两个包,而其它的相关包就看您需要了。

yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-xmlrpc php72w-mysql php72w-imap php72w-ldap php72w-odbc php72w-pear php72w-mcrypt

4、安装完成以后,启动服务

systemctl enable php-fpm.service

systemctl start php-fpm.service

  1. 安装成功重启HTTPD

systemctl restart httpd

5> 查看php 版本

php -v //输入命令

13.安装PHP,执行命令;

yum -y install php(默认安装php5.4版本不建议13,14条)

14.查看所有组件,执行命令;(默认安装php5.4版本不建议13,14条)

yum search php

选择所需组件进行安装,执行命令;

yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

15.完成后我们可以新建一个PHP页面来查看我们安装的组件,执行命令;

vim /var/www/html/info.php

打开后按键盘字母 i

编辑为以下内容;

phpinfo();

?>

编辑完后按键盘 Esc 后shift + “: ” 在输入 : 最后 wq! 回车。

vim使用方法可自行百度,不作详细解释

  1. 最后重启的httpd服务,执行命令;

systemctl restart httpd

打开浏览器输入:39.104.82.85/info.php(即IP地址 / 和文件名)

看到这个页面证明您的LAMP环境搭建httpd发布目录默认在/var/www/html/

您可以使用winscp上传您的页面到发布目录

  1. ###最后执行命令 rm -rf /var/www/html/info.php 删除你的这种测试文件###

注意事项

  • 切记删除这些文件:rm -rf /var/www/html/info.php

第三 同IP同服务器下多网站部署

使用FTP:FileZilla软件

1. 1. 单网站,默认项目目录:/var /www/html

多网站,其他项目目录:/var /www/项目1

/var/www/项目2

1. 1. /etc/httpd/conf/httpd.conf*修改文件尾部添加:*

DocumentRoot /var/www/项目1

ServerName www.项目1.com


Options FollowSymLinks
AllowOverride All

DocumentRoot /var/www/项目2

ServerName www.项目2.cn


Options FollowSymLinks
AllowOverride All

<VirtualHost *:80>

    DocumentRoot /var/www/jqbs

    ServerName 9wuquan.cn

    ServerAlias *.9wuquan.cn

<Directory />

     Options FollowSymLinks

     AllowOverride All

</Directory>

</VirtualHost>

<VirtualHost *:443>

  DocumentRoot /var/www/jqbs

  ServerName 9wuquan.cn

  ServerAlias *.9wuquan.cn

  SSLEngine on

  SSLProtocol TLSv1 TLSv1.1 TLSv1.2

  SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5

<Directory />

      Options FollowSymLinks ExecCGI

      AllowOverride All

      Order allow,deny

      Allow from all

      Require all granted

</Directory>

SSLCertificateFile /etc/letsencrypt/live/9wuquan.cn/cert.pem

SSLCertificateKeyFile /etc/letsencrypt/live/9wuquan.cn/privkey.pem

Include /etc/letsencrypt/options-ssl-apache.conf

SSLCertificateChainFile /etc/letsencrypt/live/9wuquan.cn/chain.pem

</VirtualHost>

httpd.conf配置文件的修改主要有以下几项:

(2.安装apache的mod_ssl.so模块yum -y install mod_ssl)

LoadModule ssl_module modules/mod_ssl.so

LoadModule rewrite_module modules/mod_rewrite.so
  1. ServerSignature On => ServerSignature Off // 配置错误页不显示Apache版本
  2. Options Indexes FollowSymLinks => Options FollowSymLinks // 配置Apache不能通过目录层级进行文件访问
AllowOverride All
  1. AllowOverride None => AllowOverride All // 配置允许.htaccess
  2. DirectoryIndex index.html => DirectoryIndex index.html index.php // 配置Apache支持.php文件解析

最后,通过.htaccess进行301转向

<IfModule mod_rewrite.c>

  Options +FollowSymlinks -Multiviews

  RewriteEngine On



  RewriteCond   %{HTTPS} !=on

  RewriteRule   ^(.*)  https://%{SERVER_NAME}/$1 [L,R=302]

  RewriteCond %{REQUEST_FILENAME} !-d

  RewriteCond %{REQUEST_FILENAME} !-f

  RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]

</IfModule>

# 图片和Flash内容缓存一个月

<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf)$">

Header set Cache-Control "max-age=2592000"

</FilesMatch>

<FilesMatch ".(ttf)$">

Header set Access-Control-Allow-Origin "*"

</FilesMatch>

3, systemctl restart httpd

此时也是一级,二级域名都可以访问

第四 远程连接MySQL

1. 增加帐号。MySQL服务器root帐号被配置成了禁止远程登入,因此需要新增加一个MySQL帐号用于远程管理:

[root@centos-server ~]$ mysql --host localhost --user root --password mysql
mysql> CREATE USER 'owen'@'%' IDENTIFIED BY 'owen';

mysql> GRANT ALL PRIVILEGES ON *.* TO 'owen'@'%' WITH GRANT OPTION;

2.在阿里云上开启3306端口

CentOS7服务器搭建LAMP环境_数据库_03

CentOS7服务器搭建LAMP环境_数据库_04

CentOS7服务器搭建LAMP环境_java_05

3.使用数据库软件在本地使用owen账号远程连接mysql


标签:httpd,MariaDB,root,CentOS7,LAMP,yum,服务器,php,php72w
From: https://blog.51cto.com/owenzhang24/6167341

相关文章

  • php-websocket hyperf/websocket-server/client 客户端和服务器实时双向数据传输
    WebSocket服务WebSocket是一种通信协议,可在单个TCP连接上进行全双工通信。WebSocket使得客户端和服务器之间的数据交换变得更加简单,允许服务端主动向客户端推送数据。在WebSocketAPI中,浏览器和服务器只需要完成一次握手,两者之间就可以建立持久性的连接,并进行双向数据传输。Hyperf......
  • 多台服务器之间配置ssh免密登录
    需求:假设有N台服务器,N台服务器之间都需要配置相互间免密登录步骤1:在一台服务器上安装ansibleyum-yinstallepel-release&&  yum-yinstallansible步骤2:在这台服务器上生成密钥对ssh-keygen步骤3:生成authorized_keys文件,并修改为600权限cp id_rsa.pub authorized_k......
  • 服务器液冷冷板标准正式发布,浪潮信息牵头英特尔等二十家单位参编
    2023年2月28日,《服务器及存储用液冷部件技术规范第1部分:冷板》团体标准在中国电子工业标准化技术协会开放计算标准工作委员会(OCTC)正式发布。此标准由浪潮信息牵头,联合英特尔、中国电子技术标准化研究院等二十家相关单位参编完成。此次发布的冷板标准规范了服务器及存储设备用单相液......
  • 如何XShell 通过中转服务器直接连接目标服务器
    一、使用代理方式首先填写连接信息填写用户身份验证信息添加ssh隧道(注意此处的端口要是未用的端口)添加代理服务器(此处的端口与隧道端口一致)连接代理服务器这时就可以连接到目标服务器了,但是要注意的是,如果目标服务器有设置防火墙规则,对端口要加入出入栈规则才可以正常使用。......
  • CentOS7 安装git 配置秘钥公钥克隆代码
    第一步:安装git客户端,默认安装在/usr/libexec/git-core目录yum-yinstallgit#查看版本git--version第二步:配置git信息gitconfig--globaluser.name"username"gitconfig--globaluser.email"[email protected]"第三步:生成密钥和公钥,后续只需要按回车即可ssh-keygen-......
  • 为什么是至强Xeon处理器当做服务器CPU?他和普通台式CPU的区别
    为什么是至强Xeon处理器当做服务器CPU?他和普通台式CPU的区别相同的普通台式机CPU架构,Xeon处理器是高度受欢迎由于一些高级特性,比如更高的核心价值,支持更多的RAM,大的缓存内存和机器检查体系结构能够提供企业级的可靠性,可用性和可服务性特征负责处理硬件异常。现在,我们将回答......
  • git服务器搭建过程以及遇到的问题
    git自动化部署在Git服务器上为用户配置SSH公钥git@Linux:~$mkdir.sshgit@Linux:~$touch.ssh/authorized_keysgit@Linux:~$chmod600.ssh/authorized_keysgit@Linux:~$authorized_keys文件可以保存多个用户的SSH公钥,所有公钥被添加到这个文件中的用户,就都可......
  • 六位一体Serverless化应用,帮你摆脱服务器的烦恼
    随着互联网技术的飞速发展,越来越多的应用横空出世,是以不可避免带来了大量的服务器需求。大部分的开发者都选择购买或者租用服务器,然而这样也带来了诸多的烦恼。1.硬件成本高昂购买服务器费用昂贵,除了基础的购买费用外,服务器对机房也有苛刻的要求,温度、湿度、防震等等的高要求都需要......
  • CentOS7服务器2T及2T以下磁盘挂载
    CentOS7服务器2T及2T以下磁盘挂载目录CentOS7服务器2T及2T以下磁盘挂载0.环境信息1.详细挂载步骤1.1.查看当前系统磁盘使用情况1.2.查看是否有未知硬盘未挂载1.3.分区1.3.1.依次输入以下命令1.4.格式化分区1.5.挂载硬盘1.5.1.创建挂载目录——挂载点/挂载位置1.5.2.挂载硬......
  • CentOS7-启动|重启|停止|状态服务脚本
    源码编译安装方法1、上传包nginx-1.10.0.tar.gz至服务端#解压到工作目录[root@template~]#tarxfnginx-1.10.0.tar.gz-C/usr/local/src/#切换至Nginx目录下,找到configure[root@template~]#cd/usr/local/src/[root@templatesrc]#lltotal0drwxr-xr-x.81001......