源代码编译安装lamp

源代码编译安装lamp

一、关闭防火墙和selinux
[root@stw2 ~]# systemctl stop firewalld.service 
[root@stw2 ~]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@stw2 ~]# setenforce 0
[root@stw2 ~]# vim /etc/selinux/config 
[root@stw2 ~]# reboot
二、配置yum网络源,安装epel-release(浏览器搜索centos7的镜像站)
[root@stw2 ~]# cd /etc/yum.repos.d/
[root@stw2 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@stw2 yum.repos.d]# rm -rf *
[root@stw2 yum.repos.d]# ls
[root@stw2 yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2025-08-19 10:47:17--  https://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 116.207.134.94, 116.207.134.100, 111.180.200.85
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|116.207.134.94|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

100%[====================================================>] 2,523       --.-K/s   in 0s      

2025-08-19 10:47:17 (254 MB/s) -/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]

[root@stw2 yum.repos.d]# ls
CentOS-Base.repo
[root@stw2 yum.repos.d]# yum -y install epel-release
三、安装需要的工具包(编译工具、准备编译环境)
[root@stw2 ~]# yum -y install bzip2  vim make wget openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ libxml2-devel
四、解压并安装源码包
先将所需要的包上传

在这里插入图片描述

1、apr包
(1)解压
[root@stw2 ~]# tar -xzvf apr-1.7.0.tar.gz 
[root@stw2 ~]# ls
anaconda-ks.cfg        Downloads                                   Pictures
apr-1.7.0              httpd-2.4.54.tar.gz                         Public
apr-1.7.0.tar.gz       initial-setup-ks.cfg                        Templates
apr-util-1.6.1.tar.gz  Music                                       Videos
Desktop                mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
Documents              php-7.1.10.tar.bz2
(2)修改配置文件
[root@stw2 ~]# cd apr-1.7.0/
[root@stw2 apr-1.7.0]# ls
apr-config.in  buildconf         dso         libapr.rc     NOTICE         support
apr.dep        build.conf        emacs-mode  LICENSE       NWGNUmakefile  tables
apr.dsp        build-outputs.mk  encoding    locks         passwd         test
apr.dsw        CHANGES           file_io     Makefile.in   poll           threadproc
apr.mak        CMakeLists.txt    helpers     Makefile.win  random         time
apr.pc.in      config.layout     include     memory        README         tools
apr.spec       configure         libapr.dep  misc          README.cmake   user
atomic         configure.in      libapr.dsp  mmap          shmem
build          docs              libapr.mak  network_io    strings
[root@stw2 apr-1.7.0]# vim configure
[root@stw2 apr-1.7.0]# sed -i '/$RM "$cfgfile"/d' configure //删除了configure文件中的$RM "$cfgfile
[root@stw2 apr-1.7.0]# vim configure  //查看已经被删除
(3)配置 ./configure
[root@stw2 apr-1.7.0]# ls  //一定要在apr-1.7.0这个目录下进行配置
apr-config.in  buildconf         dso         libapr.rc     NOTICE         support
apr.dep        build.conf        emacs-mode  LICENSE       NWGNUmakefile  tables
apr.dsp        build-outputs.mk  encoding    locks         passwd         test
apr.dsw        CHANGES           file_io     Makefile.in   poll           threadproc
apr.mak        CMakeLists.txt    helpers     Makefile.win  random         time
apr.pc.in      config.layout     include     memory        README         tools
apr.spec       configure         libapr.dep  misc          README.cmake   user
atomic         configure.in      libapr.dsp  mmap          shmem
build          docs              libapr.mak  network_io    strings
[root@stw2 apr-1.7.0]# ./configure --prefix=/usr/local/apr
//prefix--指定路径
(4)编译、编译安装
[root@stw2 apr-1.7.0]# make
[root@stw2 apr-1.7.0]# make install
2、apr-utils包
(1)解压
[root@stw2 ~]# ls
anaconda-ks.cfg        Downloads                                   Pictures
apr-1.7.0              httpd-2.4.54.tar.gz                         Public
apr-1.7.0.tar.gz       initial-setup-ks.cfg                        Templates
apr-util-1.6.1.tar.gz  Music                                       Videos
Desktop                mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
Documents              php-7.1.10.tar.bz2
[root@stw2 ~]# tar -xzvf apr-util-1.6.1.tar.gz 
[root@stw2 ~]# ls
anaconda-ks.cfg        Documents                                   php-7.1.10.tar.bz2
apr-1.7.0              Downloads                                   Pictures
apr-1.7.0.tar.gz       httpd-2.4.54.tar.gz                         Public
apr-util-1.6.1         initial-setup-ks.cfg                        Templates
apr-util-1.6.1.tar.gz  Music                                       Videos
Desktop                mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
(2)配置、编译、编译安装
[root@stw2 ~]# cd apr-util-1.6.1
[root@stw2 apr-util-1.6.1]# ls
aprutil.dep     build.conf        docs               LICENSE         redis
aprutil.dsp     build-outputs.mk  encoding           Makefile.in     renames_pending
aprutil.dsw     CHANGES           export_vars.sh.in  Makefile.win    strmatch
aprutil.mak     CMakeLists.txt    hooks              memcache        test
apr-util.pc.in  config.layout     include            misc            uri
apr-util.spec   configure         ldap               NOTICE          xlate
apu-config.in   configure.in      libaprutil.dep     NWGNUmakefile   xml
buckets         crypto            libaprutil.dsp     README
build           dbd               libaprutil.mak     README.cmake
buildconf       dbm               libaprutil.rc      README.FREETDS
[root@stw2 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr  with--关联apr
[root@stw2 apr-util-1.6.1]# make
[root@stw2 apr-util-1.6.1]# make install
3、httpd(Apache)包
(1)解压
[root@stw2 ~]# ls
anaconda-ks.cfg        Documents                                   php-7.1.10.tar.bz2
apr-1.7.0              Downloads                                   Pictures
apr-1.7.0.tar.gz       httpd-2.4.54.tar.gz                         Public
apr-util-1.6.1         initial-setup-ks.cfg                        Templates
apr-util-1.6.1.tar.gz  Music                                       Videos
Desktop                mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@stw2 ~]# tar -xzvf httpd-2.4.54.tar.gz 
[root@stw2 ~]# ls
anaconda-ks.cfg        Documents             mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
apr-1.7.0              Downloads             php-7.1.10.tar.bz2
apr-1.7.0.tar.gz       httpd-2.4.54          Pictures
apr-util-1.6.1         httpd-2.4.54.tar.gz   Public
apr-util-1.6.1.tar.gz  initial-setup-ks.cfg  Templates
Desktop                Music                 Videos
(2)配置、编译、编译安装
[root@stw2 httpd-2.4.54]# ./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@stw2 httpd-2.4.54]# make
[root@stw2 httpd-2.4.54]# make install

