栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

lamp部署

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

lamp部署

环境说明:
系统平台IP需要安装的服务
Redhat8192.168.160.130

httpd-2.4

mysql

php

php-mysql

 lamp平台软件安装次序:

httpd——MySQL——php

1、配置环境yum源

在阿里云里找

 选择centos8的

再把云相关的干掉

 先配置yum源
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0  12053      0 --:--:-- --:--:-- --:--:-- 11995
[root@localhost yum.repos.d]# ls
CentOS-Base.repo
[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost yum.repos.d]# cd
[root@localhost ~]# yum clean all      //清理一下缓存
正在更新 Subscription Management 软件仓库。
无法读取客户身份

本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。

0 文件已删除
[root@localhost ~]# 
再配置一下epel源

 安装

 设置一下

 配置epel源
[root@localhost ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@localhost ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache     //重建缓存
[root@localhost ~]# yum -y install wget vim   //下载一下wget和vim命令
2、编译安装httpd

Index of /apache   在里面找源码包(apr和httpd文件夹里)

[root@localhost ~]# yum groups mark install 'Development Tools'   //标记安装一下

[root@localhost ~]# useradd -r -M -s /sbin/nologin apache   //-r系统用户,-M没有目录,-s不允许登录,创建用户的时候会自动创建跟用户名相同的组

[root@localhost ~]#  yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make    //安装依赖包

//下载源码包
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz

//解压
[root@localhost ~]# tar xf apr-1.7.0.tar.gz
[root@localhost ~]# tar xf apr-util-1.6.1.tar.gz
[root@localhost ~]# tar xf httpd-2.4.53.tar.gz


//编译apr-1.7.0
[root@localhost ~]# cd apr-1.7.0
[root@localhost apr-1.7.0]# vim configure
$RM "$cfgfile"   //把这个删掉
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make
[root@localhost apr-1.7.0]# make install 

//编译apr-util-1.6.1
[root@localhost ~]# cd apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make
[root@localhost apr-util-1.6.1]# make install 

//编译httpd-2.4.53
[root@localhost ~]# cd httpd-2.4.53
[root@localhost httpd-2.4.53]# ./configure --prefix=/usr/local/apache 
> --enable-so 
> --enable-ssl 
> --enable-cgi 
> --enable-rewrite 
> --with-zlib 
> --with-pcre 
> --with-apr=/usr/local/apr 
> --with-apr-util=/usr/local/apr-util/ 
> --enable-modules=most 
> --enable-mpms-shared=all 
> --with-mpm=prefork
[root@localhost apr-1.7.0]# make
[root@localhost apr-1.7.0]# make install 

//设置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@localhost ~]# source /etc/profile.d/apache.sh
[root@localhost ~]# which httpd
/usr/local/apache/bin/httpd

//映射
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/apache

//man文档
[root@localhost ~]# vim /etc/man_db.conf 
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man


//怎么来启动使用这个服务
//关闭防火墙
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce 
Permissive
[root@localhost ~]# vim /etc/selinux/config 
SELINUX=disabled   //把这个改为disabled
//启动服务
[root@localhost ~]# ss -antl
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process     
LISTEN     0          128                  0.0.0.0:111               0.0.0.0:*                   
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                   
LISTEN     0          5                  127.0.0.1:631               0.0.0.0:*                   
LISTEN     0          128                     [::]:111                  [::]:*                   
LISTEN     0          128                     [::]:22                   [::]:*                   
LISTEN     0          5                      [::1]:631                  [::]:*      

//如果想设置成systemctl来控制启动,并且设置开机自启
[root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# ls sshd.service 
sshd.service
[root@localhost system]# cp sshd.service httpd.service
cp:是否覆盖'httpd.service'? y
[root@localhost system]# vim httpd.service     //配置修改
 
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.target
 
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID
 
[Install]
WantedBy=multi-user.target
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# cd
[root@localhost ~]# systemctl status httpd    //查看一下这个服务,有了
[root@localhost ~]# systemctl start httpd    //现在可以用systemctl来控制启动了
[root@localhost ~]# systemctl enable httpd       //设置开机自启
3、MySQL安装

网站https://dev.mysql.com/(和阿里云的源都是8.0版本的)
 

 

 

 安装5.7版本  在这个网站里下载

 

 

 

 

//下载
[root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.37-1.el7.x86_64.rpm
[root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.37-1.el7.x86_64.rpm
[root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-devel-5.7.37-1.el7.x86_64.rpm
[root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.37-1.el7.x86_64.rpm
[root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-server-5.7.37-1.el7.x86_64.rpm
[root@localhost ~]# ls
公共  下载                  mysql-community-client-5.7.37-1.el7.x86_64.rpm
模板  音乐                  mysql-community-common-5.7.37-1.el7.x86_64.rpm
视频  桌面                  mysql-community-devel-5.7.37-1.el7.x86_64.rpm
图片  anaconda-ks.cfg       mysql-community-libs-5.7.37-1.el7.x86_64.rpm
文档  initial-setup-ks.cfg  mysql-community-server-5.7.37-1.el7.x86_64.rpm
[root@localhost ~]# yum -y install *.rpm    //因为里面只有mysql这些rpm包了,所以可以直接用这个方式安装

/设置开机自启
[root@localhost ~]# systemctl enable --now mysqld
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2022-04-18 16:51:51 CST; 38s ago
....
[root@localhost ~]# ss -antl     //查看3306启动了
State     Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process    
LISTEN    0          128                  0.0.0.0:111               0.0.0.0:*                  
LISTEN    0          32             192.168.122.1:53                0.0.0.0:*                  
LISTEN    0          128                  0.0.0.0:22                0.0.0.0:*                  
LISTEN    0          5                  127.0.0.1:631               0.0.0.0:*                  
LISTEN    0          80                         *:3306                    *:*                  
LISTEN    0          128                     [::]:111                  [::]:*                  
LISTEN    0          128                     [::]:22                   [::]:*                  
LISTEN    0          5                      [::1]:631                  [::]:*     
//查看临时密码 
[root@localhost ~]# grep 'password' /var/log/mysqld.log 
2022-04-18T08:51:49.120021Z 1 [Note] A temporary password is generated for root@localhost: :c?fe_rwQ25a
//使用获取到的临时密码登录
[root@localhost ~]# mysql -uroot -p':c?fe_rwQ25a'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.37
 
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
 
mysql>    //出现这个说明登录成功
//设置密码
mysql> set password = password('Ltt429520.');
Query OK, 0 rows affected, 1 warning (0.00 sec)
 
mysql> quit
Bye
[root@localhost ~]# 
 
//为避免mysql自动升级,把最开始安装的yum源卸载
[root@localhost ~]# rpm -e mysql57-community-release 
4、php安装  4.1准备工作
//安装依赖包
[root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel sqlite-devel libzip-devel


//下载php源码包
[root@localhost ~]# wget https://www.php.net/distributions/php-7.4.29.tar.xz

//解压
[root@localhost ~]# tar xf php-7.4.29.tar.xz
4.2编译php源码包
[root@localhost ~]# cd php-7.4.29/
./configure --prefix=/usr/local/php7  
--with-config-file-path=/etc 
--enable-fpm 
--enable-inline-optimization 
--disable-debug 
--disable-rpath 
--enable-shared 
--enable-soap 
--with-openssl 
--enable-bcmath 
--with-iconv 
--with-bz2 
--enable-calendar 
--with-curl 
--enable-exif  
--enable-ftp 
--enable-gd 
--with-jpeg 
--with-zlib-dir 
--with-freetype 
--with-gettext 
--enable-json 
--enable-mbstring 
--enable-pdo 
--with-mysqli=mysqlnd 
--with-pdo-mysql=mysqlnd 
--with-readline 
--enable-shmop 
--enable-simplexml 
--enable-sockets 
--with-zip 
--enable-mysqlnd-compression-support 
--with-pear 
--enable-pcntl 
--enable-posix

[root@localhost ~]# make
[root@localhost ~]# make install   //make编译
报错解决
1.报错
configure: error: Package requirements (oniguruma) were not met:
解决
[root@localhost php-7.4.29]# cd ..
[root@localhost ~]# wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz     //下载此包
[root@localhost ~]# tar -zxf oniguruma-6.9.4.tar.gz  //解压
[root@localhost ~]# cd oniguruma-6.9.4 
[root@localhost ~]# ./autogen.sh && ./configure --prefix=/usr  //设置存放位置  
[root@localhost ~]# make && make install  //make编译
或者
[root@localhost ~]#yum -y install https://repo.almalinux.org/almalinux/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

2.报错
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzi
解决
yun install -y libzip-devel
4.3配置php
//创建环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost ~]# source /etc/profile.d/php7.sh
[root@localhost ~]# which php
/usr/local/php7/bin/php

//配置php-fpm
[root@localhost ~]# cd php-7.4.29/
[root@localhost php-7.4.29]# ls
appveyor             configure.ac     Makefile.fragments      run-tests.php
azure                CONTRIBUTING.md  Makefile.objects        sapi
azure-pipelines.yml  docs             modules                 scripts
build                ext              NEWS                    tests
buildconf            EXTENSIONS       oniguruma-6.9.4         travis
buildconf.bat        include          oniguruma-6.9.4.tar.gz  TSRM
CODING_STANDARDS.md  libs             pear                    UPGRADING
config.log           libtool          php.ini-development     UPGRADING.INTERNALS
config.nice          LICENSE          php.ini-production      win32
config.status        main             README.md               Zend
configure            Makefile         README.REDIST.BINS
[root@localhost php-7.4.29]# cp php.ini-production /etc/php.ini
[root@localhost php-7.4.29]# ls sapi/fpm/
config.m4       init.d.php-fpm.in  php-fpm.8        php-fpm.service     tests
CREDITS         LICENSE            php-fpm.8.in     php-fpm.service.in  www.conf
fpm             Makefile.frag      php-fpm.conf     status.html         www.conf.in
init.d.php-fpm  php-fpm            php-fpm.conf.in  status.html.in
[root@localhost php-7.4.29]# cp sapi/fpm/php-fpm /etc/init.d/php-fpm
cp:是否覆盖'/etc/init.d/php-fpm'? y
[root@localhost php-7.4.29]# ll /etc/init.d/php-fpm
-rwxr-xr-x 1 root root 54696368 4月  21 23:13 /etc/init.d/php-fpm
[root@localhost php-7.4.29]# cd /usr/local/php7/
[root@localhost php7]# ls
bin  etc  include  lib  php  sbin  var
[root@localhost php7]# cd etc/
[root@localhost etc]# ls
pear.conf  php-fpm.conf.default  php-fpm.d
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# ls
www.conf.default
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# ls
www.conf  www.conf.default
[root@localhost php-fpm.d]# pwd
/usr/local/php7/etc/php-fpm.d
[root@localhost php-fpm.d]# vim www.conf

listen = 127.0.0.1:9000


//临时启动
[root@localhost ~]# /etc/init.d/php-fpm
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q        Local Address:Port         Peer Address:Port    Process    
LISTEN    0         128               127.0.0.1:9000              0.0.0.0:*                  
LISTEN    0         128                 0.0.0.0:111               0.0.0.0:*                  
LISTEN    0         32            192.168.122.1:53                0.0.0.0:*                  
LISTEN    0         128                 0.0.0.0:22                0.0.0.0:*                  
LISTEN    0         5                 127.0.0.1:631               0.0.0.0:*                  
LISTEN    0         80                        *:3306                    *:*                  
LISTEN    0         128                    [::]:111                  [::]:*                  
LISTEN    0         128                       *:80                      *:*                  
LISTEN    0         128                    [::]:22                   [::]:*                  
LISTEN    0         5                     [::1]:631                  [::]:*                  
[root@localhost ~]# pkill php-fpm
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q        Local Address:Port         Peer Address:Port    Process    
LISTEN    0         128                 0.0.0.0:111               0.0.0.0:*                  
LISTEN    0         32            192.168.122.1:53                0.0.0.0:*                  
LISTEN    0         128                 0.0.0.0:22                0.0.0.0:*                  
LISTEN    0         5                 127.0.0.1:631               0.0.0.0:*                  
LISTEN    0         80                        *:3306                    *:*                  
LISTEN    0         128                    [::]:111                  [::]:*                  
LISTEN    0         128                       *:80                      *:*                  
LISTEN    0         128                    [::]:22                   [::]:*                  
LISTEN    0         5                     [::1]:631                  [::]:*  


4.4配置apache
//启动代理模块
[root@localhost ~]# cd /usr/local/apache/conf/
[root@localhost conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@localhost conf]# vim httpd.conf 

#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so   //将#删掉,取消注释


//创建测试文件
[root@localhost conf]# cd ..
[root@localhost apache]# pwd
/usr/local/apache
[root@localhost apache]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
[root@localhost apache]# cd htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# mkdir test.com
[root@localhost htdocs]# cd test.com/
[root@localhost test.com]# ls
[root@localhost test.com]# vim index.php



//将署组更改
[root@localhost ~]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# ls
index.html  test.com
[root@localhost htdocs]# cd test.com/
[root@localhost test.com]# ls
index.php
[root@localhost test.com]# cat index.php

[root@localhost test.com]# ll
总用量 4
-rw-r--r-- 1 root root 22 4月  21 22:57 index.php
[root@localhost test.com]# chown -R apache.apache /usr/local/apache/
[root@localhost test.com]# ll
总用量 4
-rw-r--r-- 1 apache apache 22 4月  21 22:57 index.php


//配置虚拟主机
[root@localhost test.com]# cd ..
[root@localhost htdocs]# ls
index.html  test.com
[root@localhost htdocs]# cd ..
[root@localhost apache]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
[root@localhost apache]# vim conf/httpd.conf   //在最后一行


    DocumentRoot "/usr/local/apache/htdocs/test.com"   
    ServerName test.example.com  
    ProxyRequests Off
    ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test.com/$1  
      
        Options none
        AllowOverride none
        Require all granted
    



[root@localhost apache]# vim conf/httpd.conf
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps    //添加
[root@localhost ~]# systemctl restart httpd


验证

在真机的host文件添加ip对应的域名做映射

192.168.160.130为虚拟机ip

test.example.com为域名

 记事本内
//记事本里添加
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost
127.0.0.1         activate.navicat.com

192.168.160.130 test.example.com
192.168.160.130 web.example.com
服务重启
[root@localhost ~]# systemctl stop httpd
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q        Local Address:Port         Peer Address:Port    Process    
LISTEN    0         128               127.0.0.1:9000              0.0.0.0:*                  
LISTEN    0         128                 0.0.0.0:111               0.0.0.0:*                  
LISTEN    0         128                 0.0.0.0:22                0.0.0.0:*                  
LISTEN    0         5                 127.0.0.1:631               0.0.0.0:*                  
LISTEN    0         80                        *:3306                    *:*                  
LISTEN    0         128                    [::]:111                  [::]:*                  
LISTEN    0         128                       *:80                      *:*                  
LISTEN    0         128                    [::]:22                   [::]:*                  
LISTEN    0         5                     [::1]:631                  [::]:*          
浏览器

192.168.160.130访问

 test.example.com访问

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/826511.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号