源码编译安装lamp

源码编译安装与lamp源码部署

1:源码包的由来

(1):源码包是什么

​ 源码包是一个包含软件程序源代码的压缩文件或文件夹。它通常用于分发和共享软件的源代码,以便其他开发人员可以查看、修改和编译该软件。源码包通常包含源代码文件、配置文件、库文件和其他必要的资源文件。在linux环境中安装源码包是比较常见的,由于源码包通常是使用c语言进行编译的,编译需要使用到C语言编译器,将源码编译成二进制文件,

​ (2):源码包的安装

下载源码包:从软件的官方网站或其他可信来源下载源码包。源码包通常以压缩文件的形式提供,如.zip或.tar.gz。

解压源码包:使用解压缩工具将源码包解压缩到一个目录中。

阅读文档:源码包通常会提供一份说明文档或README文件,其中包含了安装和配置的详细说明。如何正确地安装和配置软件。

安装依赖项:某些软件可能依赖于其他库或软件包。在安装源码包之前,您可能需要先安装这些依赖项。请参考文档中的说明,安装所需的依赖项。

编译源代码:源码包中通常包含源代码文件,您需要将其编译成可执行文件。编译过程可能因软件而异,但通常需要使用编译器(如GCC)执行一系列编译命令。

安装软件:编译成功后,您可以按照文档中的说明,将生成的可执行文件或其他必要文件复制到系统的适当位置。这可能涉及将文件复制到特定的目录、设置环境变量或运行安装脚本。

####: 源码包安装三部曲:

将源码包解压后进入对应的目录中

第一步: ./configure(定制组件编译)

1.指定安装路径,例如 --prefix=/opt/nginx-1.12
2.启用或禁用某项功能, 例如 --enable-ssl
3.和其它软件关联,例如--with-pcre
4.检查安装环境,例如是否有编译器 gcc,是否满足软件的依赖需求
5.检测通过后生成Makefile文件

第二步: make (正式编译)

1.执行make命令进行编译, 可以使用-j指定CPU核心数进行编译
2.按Makefile文件进行编译, 编译成可执行二进制文件
3.生成各类模块和主程序

第三步: make install (安装)

1.按Makefile定义好的路径拷贝至安装目录中

编译安装完成后需要做:

写入环境变量:

如果安装时不是使用的默认路径,则必须要修改PATH环境变量,以能够识别此程序的二进制文件路径;
修改/etc/profile文件里写入export PATH=$PATH:/<安装路径>或在/etc/profile.d/目录建立一个以.sh为后缀的文件,在里面定义export PATH=$PATH:/安装路径

库文件:

默认情况下,系统搜索库文件的路径只有/lib,/usr/lib
增添额外库文件搜索路径方法:
在/etc/ld.so.conf.d/中创建以<二进制程序名>.conf的文件,而后把要增添的路径直接写至此文件中。此时库文件增添的搜索路径重启后有效,若要使用增添的路径立即生效则要使用ldconfig命令重新读取配置文件
ldconfig:通知系统重新搜索库文件

头文件:

头文件是输出给系统
系统默认在/usr/include中找头文件,若要增添头文件搜索路径,使用链接进行

man帮助文档

man文件路径:安装在--prefix指定的目录下的man目录
默认:系统在/usr/share/man中找man文件。此时因为编译安装的时候不是安装到默认路径下,如果要查找man文件则可以使用以下两种方法:
man -M /path/to/man_dir command
在/etc/man_db.conf文件中添加一条MANPATH

2: 编译安装nginx

(1):下载并解压nginx源码包

#: 在Linux系统中安装wget下载工具(系统中没有wget命令时执行)
[root@localhost ~]# yum -y install wget

#:在官网找到nginx源码压缩包,并下载
 [root@localhost ~]# wget http://nginx.org/download/nginx-1.24.0.tar.gz

#:由于文件是使用tar进行压缩,直接使用tar解压
[root@localhost ~]# file nginx-1.24.0.tar.gz 
nginx-1.24.0.tar.gz: gzip compressed data, last modified: Tue Apr 11 01:45:38 2023, from Unix, original size 7042560
[root@localhost ~]# tar xf nginx-1.24.0.tar.gz 
 

(2):指定编译参数编译nginx

#: 安装依赖
yum -y install gcc gcc-c++ pcre-devel zlib-devel

