lamp部署


安装httpd


[root@localhost ~]# rm -rf /etc/yum.repos.d/*
//此处是centos8的源
阿里源配置地址:https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.d9671b11oRvHUs
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

下载依赖包(因为下的是三个程序的依赖包稍等一会)
[root@localhost yum.repos.d]# yum -y install openssl-devel pcre-devel make expat-devel libtool gcc gcc-c++ ncurses-devel libzip-devel openssl epel-release cmake mariadb-devel 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 wget vim epel-release libxslt libxslt-devel mhash mhash-devel php-mysqlnd http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm  ncurses-devel libsqlite3x-devel  ncurses-compat-libs mariadb-devel https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm epel-release


Dependencies resolved.

 Package                Arch   Version                       Repo       Size

Installing:
 expat-devel            x86_64 2.2.5-4.el8                   base       55 k
 gcc                    x86_64 8.5.0-4.el8_5                 AppStream  23 M
 gcc-c++                x86_64 8.5.0-4.el8_5                 AppStream  12 M
 libtool                x86_64 2.4.6-25.el8                  AppStream 709 k
 openssl-devel          x86_64 1:1.1.1k-5.el8_5              base      2.3 M
 pcre-devel             x86_64 8.42-6.el8                    base      551 k
Upgrading:

.......

  pkgconf-m4-1.4.2-1.el8.noarch                                              
  pkgconf-pkg-config-1.4.2-1.el8.x86_64                                      
  zlib-devel-1.2.11-17.el8.x86_64                                            

Complete!

创建apache系统用户

[root@localhost ~]# useradd -rMs /sbin/nologin apache

下载所需要的依赖包

[root@localhost ~]# cd /usr/src 
[root@localhost src]# wget https://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz
[root@localhost src]# wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
[root@localhost src]# wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.54.tar.gz
[root@localhost src]# ls
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  debug  httpd-2.4.54.tar.gz  kernels

解压

[root@localhost src]# tar xf apr-1.7.0.tar.gz -C /usr/local
[root@localhost src]# tar xf apr-util-1.6.1.tar.gz -C /usr/local
[root@localhost src]# tar xf httpd-2.4.54.tar.gz -C /usr/local/
[root@localhost src]# ls /usr/local/
apr-1.7.0       bin  games         include  lib64    sbin   src
apr-util-1.6.1  etc  httpd-2.4.54  lib      libexec  share

编译三部曲

[root@localhost src]# cd /usr/local/apr-1.7.0/
//将$RM "$cfgfile"注释掉或者删除
[root@localhost apr-1.7.0]# vim configure
    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
   # $RM "$cfgfile"

[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
Platform: x86_64-pc-linux-gnu

[root@localhost apr-1.7.0]# make && make install
make[1]: Entering directory '/usr/local/apr-1.7.0'
/bin/sh /usr/local/apr-1.7.0/libtool --silent --mode=compile gcc -g -O2 -pthread   -DHAVE_CONFIG_H  -DLINUX -D_REENTRANT -D_GNU_SOURCE   -I./include -I/usr/local/apr-1.7.0/include/arch/unix -I./include/arch/unix -I/usr/local/apr-1.7.0/include/arch/unix -I/usr/local/apr-1.7.0/include -I/usr/local/apr-1.7.0/include/private -I/usr/local/apr-1.7.0/include/private  -o encoding/apr_encode.lo -c encoding/apr_encode.c && touch encoding/apr_encode.lo
/usr/local/apr-1.7.0/build/mkdir.sh tools
......
    /usr/bin/install -c -m 644 /usr/local/apr-1.7.0/build/${f} /usr/local/apr/build-1; \
done
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config

apr-util编译三部曲

[root@localhost apr-1.7.0]# cd /usr/local/apr-util-1.6.1/
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
.....
config.status: creating include/apu_want.h
config.status: creating test/Makefile
config.status: creating include/private/apu_config.h
config.status: executing default commands

[root@localhost apr-util-1.6.1]# make && make install
make[1]: Entering directory '/usr/local/apr-util-1.6.1'
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread   -DHAVE_CONFIG_H  -DLINUX -D_REENTRANT -D_GNU_SOURCE   -I/usr/local/apr-util-1.6.1/include -I/usr/local/apr-util-1.6.1/include/private  -I/usr/local/apr/include/apr-1    -o buckets/apr_brigade.lo -c buckets/apr_brigade.c && touch buckets/apr_brigade.lo
......
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config

编译三部曲httpd

[root@localhost apr-util-1.6.1]# cd /usr/local/httpd-2.4.54/
[root@localhost 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
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
.....
configure: summary of build options:

    Server Version: 2.4.54
    Install prefix: /usr/local/apache
    C compiler:     gcc
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E
    
[root@localhost httpd-2.4.54]# make && make install
Making all in srclib
make[1]: Entering directory '/usr/local/httpd-2.4.54/srclib'
make[1]: Leaving directory '/usr/local/httpd-2.4.54/srclib'
Making all in os
make[1]: Entering directory '/usr/local/httpd-2.4.54/os'
Making all in unix
make[2]: Entering directory '/usr/local/httpd-2.4.54/os/unix'
make[3]: Entering directory '/usr/local/httpd-2.4.54/os/unix'
.................
Installing man pages and online manual
mkdir /usr/local/apache/man
mkdir /usr/local/apache/man/man1
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: Leaving directory '/usr/local/httpd-2.4.54'

//设置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh 
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost local]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/local/apache/man

启动apache

取消Servername前面的注释
[root@localhost local]# vim /etc/httpd24/httpd.conf
ServerName www.example.com:80
[root@localhost local]# apachectl start
[root@localhost local]# 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                  *:80                  *:*              
LISTEN  0       128               [::]:22               [::]:*  
将httpd服务加入systemd  
root@localhost httpd-2.4.54]# vim /usr/lib/systemd/system/apache.service
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl
ExecStop=/usr/local/apache/bin/apachectl  stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl start apache.service 
[root@localhost ~]# systemctl enable apache.service 

