lamp +++

本文档详细记录了在Linux环境下手动编译安装Apache、MySQL和PHP的过程,包括安装依赖、配置编译选项、修改环境变量、设置服务启动脚本以及测试运行。在安装过程中,还涉及到了SELinux的配置和权限设置,确保服务能够正常启动和运行。
摘要由CSDN通过智能技术生成

安装httpd

[root@localhost ~]# yum groups mark install "Development Tools"
Last metadata expiration check: 1 day, 19:35:06 ago on Thu 21 Apr 2022 02:18:55 PM CST.
Dependencies resolved.
=============================================================================
 Package          Architecture    Version             Repository        Size
=============================================================================
Installing Groups:
 Development Tools
                                                                            
 
Transaction Summary
=============================================================================
 
Is this ok [y/N]: y
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
 
[root@localhost ~]# id apache
uid=48(apache) gid=48(apache) groups=48(apache)
 
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
[root@localhost ~]# yum install -y 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@10 ~]# ls
anaconda-ks.cfg   apr-util-1.6.1.tar.gz
apr-1.7.0.tar.gz  httpd-2.4.53.tar.gz
[root@localhost ~]# tar -xf apr-util-1.6.1.tar.gz
[root@localhost ~]# tar -xf apr-1.7.0.tar.gz
[root@localhost ~]# tar -xf httpd-2.4.53.tar.gz


[root@localhost ~]# tar xf apr-1.7.0.tar.gz 
[root@localhost ~]# cd apr-1.7.0
[root@localhost apr-1.7.0]# vim configure
[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
 
[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
 
 
[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 httpd-2.4.53]# make
没有出现报错
[root@localhost httpd-2.4.53]# make install

设置环境变量
[root@localhost ~]# ls /usr/local/
apache  apr-until  bin  games    lib    libexec  share
apr     apr-util   etc  include  lib64  sbin     src
 
 
[root@localhost ~]# cd /usr/local/apache/
[root@localhost apache]# ls
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules
 
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH'
 
[root@localhost ~]# source /etc/profile.d/apache.sh
[root@localhost ~]# which apachectl
/usr/local/apache/bin/apachectl
[root@localhost ~]# which httpd
/usr/local/apache/bin/httpd
[root@localhost ~]# vim /etc/man_db.conf 
 
添加一个文档
MANDATORY_MANPATH                       /usr/local/apache/man




[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# vim /etc/selinux/config
[root@localhost ~]# ss -antl
State  Recv-Q  Send-Q   Local Address:Port   Peer Address:Port Process                                                        
LISTEN 0       128            0.0.0.0:22          0.0.0.0:*                                                                   
LISTEN 0       128               [::]:22             [::]:*                                                                   
LISTEN 0       128                  *:80                *:*                                                  

mysql

//安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

//创建用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
[root@localhost ~]# id mysql
uid=994(mysql) gid=991(mysql) groups=991(mysql)

anaconda-ks.cfg   apr-util-1.6.1         httpd-2.4.53.tar.gz
apr-1.7.0         apr-util-1.6.1.tar.gz
apr-1.7.0.tar.gz  httpd-2.4.53
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
[root@localhost ~]# id mysql
uid=993(mysql) gid=991(mysql) groups=991(mysql)
[root@localhost ~]# ls
anaconda-ks.cfg   apr-util-1.6.1         httpd-2.4.53.tar.gz
apr-1.7.0         apr-util-1.6.1.tar.gz
apr-1.7.0.tar.gz  httpd-2.4.53
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# source /etc/profile.d/mysql.sh
[root@localhost ~]# which mysql
/usr/bin/which: no mysql in (/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@localhost ~]# mkdir /opt/data/
[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll /opt/
total 0
drwxr-xr-x 2 mysql mysql 6 Apr 21 16:02 data
[root@localhost ~]# vim /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

//加软连接,添加配置并重新读取配置
[root@localhost ~]# ls /usr/local/mysql
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost ~]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# ldconfig
[root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# vim /etc/init.d/mysqld   //找到以下两行加上路径
basedir=/usr/local/mysql
datadir=/opt/data

//启动服务
[root@localhost ~]# service mysqld start
Starting MySQL. SUCCESS! 
[root@localhost ~]# 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                [::]:*      
LISTEN  0        80                      *:3306                 *:*      

//下载安装包,进入数据库修改密码
[root@localhost ~]# yum -y install ncurses-compat-libs

[root@localhost ~]# mysql
mysql> set password=password("123456");
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> quit

安装php  apache

[root@localhost ~]# wget http://cn.php.net/distributions/php-7.2.9.tar.xz

//下载依赖包
[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 

dnf -y install sqlite-devel
dnf -y install oniguruma
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
dnf -y install libzip-devel






//解压并编译安装php
[root@localhost ~]# tar xf php-7.2.9.tar.xz 
[root@localhost ~]# cd php-7.2.9
[root@localhost php-7.2.9]#  ./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 php-7.4.29]# make && make install
[root@localhost php-7.4.29]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
source /etc/profile.d/php7.sh
[root@localhost php-7.4.29]# which php
/usr/local/php7/bin/php
which php
//配置php-fpm2
[root@localhost php-7.4.29]# cp php.ini-prodction /etc/php.ini   //生产环境
cp: overwrite '/etc/php.ini'? y
[root@localhost php-7.4.29]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.4.29]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-7.4.29]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-7.4.29]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf



//生成php测试页面,修改权限
[root@localhost ~]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# vim index.php
<?php
    phpinfo();
?>

[root@10 php-7.4.29]# \cp php.ini-production /etc/php.ini
[root@10 php-7.4.29]# ls
appveyor             ext                  README.REDIST.BINS
azure                EXTENSIONS           run-tests.php
azure-pipelines.yml  include              sapi
build                libs                 scripts
buildconf            LICENSE              tests
buildconf.bat        main                 travis
CODING_STANDARDS.md  Makefile.fragments   TSRM
config.log           Makefile.objects     UPGRADING
config.nice          NEWS                 UPGRADING.INTERNALS
configure            pear                 win32
configure.ac         php.ini-development  Zend
CONTRIBUTING.md      php.ini-production
docs                 README.md
[root@10 php-7.4.29]# ls sapi/
apache2handler  cgi  cli  embed  fpm  litespeed  phpdbg
[root@10 php-7.4.29]# ls sapi/fpm/
config.m4  init.d.php-fpm.in  php-fpm.8.in        status.html.in
CREDITS    LICENSE            php-fpm.conf.in     tests
fpm        Makefile.frag      php-fpm.service.in  www.conf.in
[root@10 php-7.4.29]# cp sapi/fpm/php-fpm /etc/init.d/php-fpm
[root@10 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.default   www.conf


[root@localhost htdocs]# vim /usr/local/php7/etc/php-fpm.d/www.conf
listen = 127.0.0.1:9000    //找到此行
listen = 0.0.0.0:9000      //修改为所有IP
[root@localhost htdocs]# service php-fpm restart   //重启服务
Gracefully shutting down php-fpm . done
Starting php-fpm  done
[root@localhost htdocs]# 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               0.0.0.0:9000           0.0.0.0:*      
LISTEN  0        128                  [::]:22                [::]:*     


 

打不开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值