LAMP的源码搭建

LAMP的源码搭建

一. 编译安装Apache

1. 提供软件包
1.apache:
[root@node4 ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@node4 ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@node4 ~]# wget https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz

[root@node4 ~]# ls
anaconda-ks.cfg
apr-1.7.0.tar.gz
apr-util-1.6.1.tar.gz
httpd-2.4.54.tar.gz
mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
php-7.4.29.tar.xz
[root@node4 ~]# 

[root@node4 ~]# tar xf apr-1.7.0.tar.gz 
[root@node4 ~]# tar xf apr-util-1.6.1.tar.gz 
[root@node4 ~]# tar xf httpd-2.4.54.tar.gz 
[root@node4 ~]# ls
anaconda-ks.cfg
apr-1.7.0
apr-1.7.0.tar.gz
apr-util-1.6.1
apr-util-1.6.1.tar.gz
httpd-2.4.54
httpd-2.4.54.tar.gz
mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
php-7.4.29.tar.xz
[root@node4 ~]# 

2. 创建用户,安装开发工具包,依赖包
[root@node4 ~]# useradd -r -M -s /sbin/nologin apache

[root@node4 ~]# yum -y groups mark install 'Development Tools'

[root@node4 ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
3. 编译安装apr,apr-util, apache
apr:
[root@node4 ~]# cd apr-1.7.0
[root@node4 apr-1.7.0]# vim configure
[root@node4 apr-1.7.0]# cat configure|grep cfgfile
    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
#    $RM "$cfgfile"
[root@node4 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@node4 apr-1.7.0]# make
[root@node4 apr-1.7.0]# make install


apr-util
[root@node4 apr-1.7.0]# cd ../apr-util-1.6.1
[root@node4 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@node4 apr-util-1.6.1]# make  
[root@node4 apr-util-1.6.1]# make install

httpd
[root@node4 apr-util-1.6.1]# cd ../httpd-2.4.54
[root@node4 httpd-2.4.54]# ./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@node4 httpd-2.4.54]# make 
[root@node4 httpd-2.4.54]# make install
4. 设置环境变量,man文档,头文件
[root@node4 ~]# cd /usr/local/apache/
[root@node4 apache]# ls
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules
[root@node4 apache]# 

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

man文档
[root@node4 apache]# vim /etc/man_db.conf 
[root@node4 apache]# cat /etc/man_db.conf |grep apache
MANDATORY_MANPATH                       /usr/local/apache/man
[root@node4 apache]# 

头文件
[root@node4 apache]# ln -s /usr/local/apache/include /usr/include/apache
[root@node4 apache]# 
5. 关闭防火墙和selinux
[root@node4 ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@node4 ~]# vim /etc/selinux/config 
[root@node4 ~]# setenforce 0
[root@node4 ~]# 
6. 配置service file
[root@node4 ~]# cd /usr/lib/systemd/system
[root@node4 system]# cp sshd.service httpd.service 
[root@node4 system]# vim httpd.service 
[root@node4 system]# cat 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@node4 system]# systemctl daemon-reload
[root@node4 system]# 
[root@node4 ~]# systemctl start httpd
[root@node4 ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@node4 ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0      128          0.0.0.0:22        0.0.0.0:*          
LISTEN 0      128             [::]:22           [::]:*          
LISTEN 0      128                *:80              *:*          
[root@node4 ~]# 
7. 访问

在这里插入图片描述

二. MySQL的二进制安装

1. 安装依赖包,创建用户,并解压
[root@node4 ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
[root@node4 ~]# useradd -r -M -s /sbin/nologin mysql
[root@node4 ~]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
2. 修改属主
[root@node4 ~]# cd /usr/local/
[root@node4 local]# ls
apache    etc      lib64                                share
apr       games    libexec                              src
apr-util  include  mysql-5.7.37-linux-glibc2.12-x86_64
bin       lib      sbin
[root@node4 local]# mv mysql-5.7.37-linux-glibc2.12-x86_64 mysql
[root@node4 local]# chown -R mysql.mysql mysql
[root@node4 local]# 
3. 配置环境变量,man文档,lib库,头文件
[root@node4 mysql]# ls
LICENSE  bin   include  man    support-files
README   docs  lib      share
[root@node4 mysql]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@node4 mysql]# source /etc/profile.d/mysql.sh

[root@node4 mysql]# vim /etc/man_db.conf 
[root@node4 mysql]# cat /etc/man_db.conf |grep mysql
MANDATORY_MANPATH                       /usr/local/mysql/man
[root@node4 mysql]#

[root@node4 mysql]# vim /etc/ld.so.conf.d/mysql.conf
[root@node4 mysql]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@node4 mysql]# ldconfig 
[root@node4 mysql]#

[root@node4 mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@node4 mysql]# 
4. 建立数据存放目录,并修改属主
[root@node4 ~]# mkdir -p /opt/data
[root@node4 ~]# chown -R mysql.mysql /opt/data
[root@node4 ~]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jul  5 18:37 data
[root@node4 ~]# 
5. 初始化数据库,并保存密码
[root@node4 ~]# mysqld --initialize --user mysql --datadir /opt/data
2022-07-05T10:39:22.692923Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-05T10:39:23.773491Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-05T10:39:23.927938Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-05T10:39:23.985669Z 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: bc6265d0-fc4e-11ec-b6d3-000c2939e984.
2022-07-05T10:39:23.986435Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-05T10:39:24.520794Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-05T10:39:24.520832Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-05T10:39:24.521221Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-05T10:39:24.822033Z 1 [Note] A temporary password is generated for root@localhost: 3SiWpfOe:RW&
[root@node4 ~]# echo '3SiWpfOe:RW&' > pass
6. 生成配置文件
[root@node4 ~]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

[root@node4 ~]# > /etc/my.cnf
[root@node4 ~]# vim /etc/my.cnf
[root@node4 ~]# cat /etc/my.cnf
[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
sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[root@node4 ~]# 
7. 配置服务启动脚本
[root@node4 ~]# cd /usr/local/mysql/support-files/
[root@node4 support-files]# ls
magic  mysql-log-rotate  mysql.server  mysqld_multi.server
[root@node4 support-files]# cp mysql.server mysqld
[root@node4 support-files]# vim mysqld
[root@node4 support-files]# chown -R mysql.mysql mysqld
[root@node4 support-files]# cat mysqld
basedir=/usr/local/mysql
datadir=/opt/data
8. 配置service文件,设置开机自启
[root@node4 ~]# cd /usr/lib/systemd/system
[root@node4 system]# cp sshd.service mysqld.service 
[root@node4 system]# vim mysqld.service 
[root@node4 system]# cat mysqld.service 
[Unit]
Description=mysqld server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysqld start
ExecStop=/usr/local/mysql/support-files/mysqld stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@node4 system]# systemctl daemon-reload
[root@node4 system]# 
9. 启动,安装lib库,设置密码
[root@node4 ~]# systemctl start mysqld
[root@node4 ~]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@node4 ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0      128          0.0.0.0:22        0.0.0.0:*          
LISTEN 0      128             [::]:22           [::]:*          
LISTEN 0      80                 *:3306            *:*          
LISTEN 0      128                *:80              *:*          
[root@node4 ~]# cat pass 
3SiWpfOe:RW&
[root@node4 ~]# mysql -uroot -p'3SiWpfOe:RW&';

[root@node4 ~]# mysql -uroot -p'3SiWpfOe:RW&';
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@node4 ~]# 