安装mysql

[root@localhost ~]# groupadd -r -g 306 mysql
[root@localhost ~]# useradd -rMs /sbin/nologin -g 306 -u 306 mysql
[root@localhost ~]# cd /usr/src/

[root@localhost ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz

[root@localhost local]# tar xf  mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz -C /usr/local
[root@localhost src]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.7.39-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 Aug  2 23:28 /usr/local/mysql -> mysql-5.7.39-linux-glibc2.12-x86_64/
设置环境变量
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh 
[root@localhost local]# ln -s /usr/local/mysql/include/ /usr/include/mysql/
[root@localhost local]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost local]# cat /etc/ld.so.conf.d/mysql.conf 
/usr/local/mysql/lib
[root@localhost local]# ldconfig 
[root@localhost local]# vim /etc/man_db.conf 
MANDATORY_MANPATH                       /usr/local/mysql/man
建立存放目录
[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 Aug  2 23:34 data
初始化
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2022-08-02T15:37:36.145176Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-02T15:37:36.317700Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-02T15:37:36.348292Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-02T15:37:36.410237Z 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: 08aab86a-1279-11ed-9071-000c291857bd.
2022-08-02T15:37:36.410895Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-08-02T15:37:36.637865Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T15:37:36.637879Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T15:37:36.638290Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-02T15:37:36.664064Z 1 [Note] A temporary password is generated for root@localhost: Njutr7qPgk?8
将密码保存
[root@localhost mysql]# echo 'Njutr7qPgk?8' > pass
卸载自带的mariadb
[root@localhost local]# rpm -qa |grep mariadb
[root@localhost local]# dnf -y remove mariadb*

生成配置文件

[root@localhost etc]# 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 etc]# cd /usr/local/mysql
[root@localhost mysql]# ls
bin  data  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost mysql]# cd support-files/
[root@localhost support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
//找到basedir添加内容
[root@localhost support-files]# vim /etc/init.d/mysqld
basedir=/usr/local/mysqld
datadir=/opt/data
[root@localhost support-files]# chmod +x /etc/init.d/mysqld
启动mysql
[root@localhost support-files]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 
使用临时密码进入mysql
[root@localhost ~]# 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

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> 
设置新密码
mysql> set password = password('liuyang123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye
[root@localhost ~]# 

安装php

下载php安装包

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://www.php.net/distributions/php-8.1.11.tar.gz

解压

[root@localhost src]# tar xf php-8.1.11.tar.gz -C /usr/local/
[root@localhost local]# cd /usr/local/php-8.1.11/

编译安装

[root@localhost php-8.1.11]# ./configure --prefix=/usr/local/php  --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-posix


[root@localhost php-7.4.30]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
/bin/sh /usr/src/php-7.4.30/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/ -I/usr/src/php-7.4.30/ext/opcache/ -DPHP_ATOM_INC -I/usr/src/php-7.4.30/include -I/usr/src/php-7.4.30/main -I/usr/src/php-7.4.30 -I/usr/src/php-7.4.30/ext/date/lib -I/usr/include/libxml2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/src/php-7.4.30/ext/mbstring/libmbfl -I/usr/src/php-7.4.30/ext/mbstring/libmbfl/mbfl -I/usr/src/php-7.4.30/TSRM -I/usr/src/php-7.4.30/Zend    -I/usr/include -g -O2 -fvisibility=hidden -Wall -Wno-strict-aliasing -DZEND_SIGNALS    -c /usr/src/php-7.4.30/ext/opcache/ZendAccelerator.c -o ext/opcache/ZendAccelerator.lo 
/bin/sh /usr/src/php-7.4.30/libtool --silent --preserve-dup-deps --mode=compi
.......
pharcommand.inc
invertedregexiterator.inc
directorytreeiterator.inc
directorygraphiterator.inc
phar.inc

Build complete.
Don't forget to run 'make test'.
[root@localhost php-7.4.30]# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/
Installing PHP CLI binary:        /usr/local/php/bin/
Installing PHP CLI man page:      /usr/local/php/php/man/man1/
Installing PHP FPM binary:        /usr/local/php/sbin/
Installing PHP FPM defconfig:     /usr/local/php/etc/
.....
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/src/php-7.4.30/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin/phar.phar
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/

安装后配置

[root@localhost php]# echo 'export PATH=/usr/local/php/bin:$PATH' > /etc/profile.d/php.sh
[root@localhost php]# source /etc/profile.d/php.sh 
[root@localhost php-7.4.30]# which php
/usr/local/php/bin/php
[root@localhost php-7.4.30]# php -v
PHP 7.4.30 (cli) (built: Aug  3 2022 02:30:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
[root@localhost php]# vim /etc/ld.so.conf.d/php.conf
[root@localhost php]# cat /etc/ld.so.conf.d/php.conf
/usr/local/php/lib
[root@localhost php]# ln -s /usr/local/php/include/ /usr/include/php
//配置php-fpm
[root@localhost php-8.1.11]# cd /usr/local/php
[root@localhost php]# cp etc/php-fpm.conf.default etc/php-fpm.conf 
[root@localhost php]# cp etc/php-fpm.d/www.conf.default etc/php-fpm.d/www.conf
[root@localhost php]#  cp /lib/systemd/system/sshd.service /lib/systemd/system/php.service
[root@localhost system]# vim /lib/systemd/system/php.service
[Unit]
Description=php server daemon
After=network.target sshd-keygen.target
Wants=sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=ps -ef |grep php |grep -v grep|awk '{print$2}'|xargs kill -9
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost php]#  systemctl daemon-reload 
[root@localhost ~]# systemctl start php.service 
[root@localhost ~]# systemctl enable php.service 

查看服务状态

[root@localhost ~]# systemctl  status php.service
 php.service - php server daemon
   Loaded: loaded (/usr/lib/systemd/system/php.service; enabled; vendor pres>
   Active: active (running) since Wed 2022-08-03 02:46:26 CST; 48s ago
 Main PID: 247521 (php-fpm)
    Tasks: 3 (limit: 4743)
   Memory: 25.5M
   CGroup: /system.slice/php.service
           ├─247521 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
           ├─247522 php-fpm: pool www
           └─247523 php-fpm: pool www

Aug 03 02:46:26 localhost.localdomain systemd[1]: Starting php server daemon>
Aug 03 02:46:26 localhost.localdomain systemd[1]: Started php server daemon.

查看端口信息

[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           127.0.0.1:9000          0.0.0.0:*              
LISTEN  0       128                   *:80                  *:*              
LISTEN  0       128                [::]:22               [::]:*              
LISTEN  0       80                    *:3306                *:* 

配置apache虚拟主机

启动代理模块
在apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩展,因此,这两个模块都要加载,编辑httpd.conf文件,取消以下两行内容的注释:

[root@localhost ly]# vim /etc/httpd24/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

配置虚拟主机
创建虚拟主机的目录并生成php测试页面

[root@localhost ~]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# 
[root@localhost htdocs]# mkdir ./ly
[root@localhost htdocs]# cd ly/

[root@localhost ly]# cat index.php 
<?php
 phpinfo();
?>
[root@localhost htdocs]# chown -R apache.apache /usr/local/apache/htdocs/

配置虚拟主机

[root@localhost ly]# vim /etc/httpd24/extra/httpd-vhosts.conf 

<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/ly"
    ServerName ly.example.com
    ErrorLog "logs/ly.example.com-error_log"
    CustomLog "logs/ly.example.com-access_log" common
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/ly/$1
    <Directory "/usr/local/apache/htdocs/ly">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>
[root@localhost ly]#  vim /etc/httpd24/httpd.conf
Include /etc/httpd24/extra/httpd-vhosts.conf     //将此行注释取消
AddType application/x-httpd-php .php             //添加此行
AddType application/x-httpd-php-source .phps     //添加此行
//在'DirectoryIndex index.html'后面添加index.php
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

重启httpd服务

[root@localhost ly]# systemctl  restart apache.service
[root@localhost htdocs]# 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           127.0.0.1:9000          0.0.0.0:*              
LISTEN  0       128                   *:80                  *:*              
LISTEN  0       128                [::]:22               [::]:*   

测试

//在物理机C:\Windows\System32\drivers\etc\hosts文件下添加域名映射
192.168.34.130 ly.example.com

在浏览器上验证

posted @   Tqing  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示