[root@localhost nginx-1.24.0]# ./configure --prefix=/opt/nginx-1.24.0
[root@localhost nginx-1.24.0]# echo $?
0
#: 返回值为0,说明编译成功
#:编译前后对比
#:编译前
[root@localhost nginx-1.24.0]# ls
CHANGES     LICENSE  auto  configure  html  src
CHANGES.ru  README   conf  contrib    man
#:编译后
[root@localhost nginx-1.24.0]# ls
CHANGES     LICENSE   README  conf       contrib  man   src
CHANGES.ru  Makefile  auto    configure  html     objs
#: 发现多出来一个 Makefile 和objs

(3):安装nginx

#: 使用make命令编译
[root@localhost nginx-1.24.0]# make 
-bash: make: command not found
#: 提示make命令没有安装, 安装make命令
[root@localhost nginx-1.24.0]# yum -y install make
----省略-----
Installed:
  make-1:4.2.1-10.el8.x86_64                                       
Complete!
#: 继续编译
[root@localhost nginx-1.24.0]# make
[root@localhost nginx-1.24.0]# echo $?
0
#: 返回值为0,编译成功,然后进行安装
[root@localhost nginx-1.24.0]# make install 

(4):使用nginx

#: 关闭防火墙和selinux,并启动nginx
[root@localhost nginx-1.24.0]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost nginx-1.24.0]# setenforce 0
#: 写入环境变量
[root@localhost nginx-1.24.0]# export PATH=/opt/nginx-1.24.0/sbin:$PATH
#: 查看端口号
[root@localhost nginx-1.24.0]# ss -antl
State   Recv-Q  Send-Q   Local Address:Port     Peer Address:Port  
LISTEN  0       128            0.0.0.0:80            0.0.0.0:*     
LISTEN  0       128            0.0.0.0:22            0.0.0.0:*     
LISTEN  0       128               [::]:22               [::]:*     
#: 此时nginx启动了一个80的端口,证明服务已经正常运行

(4):访问nginx

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

编译安装LAMP

1: 下载和安装apr, apr-util

#:安装所需的依赖包
[root@localhost httpd-2.4.57]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++

#: (1): 在官网找到最新版apr, apr-util源码包并下载
[root@localhost ~]# wget 
https://downloads.apache.org/apr/apr-util-1.6.3.tar.gz
[root@localhost ~]# wget 
https://downloads.apache.org/apr/apr-1.7.4.tar.gz
#:  (2): 将下载的包解压
[root@localhost ~]# tar xf httpd-2.4.57.tar.gz 
[root@localhost ~]# tar xf apr-1.7.4.tar.gz 
[root@localhost ~]# tar xf apr-util-1.6.3.tar.gz 
#  (3): 将apr-1.7.4目录configure文件中指定条目删除或注释
[root@localhost apr-1.7.4]# vim configure
 cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    $RM "$cfgfile" #:将此行删除或注释
#: (4):编译安装apr
[root@localhost apr-1.7.4]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.4]# echo $?
0
[root@localhost apr-1.7.4]# make && make install
[root@localhost apr-1.7.4]# echo $?
0

#: (5): 编译安装 apr-util 
[root@localhost apr-util-1.6.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.3]# echo $?
0
#: 安装依赖
[root@localhost apr-util-1.6.3]# yum -y install expat-devel
[root@localhost apr-util-1.6.3]# make
[root@localhost apr-util-1.6.3]# echo $? 
0
#:返回值为0,编译正常
#: (6):安装
[root@localhost apr-util-1.6.3]# make install
[root@localhost apr-util-1.6.3]# echo $? 
0

2: 下载安装httpd

#:(1):下载并解压httpd源码包
[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.57.tar.gz
[root@localhost ~]# tar xf httpd-2.4.57.tar.gz 

#: (2): 编译httpd服务, 
[root@localhost httpd-2.4.57]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --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 httpd-2.4.57]# echo $? 
0
#: (3): 安装httpd服务
[root@localhost httpd-2.4.57]# make && make install 
[root@localhost httpd-2.4.57]# echo $? 
0
#: (4):安装之后配置
[root@localhost httpd-2.4.57]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost httpd-2.4.57]# source /etc/profile.d/httpd.sh
[root@localhost httpd-2.4.57]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost httpd-2.4.57]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config