(3)启动(没有设置环境变量需要带上绝对路径)
[root@stw2 httpd-2.4.54]# cd
[root@stw2 ~]# /usr/local/apache/bin/apachectl start
[root@stw2 ~]# cd /usr/local/apache/
[root@stw2 apache]# ls
bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules
[root@stw2 apache]# cd htdocs/
[root@stw2 htdocs]# ls
index.html     //网页存放位置
[root@stw2 htdocs]# cd /etc/httpd24/     //配置文件存放位置
[root@stw2 httpd24]# ls
extra  httpd.conf  magic  mime.types  original  

在这里插入图片描述

4、mysql包(二进制安装、不需要编译)
(1)创建一个mysql的服务用户
[root@stw2 ~]# useradd -r -M -s /sbin/nologin mysql
-r -M :不创建用户的家目录,并且uid要小于1000
[root@stw2 ~]# id mysql
uid=988(mysql) gid=982(mysql) groups=982(mysql)
(2)安装依赖包libncurses*
[root@stw2 ~]# yum -y install libncurses*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: pubmirror1.math.uh.edu
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Package ncurses-libs-5.9-14.20130511.el7_4.x86_64 already installed and latest version
Nothing to do
(3)解压(直接解压到/usr/local)
[root@stw2 ~]# tar -xzvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@stw2 local]# ls
apache  apr-util  etc    include  lib64    mysql-5.7.37-linux-glibc2.12-x86_64  share
apr     bin       games  lib      libexec  sbin                                 src
(4)做软连接
[root@stw2 local]# ln -sv /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/mysql/usr/local/mysql’ -> ‘/usr/local/mysql-5.7.37-linux-glibc2.12-x86_64’
[root@stw2 local]# ll
total 0
drwxr-xr-x  13 root root 152 Aug 19 14:33 apache
drwxr-xr-x   6 root root  58 Aug 19 14:21 apr
drwxr-xr-x   5 root root  43 Aug 19 14:24 apr-util
drwxr-xr-x.  2 root root   6 Apr 11  2018 bin
drwxr-xr-x.  2 root root   6 Apr 11  2018 etc
drwxr-xr-x.  2 root root   6 Apr 11  2018 games
drwxr-xr-x.  2 root root   6 Apr 11  2018 include
drwxr-xr-x.  2 root root   6 Apr 11  2018 lib
drwxr-xr-x.  2 root root   6 Apr 11  2018 lib64
drwxr-xr-x.  2 root root   6 Apr 11  2018 libexec
lrwxrwxrwx   1 root root  46 Aug 19 14:50 mysql -> /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x   9 root root 129 Aug 19 14:48 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x.  2 root root   6 Apr 11  2018 sbin
drwxr-xr-x.  5 root root  49 Jul 23 11:56 share
drwxr-xr-x.  2 root root   6 Apr 11  2018 src
[root@stw2 local]# ls
apache  apr-util  etc    include  lib64    mysql                                sbin   src
apr     bin       games  lib      libexec  mysql-5.7.37-linux-glibc2.12-x86_64  share
(5)将mysql的用户改为刚刚创建的用户mysql
[root@stw2 local]# chown -R mysql:mysql /usr/local/mysql
[root@stw2 local]# ll
total 0
drwxr-xr-x  13 root  root  152 Aug 19 14:33 apache
drwxr-xr-x   6 root  root   58 Aug 19 14:21 apr
drwxr-xr-x   5 root  root   43 Aug 19 14:24 apr-util
drwxr-xr-x.  2 root  root    6 Apr 11  2018 bin
drwxr-xr-x.  2 root  root    6 Apr 11  2018 etc
drwxr-xr-x.  2 root  root    6 Apr 11  2018 games
drwxr-xr-x.  2 root  root    6 Apr 11  2018 include
drwxr-xr-x.  2 root  root    6 Apr 11  2018 lib
drwxr-xr-x.  2 root  root    6 Apr 11  2018 lib64
drwxr-xr-x.  2 root  root    6 Apr 11  2018 libexec
lrwxrwxrwx   1 mysql mysql  46 Aug 19 14:50 mysql -> /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x   9 root  root  129 Aug 19 14:48 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x.  2 root  root    6 Apr 11  2018 sbin
drwxr-xr-x.  5 root  root   49 Jul 23 11:56 share
drwxr-xr-x.  2 root  root    6 Apr 11  2018 src
(6)创建一个专门存放数据的目录并将服务用户改为mysql
[root@stw2 local]# mkdir /opt/data
[root@stw2 local]# chown -R mysql:mysql /opt/data
(7)再安装一个依赖包libaio
[root@stw2 local]# yum -y install libaio
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirror.math.princeton.edu
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Package libaio-0.3.109-13.el7.x86_64 already installed and latest version
Nothing to do
5、初始化数据库
(1)初始化数据库、软连接include、将配置文件/usr/local/mysql/lib写入/etc/ld.so.conf.d/mysql.conf
[root@stw2 ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data/
2025-08-19T07:00:02.326950Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-08-19T07:00:02.925170Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-08-19T07:00:03.008938Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-08-19T07:00:03.045682Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 212f130b-7cca-11f0-a5fb-000c29a41fc0.
2025-08-19T07:00:03.047652Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-08-19T07:00:03.497719Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-08-19T07:00:03.497756Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-08-19T07:00:03.501263Z 0 [Warning] CA certificate ca.pem is self signed.
2025-08-19T07:00:04.046454Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@stw2 local]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql  //软连接/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[root@stw2 local]# cd /usr/local/include/
[root@stw2 include]# ls
mysql
[root@stw2 ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@stw2 ~]# vim /etc/ld.so.conf.d/mysql.conf 
[root@stw2 ~]# ldconfig     //没有报错说明配置文件没有问题
(2)编辑mysql配置文件(/etc/my.cnf)
[root@stw2 ~]# vim /etc/my.cnf
[root@stw2 ~]# cd /usr/local/mysql
[root@stw2 mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@stw2 mysql]# cd support-files/
[root@stw2 support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@stw2 support-files]# vim mysql.server 