[root@node4 ~]# yum -y install ncurses-compat-libs

mysql> set password = password('run123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye
[root@node4 ~]# mysql -uroot -p'run123456';

三. PHP的源码安装

1. 解压
[root@node4 ~]# tar xf php-7.4.29.tar.xz 
2. 安装依赖包
[root@node4 ~]# 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 php-mysqlnd sqlite-devel libzip-devel

[root@node4 ~]# yum -y install https://vault.centos.org/centos/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

3. 编译安装
[root@node4 ~]# cd php-7.4.29 
[root@node4 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@node4 php-7.4.29]# make
[root@node4 php-7.4.29]# make install
4. 配置环境变量,lib,头文件
[root@node4 php7]# ls
bin  etc  include  lib  php  sbin  var
[root@node4 php7]# pwd
/usr/local/php7
[root@node4 php7]# echo 'export PATH=/usr/local/php7/bin:/usr/local/php7/:sbin:$PATH' > /etc/profile.d/php7.sh
[root@node4 php7]# source /etc/profile.d/php7.sh
[root@node4 php7]# which php
/usr/local/php7/bin/php

[root@node4 php7]# ln -s /usr/local/php7/include /usr/include/php

[root@node4 php7]# vim /etc/ld.so.conf.d/php.conf
[root@node4 php7]# cat /etc/ld.so.conf.d/php.conf
/usr/local/php7/lib
[root@node4 php7]# ldconfig 

[root@node4 ~]# php -v
PHP 7.4.29 (cli) (built: Jul  5 2022 19:23:11) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
[root@node4 ~]# 
5. 配置php-fpm
[root@node4 php-7.4.29]# ls
CODING_STANDARDS.md  appveyor             libs
CONTRIBUTING.md      azure                libtool
EXTENSIONS           azure-pipelines.yml  main
LICENSE              build                modules
Makefile             buildconf            pear
Makefile.fragments   buildconf.bat        php.ini-development
Makefile.objects     config.log           php.ini-production
NEWS                 config.nice          run-tests.php
README.REDIST.BINS   config.status        sapi
README.md            configure            scripts
TSRM                 configure.ac         tests
UPGRADING            docs                 travis
UPGRADING.INTERNALS  ext                  win32
Zend                 include
[root@node4 php-7.4.29]# \cp php.ini-production /etc/php.ini 
[root@node4 php-7.4.29]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@node4 php-7.4.29]# chmod +x /etc/rc.d/init.d/php-fpm
[root@node4 php-7.4.29]# ll /etc/rc.d/init.d/php-fpm
-rwxr-xr-x. 1 root root 54696280 Jul  5 21:18 /etc/rc.d/init.d/php-fpm
[root@node4 php-7.4.29]# 