#: (5): 将/etc/httpd24/httpd.conf中ServerName前的#删除
[root@localhost httpd-2.4.57]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf

#: (6): 启动httpd服务
[root@localhost httpd-2.4.57]# apachectl start 
[root@localhost httpd-2.4.57]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port   
LISTEN   0        128              0.0.0.0:22            0.0.0.0:*      
LISTEN   0        128                    *:80                  *:*      
LISTEN   0        128                 [::]:22               [::]:*  
    
#: 关闭防火墙和selinux
[root@localhost lib]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost lib]# setenforce 0

3: 安装mysql

#: 安装依赖
[root@localhost local]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

#: 将mysql源码包上传至服务器中进行解压
[root@localhost ~]# tar -xf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz 
#: 将解压后的文件移动到/usr/local下,并改名为mysql
[root@localhost ~]# mv mysql-5.7.39-linux-glibc2.12-x86_64 /usr/local/mysql
[root@localhost ~]# ls /usr/local/
apache  apr-util  etc    include  lib64    mysql  share
apr     bin       games  lib      libexec  sbin   src
#: 创建mysql系统用户和mysql系统组
 [root@localhost ~]# groupadd -r mysql
[root@localhost ~]# useradd -r -s /sbin/nologin -M -g mysql mysql
[root@localhost ~]# id mysql
uid=993(mysql) gid=990(mysql) groups=990(mysql)
#:递归修改mysql文件夹的属主属组
[root@localhost ~]# cd /usr/local/
[root@localhost local]# chown -R mysql:mysql mysql
[root@localhost local]# ll -d mysql/
drwxr-xr-x. 9 mysql mysql 129 Aug 29 14:04 mysql/
[root@localhost local]# ll  mysql/
total 268
-rw-r--r--.  1 mysql mysql 255074 Jun  8  2022 LICENSE
-rw-r--r--.  1 mysql mysql    566 Jun  8  2022 README
drwxr-xr-x.  2 mysql mysql   4096 Aug 29 14:04 bin
drwxr-xr-x.  2 mysql mysql     55 Aug 29 14:04 docs
-----省略-----
#: 添加mysql的环境变量  
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# . /etc/profile.d/mysql.sh 
[root@localhost local]# echo $PATH
/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

#: 建立mysql数据存放目录
[root@localhost local]# mkdir /opt/data
[root@localhost local]# chown -R mysql:mysql /opt/data/
[root@localhost local]# ll -d /opt/data
drwxr-xr-x. 2 mysql mysql 6 Aug 29 14:25 /opt/data

#: 初始化数据库
[root@localhost local]# ./mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
-------省略-------
 2023-08-29T06:30:30.734710Z 1 [Note] A temporary password is generated for root@localhost: lzH?uSii>4X%
***:最后一行有一个mysql登录的临时密码,只能使用一次,登录数据库后必重新设置一次密码
 
 #: 配置mysql
 [root@localhost local]# ls
apache  apr-util  etc    include  lib64    mysql  share
apr     bin       games  lib      libexec  sbin   src
[root@localhost local]# ln -s mysql/include/ include/mysql
[root@localhost local]# ll -d include/mysql 
lrwxrwxrwx. 1 root root 14 Aug 29 14:36 include/mysql -> mysql/include/
[root@localhost local]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost local]# ldconfig

#: 生成配置文件
[root@localhost local]# cat > /etc/my.cnf <<EOF
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF


#: 配置启动脚本
[root@localhost local]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost local]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@localhost local]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld

#: 启动mysql
[root@localhost local]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost local]# ss -antl
State   Recv-Q  Send-Q   Local Address:Port     Peer Address:Port  
LISTEN  0       128            0.0.0.0:22            0.0.0.0:*     
LISTEN  0       80                   *:3306                *:*     
LISTEN  0       128                  *:80                  *:*     
LISTEN  0       128               [::]:22               [::]:* 
    
#: 修改mysql数据库的密码
[root@localhost lib]# mysql -uroot -p
Enter password: #:这个密码是初始化时自动生成的密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.39
mysql> set password = password('Liuhongsheng1');
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> exit
Bye






4: 安装php

#: (1):官网上下载php最新版本源码包,并解压
[root@localhost ~]# wget https://www.php.net/distributions/php-8.2.9.tar.xz
[root@localhost ~]# tar -xf php-8.2.9.tar.xz 