在这里插入图片描述

在这里插入图片描述

(3)定义mysql服务可以使用systemd来进行管理
[root@stw2 ~]# vim /usr/lib/systemd/system/mysqld.service
[root@stw2 ~]# systemctl daemon-reload 
[root@stw2 ~]# systemctl enable --now mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.

在这里插入图片描述

(4)设置环境变量
[root@stw2 ~]# vim /etc/profile
[root@stw2 ~]# source /etc/profile

在这里插入图片描述

(5)设置密码
[root@stw2 ~]# 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.37 MySQL Community Server (GPL)

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> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit
Bye
[root@stw2 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.37 MySQL Community Server (GPL)

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> 
6、php包
(1)安装依赖包,安装GD库和GD库关联程序,用来处理和生成图片
[root@stw2 ~]# yum -y install \
> libjpeg \
> libjpeg-devel \
> libpng libpng-devel \
> freetype freetype-devel \
> libxml2 \
> libxml2-devel \
> zlib zlib-devel \
> curl curl-devel
(2)解压
[root@stw2 ~]# tar -xjvf php-7.1.10.tar.bz2 
[root@stw2 ~]# ls
anaconda-ks.cfg        Downloads                                   php-7.1.10.tar.bz2
apr-1.7.0              httpd-2.4.54                                Pictures
apr-1.7.0.tar.gz       httpd-2.4.54.tar.gz                         Public
apr-util-1.6.1         initial-setup-ks.cfg                        Templates
apr-util-1.6.1.tar.gz  Music                                       Videos
Desktop                mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
Documents              php-7.1.10
(3)配置、编译、编译安装
[root@stw2 php-7.1.10]# ./configure \
> --prefix=/usr/local/php \
> --with-apxs2=/usr/local/apache/bin/apxs \
> --with-mysql-sock=/tmp/mysql.sock \
> --with-mysqli \
> --with-zlib \
> --with-curl \
> --with-gd \
> --with-jpeg-dir \
> --with-png-dir \
> --with-freetype-dir \
> --with-openssl \
> --enable-mbstring \
> --enable-xml \
> --enable-session \
> --enable-ftp \
> --enable-pdo \
> --enable-tokenizer \
> --enable-zip
[root@stw2 php-7.1.10]# make
[root@stw2 php-7.1.10]# make install
[root@stw2 php-7.1.10]# libtool --finish /root/php-7.1.10/libs
(4)配置php

在这里插入图片描述

改时区为亚洲上海
[root@stw2 php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
[root@stw2 php-7.1.10]# vim /usr/local/php/lib/php.ini 

在这里插入图片描述

让httpd支持index.php网页
[root@stw2 ~]# cd /etc/httpd24/
[root@stw2 httpd24]# ls
extra  httpd.conf  httpd.conf.bak  magic  mime.types  original
[root@stw2 httpd24]# vim httpd.conf
[root@stw2 httpd24]# cd /usr/local/apache/
[root@stw2 apache]# ls
bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules
[root@stw2 apache]# cd htdocs/
[root@stw2 htdocs]# ls
index.html
[root@stw2 htdocs]# rm -rf index.html
[root@stw2 htdocs]# vim index.php
[root@stw2 htdocs]# ls
index.php

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

(5)重启服务
[root@stw2 ~]# /usr/local/apache/bin/apachectl stop
[root@stw2 ~]# /usr/local/apache/bin/apachectl start

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值