[root@node4 ~]# cd /usr/local/php7/etc/
[root@node4 etc]# cp php-fpm.conf.default php-fpm.conf
[root@node4 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d
[root@node4 etc]# cd php-fpm.d/
[root@node4 php-fpm.d]# ls
www.conf.default
[root@node4 php-fpm.d]# cp www.conf.default www.conf
[root@node4 php-fpm.d]# ls
www.conf  www.conf.default
[root@node4 php-fpm.d]# 
[root@node4 etc]# cd php-fpm.d/
[root@node4 php-fpm.d]# ls
www.conf  www.conf.default
[root@node4 php-fpm.d]# vim www.conf
[root@node4 php-fpm.d]# cat www.conf|grep 9000
listen = 127.0.0.1:9000
[root@node4 php-fpm.d]# 
6. 查看
[root@node4 ~]# ls /etc/init.d/
README  functions  php-fpm
[root@node4 ~]# service php-fpm start
[root@node4 ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0      128          0.0.0.0:22        0.0.0.0:*          
LISTEN 0      128        127.0.0.1:9000      0.0.0.0:*          
LISTEN 0      128             [::]:22           [::]:*          
LISTEN 0      80                 *:3306            *:*          
LISTEN 0      128                *:80              *:*          
[root@node4 ~]# 

四. apache的配置

1. 启动代理模块
[root@node4 ~]# cd /usr/local/apache/conf/
[root@node4 conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@node4 conf]# vim httpd.conf 
[root@node4 conf]# cat httpd.conf|grep mod_proxy
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
2. 配置虚拟主机
[root@node4 htdocs]# pwd
/usr/local/apache/htdocs
[root@node4 htdocs]# ls
index.html
[root@node4 htdocs]# vim index.php
[root@node4 htdocs]# cat index.php 
<?php
    phpinfo();
?>
[root@node4 htdocs]# 

[root@node4 extra]# ls
httpd-autoindex.conf  httpd-mpm.conf
httpd-dav.conf        httpd-multilang-errordoc.conf
httpd-default.conf    httpd-ssl.conf
httpd-info.conf       httpd-userdir.conf
httpd-languages.conf  httpd-vhosts.conf
httpd-manual.conf     proxy-html.conf
[root@node4 extra]# vim httpd-vhosts.conf
[root@node4 extra]# pwd
/usr/local/apache/conf/extra
[root@node4 extra]# vim httpd-vhosts.conf
[root@node4 extra]# cat httpd-vhosts.conf 
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs"
    ServerName www.example.com
    ErrorLog "logs/www.example.com-error_log"
    CustomLog "logs/www.example.com-access_log" common
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/$1
    <Directory "/usr/local/apache/htdocs">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>
[root@node4 extra]# 


[root@node4 conf]# vim httpd.conf 
[root@node4 conf]# pwd
/usr/local/apache/conf
[root@node4 conf]# cat httpd.conf|grep vhosts
Include conf/extra/httpd-vhosts.conf
修改主配置文件,搜索AddType,添加以下内容
[root@node4 conf]# vim httpd.conf 
[root@node4 conf]# cat 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@node4 conf]# vim httpd.conf 
[root@node4 conf]# cat httpd.conf|grep index.php
    DirectoryIndex index.php index.html
[root@node4 conf]# 

修改属主
[root@node4 ~]# chown -R apache.apache /usr/local/apache/
[root@node4 ~]# ll /usr/local/apache/
total 36
drwxr-xr-x.  2 apache apache  262 Jul  5 17:56 bin
drwxr-xr-x.  2 apache apache  167 Jul  5 17:57 build
drwxr-xr-x.  2 apache apache   78 Jul  5 17:52 cgi-bin
drwxr-xr-x.  4 apache apache   84 Jul  5 21:48 conf
drwxr-xr-x.  3 apache apache 4096 Jul  5 17:52 error
drwxr-xr-x.  2 apache apache   41 Jul  5 21:34 htdocs
drwxr-xr-x.  3 apache apache 8192 Jul  5 17:52 icons
drwxr-xr-x.  2 apache apache 4096 Jul  5 17:57 include
drwxr-xr-x.  2 apache apache   58 Jul  5 18:12 logs
drwxr-xr-x.  4 apache apache   30 Jul  5 17:52 man
drwxr-xr-x. 14 apache apache 8192 Jul  5 17:52 manual
drwxr-xr-x.  2 apache apache 4096 Jul  5 17:56 modules
[root@node4 ~]# 

将注释取消掉
[root@node4 ~]# apachectl restart
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe39:e984%ens160. Set the 'ServerName' directive globally to suppress this message
[root@node4 ~]# vim /usr/local/apache/conf/httpd.conf 
[root@node4 ~]# cat /usr/local/apache/conf/httpd.conf|grep ServerName
# ServerName gives the name and port that the server uses to identify itself.
ServerName www.example.com:80
[root@node4 ~]# 
3. 重启
[root@node4 ~]# apachectl restart
[root@node4 ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0      128          0.0.0.0:22        0.0.0.0:*          
LISTEN 0      128        127.0.0.1:9000      0.0.0.0:*          
LISTEN 0      128             [::]:22           [::]:*          
LISTEN 0      80                 *:3306            *:*          
LISTEN 0      128                *:80              *:*          
[root@node4 ~]# 
  • 在这里插入图片描述

  • 在这里插入图片描述

4. 设置重启
[root@node4 ~]# ll /etc/rc.local 
lrwxrwxrwx. 1 root root 13 Sep 23  2021 /etc/rc.local -> rc.d/rc.local
[root@node4 ~]# ll /etc/rc.d/rc.local 
-rw-r--r--. 1 root root 474 Sep 23  2021 /etc/rc.d/rc.local
[root@node4 ~]# chmod +x /etc/rc.d/rc.local
[root@node4 ~]# vim /etc/rc.d/rc.local
[root@node4 ~]# cat /etc/rc.d/rc.local 
#!/bin/bash
/usr/local/apache/bin/apachectl start
service mysqld start
service php-fpm start
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值