#: 安装依赖:
yum -y install libxml2-devel  sqlite-devel openssl-devel libxml2-devel  bzip2-devel libcurl-devel readline-devel libpng-devel libjpeg-turbo-devel freetype-devel libzip-devel 
yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
#: 编译安装
[root@localhost php-8.2.9]#  ./configure --prefix=/usr/local/php7  --with-config-file-path=/etc --enable-fpm --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-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-posi
[root@localhost php-8.2.9]# make -j $(cat /proc/cpuinfo |grep processor|wc -l) && make install

#: 安装后配置
[root@localhost php-8.2.9]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost php-8.2.9]# source /etc/profile.d/php7.sh
[root@localhost php-8.2.9]#  which php
/usr/local/php7/bin/php
[root@localhost php-8.2.9]# php -v
PHP 8.2.9 (cli) (built: Aug 29 2023 23:08:29) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.9, Copyright (c) Zend Technologies

#: 配置php-fpm
[root@localhost php-8.2.9]# cp php.ini-production /etc/php.ini
[root@localhost php-8.2.9]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-8.2.9]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-8.2.9]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-8.2.9]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

#:编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf)
[root@localhost php-8.2.9]# vim /usr/local/php7/etc/php-fpm.conf
[root@localhost php-8.2.9]# tail -5 /usr/local/php7/etc/php-fpm.conf

pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8

#: 启动php服务
[root@localhost php-8.2.9]# service php-fpm start
Starting php-fpm  done

#: 查看默认端口是否已经监听
[root@localhost php-8.2.9]# ss -antl
State   Recv-Q  Send-Q   Local Address:Port     Peer Address:Port  
LISTEN  0       128          127.0.0.1:9000          0.0.0.0:*     
LISTEN  0       128            0.0.0.0:22            0.0.0.0:*     
LISTEN  0       128               [::]:22               [::]:* 
  
#: 启用httpd相关模块,将/etc/httpd24/httpd.conf中下面两行取消注释
[root@localhost php-8.2.9]# vim /etc/httpd24//httpd.conf  
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

#: 创建虚拟主机目录并生成php测试页
[root@localhost ~]# mkdir /usr/local/apache/htdocs/liu.com
[root@localhost ~]# vim /usr/local/apache/htdocs/liu.com/index.php
[root@localhost ~]# cat  /usr/local/apache/htdocs/liu.com/index.php
<?php
   phpinfo();
?>
[root@localhost ~]# chown -R apache:apache /usr/local/apache/htdocs/
[root@localhost ~]# ll -d /usr/local/apache/htdocs/ 
drwxr-xr-x. 4 apache apache 59 Aug 30 10:29 /usr/local/apache/htdocs/
   

#: 在 /etc/httpd24/httpd.conf最后添加以下内容  
 [root@localhost ~]# tail -11 /etc/httpd24/httpd.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/liu.com"
    ServerName www.liu.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/liu.com/$1
    <Directory "/usr/local/apache/htdocs/liu.com">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

#: 在 /etc/httpd24/httpd.conf中搜索AddType 添加下面两行
 [root@localhost ~]# head -400  /etc/httpd24/httpd.conf | tail -4
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php  #:添加      
    AddType application/x-httpd-php-source .phps #: 添加

 #: 重启httpd服务   
[root@localhost ~]# apachectl stop
[root@localhost ~]# apachectl start
[root@localhost ~]# ss -antl
State   Recv-Q  Send-Q   Local Address:Port     Peer Address:Port  
LISTEN  0       128          127.0.0.1:9000          0.0.0.0:*     
LISTEN  0       128            0.0.0.0:22            0.0.0.0:*     
LISTEN  0       128                  *:80                  *:*     
LISTEN  0       128               [::]:22               [::]:* 

验证: 修改本地域名解析文件C:\Windows\System32\drivers\etc\hosts 添加对应的域名地址对应关系,使用浏览器进行验证

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

e Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 :80 :
LISTEN 0 128 [::]:22 [::]:


验证: 修改本地域名解析文件C:\Windows\System32\drivers\etc\hosts 添加对应的域名地址对应关系,使用浏览器进行验证

[外链图片转存中...(img-xUCrofBS-1693910617407)]



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值