Java教程

LAMP的部署

本文主要是介绍LAMP的部署,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

LAMP:L是linux(操作系统),A是apache(HTTP服务器),M是mysql(MariaDB,数据库软件),P是php(有时是perl或python,一门以P开头的语言)

除了LINUX外其他各部件本身是各自独立的程序,但是因为经常被放到一起使用,拥有了越来越高的兼容性,共同组成了一个强大的Web应用程序平台。

 LAMP的部署步骤:

1. 安装apache.

1.1 安装apache需要先安装:apr,apr-util,httpd.

       提前做好准备工作配置国内源,速度快,地址:mirrors.aliyun.com,下载wget,vim.

 1 [root@localhost ~]#  cd /etc/yum.repos.d/
 2 [root@localhost yum.repos.d]# ls
 3 CentOS-Stream-AppStream.repo  CentOS-Stream-Extras.repo            CentOS-Stream-NFV.repo         CentOS-Stream-ResilientStorage.repo
 4 CentOS-Stream-BaseOS.repo     CentOS-Stream-HighAvailability.repo  CentOS-Stream-PowerTools.repo  CentOS-Stream-Sources.repo
 5 CentOS-Stream-Debuginfo.repo  CentOS-Stream-Media.repo             CentOS-Stream-RealTime.repo
 6 [root@localhost yum.repos.d]# rm -rf * 把里面的源删掉配aliyun的源
 7 [root@localhost yum.repos.d]# ls     
 8  [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
 9                                   Dload  Upload   Total   Spent    Left  Speed
10  100  2495  100  2495    0     0   8754      0 --:--:-- --:--:-- --:--:--  8754
11 [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
12 [root@localhost yum.repos.d]# dnf clean all    清理缓存
13 21 文件已删除
14 [root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm   安装epel源
15 [root@localhost yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
16 [root@localhost yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*  配置
17 [root@localhost yum.repos.d]# dnf clean all  清理缓存
18 文件已删除
19 [root@localhost yum.repos.d]# dnf makecache  建立缓存
20 [root@localhost yum.repos.d]# dnf -y install wget vim     下载wget,vim

安装所依赖的包组

1 [root@localhost ~]# dnf -y  groupinstall 'Development Tools' --allowerasing --nobest   
2 [root@localhost ~]# useradd -r -M -s /sbin/nologin apache   创建一个不需要登陆没有家目录名字叫apache的系统用户
3 [root@localhost ~]# id apache
4 uid=994(apache) gid=991(apache) 组=991(apache)
5 [root@localhost ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++  make  安装依赖包

下载apr,apr-util,httpd解压。地址:apache.org

1 [root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz    下载
2 https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
3 [root@localhost ~]# ls
4 anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.53.tar.gz
5 [root@localhost ~]# tar xf apr-1.7.0.tar.gz    解压
6 [root@localhost ~]# tar xf apr-util-1.6.1.tar.gz 
7 [root@localhost ~]# tar xf httpd-2.4.53.tar.gz 

apr的编译安装

1 [root@localhost ~]# cd apr-1.7.0
2 [root@localhost apr-1.7.0]# vim configure   
3      $RM "$cfgfile"     找到这一行删除掉
4 [root@localhost apr-1.7.0]# ./configure  --prefix=/usr/local/apr配置
5 [root@localhost apr-1.7.0]# make -j 4   编译
6 [root@localhost apr-1.7.0]# make install   安装

apr- util的编译安装

1 [root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr     配置
2 [root@localhost apr-util-1.6.1]# make -j 4   编译
3 [root@localhost apr-util-1.6.1]# make install  安装

httpd的编译安装,设置环境变量,头文件,man文件等。

 1 [root@localhost httpd-2.4.53]# ./configure --prefix=/usr/local/apache \
 2 > --enable-so \
 3 > --enable-ssl \
 4 > --enable-cgi \
 5 > --enable-rewrite \
 6 > --with-zlib \
 7 > --with-pcre \
 8 > --with-apr=/usr/local/apr \
 9 > --with-apr-util=/usr/local/apr-util/ \
10 > --enable-modules=most \
11 > --enable-mpms-shared=all \
12 > --with-mpm=prefork
13 [root@localhost httpd-2.4.53]#make -j 4 编译
14 [root@localhost httpd-2.4.53]#make install 安装
15 [root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
16 [root@localhost ~]# source /etc/profile.d/httpd.sh
17 [root@localhost ~]# which httpd  读一下就可以看到了
18 /usr/local/apache/bin/httpd
19 [root@localhost ~]# ln -s /usr/local/apache/include /usr/include/apache   设置头文件
20 [root@localhost ~]# vim /etc/man_db.conf   设置man文档
21 MANDATORY_MANPATH                       /usr/local/apache/man
22 [root@localhost ~]# cd /usr/lib/systemd/system   设置开机自启
23 [root@localhost system]# cp sshd.service httpd.service
24 [root@localhost system]# vim httpd.service   
25 修改成这样
26 [Unit]
27 Description=httpd server daemon
28 After=network.target sshd-keygen.target
29 
30 [Service]
31 Type=forking
32 ExecStart=/usr/local/apache/bin/apachectl start
33 ExecStop=/usr/local/apache/bin/apachectl stop
34 ExecReload=/bin/kill -HUP $MAINPID
35 
36 [Install]
37 WantedBy=multi-user.target
38 [root@localhost system]# systemctl daemon-reload  重新加载一下
39 [root@localhost system]# systemctl status httpd
40 ● httpd.service - httpd server daemon
41    Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
42    Active: inactive (dead)
43 [root@localhost ~]# systemctl enable --now httpd   立马启动
44 Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.   
45 [root@localhost ~]# ss -antl
46 State             Recv-Q            Send-Q                       Local Address:Port                       Peer Address:Port            Process            
47 LISTEN            0                 128                                0.0.0.0:22                              0.0.0.0:*                                  
48 LISTEN            0                 128                                      *:80                                    *:*                                  
49 LISTEN            0                 128                                   [::]:22                                 [::]:*    已经可以看到80端口
50 [root@localhost ~]# systemctl disable --now firewalld  关闭防火墙
51 Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
52 Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
53 [root@localhost ~]# vim /etc/selinux/config
54 SELINUX=disabled改成这样
55 [root@localhost ~]# setenforce 0

     部署成功!

 

 

 2. 安装Mysql

        2.1 首先找到mysql的yum源,地址:dev.mysql.comv

 1 [root@localhost ~]# https://repo.mysql.com//mysql80-community-release-el7-5.noarch.rpm  下载
 2 [root@localhost ~]# rpm -ivh mysql80-community-release-el7-5.noarch.rpm 安装
 3 [root@localhost yum.repos.d]# ls
 4 CentOS-Base.repo  epel-modular.repo  epel.repo  epel-testing-modular.repo  epel-testing.repo  mysql-community.repo  mysql-community-source.repo   有mysql的源
 5 [root@localhost yum.repos.d]# vim mysql-community.repo 
 6 name=MySQL 5.7 Community Server
 7 baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch
 8 enabled=1   5.7的打开
 9 gpgcheck=1
10 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
11        file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
12 
13 [mysql80-community]
14 name=MySQL 8.0 Community Server
15 baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch
16 enabled=0    8.0关闭
17 gpgcheck=1
18 [root@localhost yum.repos.d]# dnf clean all   清理缓存
19 304 文件已删除
20 [root@localhost ~]# dnf makecache  建立缓存
21 [root@localhost ~]# dnf list all|grep '^mysql'  查看需要的依赖包
22 [root@localhost ~]# dnf -y install mysql mysql-common mysql-devel mysql-libs mysql-server 使用yum安装会自动创建mysql用户,使用二进制安装需要手动创建用户
23 [root@localhost ~]# id mysql   自动生成
24 uid=27(mysql) gid=27(mysql) 组=27(mysql)
25 [root@localhost ~]# which mysql
26 /usr/bin/mysql    环境变量也不需要设置直接可以找到
27 [root@localhost ~]# cat /etc/my.cnf 存放配置文件的位子
28 [root@localhost ~]# ls /etc/my.cnf.d/
29 client.cnf  mysql-default-authentication-plugin.cnf  mysql-server.cnf
30 [root@localhost ~]# systemctl enable --now mysqld 启动自动初始化
31 [root@localhost ~]# ss -antl
32 State             Recv-Q            Send-Q                       Local Address:Port                        Peer Address:Port           Process            
33 LISTEN            0                 128                                0.0.0.0:22                               0.0.0.0:*                                 
34 LISTEN            0                 128                                     *:3306                                   *:*                                 
35 LISTEN            0                 128                                      *:80                                     *:*                                 
36 LISTEN            0                 128                                   [::]:22                                  [::]:*                                 
37 LISTEN            0                 70                                       *:33060                                  *:*
38 [root@localhost ~]# ls /var/lib/mysql
39  auto.cnf        ca.pem              '#ib_16384_1.dblwr'   ib_logfile1     mysql.ibd            mysqlx.sock          public_key.pem    undo_001
40  binlog.000001   client-cert.pem      ib_buffer_pool       ibtmp1          mysql.sock           mysqlx.sock.lock     server-cert.pem   undo_002
41  binlog.index    client-key.pem       ibdata1             '#innodb_temp'   mysql.sock.lock      performance_schema   server-key.pem
42  ca-key.pem     '#ib_16384_0.dblwr'   ib_logfile0          mysql           mysql_upgrade_info   private_key.pem      sys
43 [root@localhost ~]# grep 'password' /var/log/mysql/mysqld.log 
44 2022-04-21T15:22:05.979115Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
45 没有密码可以直接登录
46 [root@localhost ~]# mysql   直接登录
47 Welcome to the MySQL monitor.  Commands end with ; or \g.
48 Your MySQL connection id is 8
49 Server version: 8.0.26 Source distribution
50 
51 Copyright (c) 2000, 2021, Oracle and/or its affiliates.
52 
53 Oracle is a registered trademark of Oracle Corporation and/or its
54 affiliates. Other names may be trademarks of their respective
55 owners.
56 
57 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
58                           设置密码
59 mysql> ALTER USER root@localhost IDENTIFIED BY 'runtime123!';
 1 [root@localhost ~]# https://repo.mysql.com//mysql80-community-release-el7-5.noarch.rpm  下载
 2 [root@localhost ~]# rpm -ivh mysql80-community-release-el7-5.noarch.rpm 安装
 3 [root@localhost yum.repos.d]# ls
 4 CentOS-Base.repo  epel-modular.repo  epel.repo  epel-testing-modular.repo  epel-testing.repo  mysql-community.repo  mysql-community-source.repo   有mysql的源
 5 [root@localhost yum.repos.d]# vim mysql-community.repo 
 6 name=MySQL 5.7 Community Server
 7 baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch
 8 enabled=1   5.7的打开
 9 gpgcheck=1
10 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
11        file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
12 
13 [mysql80-community]
14 name=MySQL 8.0 Community Server
15 baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch
16 enabled=0    8.0关闭
17 gpgcheck=1
18 [root@localhost yum.repos.d]# dnf clean all   清理缓存
19 304 文件已删除
20 [root@localhost ~]# dnf makecache  建立缓存
21 [root@localhost ~]# dnf list all|grep '^mysql'  查看需要的依赖包
22 [root@localhost ~]# dnf -y install mysql mysql-common mysql-devel mysql-libs mysql-server 使用yum安装会自动创建mysql用户,使用二进制安装需要手动创建用户
23 [root@localhost ~]# id mysql   自动生成
24 uid=27(mysql) gid=27(mysql) 组=27(mysql)
25 [root@localhost ~]# which mysql
26 /usr/bin/mysql    环境变量也不需要设置直接可以找到
27 [root@localhost ~]# cat /etc/my.cnf 存放配置文件的位子
28 [root@localhost ~]# ls /etc/my.cnf.d/
29 client.cnf  mysql-default-authentication-plugin.cnf  mysql-server.cnf
30 [root@localhost ~]# systemctl enable --now mysqld 启动自动初始化
31 [root@localhost ~]# ss -antl
32 State             Recv-Q            Send-Q                       Local Address:Port                        Peer Address:Port           Process            
33 LISTEN            0                 128                                0.0.0.0:22                               0.0.0.0:*                                 
34 LISTEN            0                 128                                     *:3306                                   *:*                                 
35 LISTEN            0                 128                                      *:80                                     *:*                                 
36 LISTEN            0                 128                                   [::]:22                                  [::]:*                                 
37 LISTEN            0                 70                                       *:33060                                  *:*
38 [root@localhost ~]# ls /var/lib/mysql
39  auto.cnf        ca.pem              '#ib_16384_1.dblwr'   ib_logfile1     mysql.ibd            mysqlx.sock          public_key.pem    undo_001
40  binlog.000001   client-cert.pem      ib_buffer_pool       ibtmp1          mysql.sock           mysqlx.sock.lock     server-cert.pem   undo_002
41  binlog.index    client-key.pem       ibdata1             '#innodb_temp'   mysql.sock.lock      performance_schema   server-key.pem
42  ca-key.pem     '#ib_16384_0.dblwr'   ib_logfile0          mysql           mysql_upgrade_info   private_key.pem      sys
43 [root@localhost ~]# grep 'password' /var/log/mysql/mysqld.log 
44 2022-04-21T15:22:05.979115Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
45 没有密码可以直接登录
46 [root@localhost ~]# mysql   直接登录
47 Welcome to the MySQL monitor.  Commands end with ; or \g.
48 Your MySQL connection id is 8
49 Server version: 8.0.26 Source distribution
50 
51 Copyright (c) 2000, 2021, Oracle and/or its affiliates.
52 
53 Oracle is a registered trademark of Oracle Corporation and/or its
54 affiliates. Other names may be trademarks of their respective
55 owners.
56 
57 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
58                           设置密码
59 mysql> ALTER USER root@localhost IDENTIFIED BY 'runtime123!';

 3.安装PHP  地址:php.net

 1 [root@localhost ~]# wget https://www.php.net/distributions/php-7.4.29.tar.xz   下载
 2 [root@localhost ~]# tar xf php-7.4.29.tar.xz   解压
 3 [root@localhost php-7.4.29]# dnf -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
 4 php-mysqlnd   安装依赖包
 5 [root@localhost php-7.4.29]# dnf -y install libxml2-devel 解决报错
 6 [root@localhost php-7.4.29]# dnf -y install oniguruma  解决报错
 7 [root@localhost php-7.4.29]# dnf -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm   解决报错
 8 ./configure --prefix=/usr/local/php7  \    解决报错
 9 --with-config-file-path=/etc \
10 --enable-fpm \
11 --enable-inline-optimization \
12 --disable-debug \
13 --disable-rpath \
14 --enable-shared \
15 --enable-soap \
16 --with-openssl \
17 --enable-bcmath \
18 --with-iconv \
19 --with-bz2 \
20 --enable-calendar \
21 --with-curl \
22 --enable-exif  \
23 --enable-ftp \
24 --enable-gd \
25 --with-jpeg \
26 --with-zlib-dir \
27 --with-freetype \
28 --with-gettext \
29 --enable-json \
30 --enable-mbstring \
31 --enable-pdo \
32 --with-mysqli=mysqlnd \
33 --with-pdo-mysql=mysqlnd \
34 --with-readline \
35 --enable-shmop \
36 --enable-simplexml \
37 --enable-sockets \
38 --with-zip \
39 --enable-mysqlnd-compression-support \
40 --with-pear \
41 --enable-pcntl \
42 --enable-posix
43 [root@localhost php-7.4.29]# dnf -y install libzip-devel解决报错
44 完成以上步骤即可成功
45 [root@localhost php-7.4.29]# make  -j 4  编译
46 [root@localhost ~]# echo 'export   这是环境变量PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
47 [root@localhost ~]# source /etc/profile.d/php7.sh  读一下
48 [root@localhost conf]# vim httpd.conf  配置文件
49 LoadModule proxy_module modules/mod_proxy.so取消注释
50 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
51 [root@localhost htdocs]# mkdir test.com创建一个测试目录
52 [root@localhost htdocs]# cd test.com/
53 [root@localhost test.com]# ls 
54 [root@localhost test.com]# vim index.php  进到里面写一个文件
55 <?php
56     phpinfo;
57 ?>
58 [root@localhost apache]# vim conf/httpd.conf
59 <VirtualHost *:80> 加到最下面
60     DocumentRoot "/usr/local/apache/htdocs/test.com"
61     ServerName test.example.com
62     ProxyRequests Off
63     ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test.com/$1
64     <Directory "/usr/local/apache/htdocs/test.com">
65         Options none
66         AllowOverride none
67         Require all granted
68     </Directory>
69 </VirtualHost>
70  [root@localhost apache]# vim conf/httpd.conf   
71     AddType application/x-compress .Z
72     AddType application/x-gzip .gz .tgz
73     AddType application/x-httpd-php .php        
74     AddType application/x-httpd-php-source .phps加入最后两行
75      DirectoryIndex index.php index.html  

 

这篇关于LAMP的部署的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!