首先搭建一个LAMP网站我们要用到apche,mysql,php这3大服务。
第一步编译安装httpd
[root@mingzi ~]# yum groups mark install "Development Tools"
[root@mingzi ~]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz
[root@mingzi ~]# useradd -r -M -s /sbin/nologin apache
[root@mingzi ~]# id apache
uid=995(apache) gid=992(apache) groups=992(apache)
//下载需要编译安装的3个包
//在创建一个apache系统用户
[root@mingzi ~]# tar xf apr-1.7.0.tar.gz
[root@mingzi ~]# tar xf apr-util-1.6.1.tar.gz
[root@mingzi ~]# tar xf httpd-2.4.53.tar.gz
[root@mingzi ~]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz
apr-1.7.0 apr-util-1.6.1 httpd-2.4.53
//一次解压
[root@mingzi apr-1.7.0]# vim configure
cfgfile="${ofile}T"
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
# $RM "$cfgfile" //将此行加上注释,或者删除此行
[root@mingzi apr-1.7.0]# dnf -y install gcc gcc-c++
[root@mingzi ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
//安装他的依赖包
[root@mingzi apr-1.7.0]# ./configure --prefix=/usr/local/apr
//编译安装
make make install
//安装
[root@mingzi apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --withapr=/usr/local/apr
//编译
make
make install
//安装
[root@mingzi httpd-2.4.53]# ./configure --prefix=/usr/local/apache --enable-so --
enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --withapr=/usr/local/apr
--with-apr-util=/usr/local/apr-util/ --enable-modules=most --
enable-mpms-shared=all --with-mpm=prefork
//编译
[root@mingzi ~]# ls /usr/local/
apache apr-util etc include lib64 sbin src
apr bin games lib libexec share
[root@mingzi ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' >
/etc/profile.d/apache.sh
//设置环境变量
[root@mingzi ~]# source /etc/profile.d/apache.sh
[root@mingzi ~]# which httpd
/usr/local/apache/bin/httpd
//刷新读取一下
[root@mingzi ~]# ln -s /usr/local/apache/include /usr/include/apache
//设置头文件
[root@mingzi apache]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/apache/man
//设置man文档
[root@mingzi apache]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@mingzi apache]# setenforce 0
[root@mingzi apache]# getenforce
Permissive
[root@mingzi apache]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
//关闭防火墙
[root@mingzi ~]# apachectl start
[root@mingzi ~]# ss -ant
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
ESTAB 0 0 192.168.80.3:22 192.168.80.1:56818
ESTAB 0 52 192.168.80.3:22 192.168.80.1:55451
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
//启动
二进制安装mysql
yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
先安装他所需要用到的依赖包
MySQL :: Download MySQL Community Server (Archived Versions)
下载他的安装包
[root@mingzi src]# useradd -r -M -s /sbin/nologin mysql
[root@mingzi src]# id mysql
uid=995(mysql) gid=992(mysql) groups=992(mysql)
//创建一个不允许登录的系统用户
[root@mingzi src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
解压道这个目录
[root@mingzi local]# mv mysql-5.7.37-linux-glibc2.12-x86_64 mysql
[root@mingzi local]# ls
bin etc games include lib lib64 libexec mysql sbin share src
[root@mingzi local]# chown -R mysql.mysql mysql
[root@mingzi local]# ll
total 0
drwxr-xr-x. 2 root root 6 Jun 22 2021 bin
drwxr-xr-x. 2 root root 6 Jun 22 2021 etc
drwxr-xr-x. 2 root root 6 Jun 22 2021 games
drwxr-xr-x. 2 root root 6 Jun 22 2021 include
drwxr-xr-x. 2 root root 6 Jun 22 2021 lib
drwxr-xr-x. 3 root root 17 May 23 13:11 lib64
drwxr-xr-x. 2 root root 6 Jun 22 2021 libexec
drwxr-xr-x. 9 mysql mysql 129 Jun 28 13:38 mysql
drwxr-xr-x. 2 root root 6 Jun 22 2021 sbin
drwxr-xr-x. 5 root root 49 May 23 13:11 share
drwxr-xr-x. 2 root root 6 Jun 22 2021 src
//改掉属组
[root@mingzi local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >/etc/profile.d/mysql.sh
[root@mingzi local]# source /etc/profile.d/mysql.sh
//设置他的环境变量
[root@mingzi mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
//做一个映射链接
[root@mingzi mysql]# vi /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
~
~
//配置lib库
[root@mingzi mysql]# ldconfig
[root@mingzi mysql]# vi /etc/man_db.conf
#MANDATORY_MANPATH /usr/src/pvm3/man
#
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/mysql/man
//修改man文档
[root@mingzi ~]# mkdir -p /opt/data
[root@mingzi ~]# chown -R mysql.mysql /opt/data
[root@mingzi ~]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jun 28 13:53 data
//建立数据存放目录
[root@mingzi ~]# mysqld --initialize --user mysql --datadir /opt/data
//初始化数据库
MihqWpsps9>E
//过滤出他的临时密码
[root@localhost ~]# 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@mingzi support-files]# cp mysql.server mysqld
[root@mingzi support-files]# chown -R mysql.mysql mysqld
[root@mingzi support-files]# ll
total 36
-rw-r--r--. 1 mysql mysql 773 Nov 30 2021 magic
-rwxr-xr-x. 1 mysql mysql 10576 Jun 28 14:24 mysqld
-rwxr-xr-x. 1 mysql mysql 1061 Nov 30 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql 894 Nov 30 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 Nov 30 2021 mysql.server
复制一个改掉属主
[root@mingzi support-files]# vi mysqld
basedir=/usr/local/mysql
datadir=/opt/data
//告诉他安装的路径
[root@mingzi support-files]# /usr/local/mysql/support-files/mysqld start
Starting MySQL.Logging to '/opt/data/mingzi.err'.
SUCCESS!
//用配置脚本启动
[root@mingzi support-files]# ss -ant
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
ESTAB 0 52 192.168.80.20:22 192.168.80.1:52734
ESTAB 0 0 192.168.80.20:22 192.168.80.1:53479
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
[root@mingzi support-files]# ps -ef|grep mysql
root 1914 1 0 14:28 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql 2102 1914 0 14:28 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mingzi.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root 2138 1584 0 14:29 pts/0 00:00:00 grep --color=auto mysql
[root@mingzi ~]# dnf provides libncurses.so.5
Last metadata expiration check: 0:53:57 ago on Tue 28 Jun 2022 01:38:41 PM CST.
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
Repo : base
Matched from:
Provide : libncurses.so.5
//修改密码之前过滤他的依赖包安装上
[root@mingzi ~]# mysql -uroot -p'MihqWpsps9>E'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.37
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
//修改密码
安装php
https://www.php.net/distributions/php-7.4.29.tar.xz php安装包
[root@mingzi ~]# ls
anaconda-ks.cfg mysql-community-client-5.7.37-1.el7.x86_64.rpm
apr-1.7.0 mysql-community-common-5.7.37-1.el7.x86_64.rpm
apr-1.7.0.tar.gz mysql-community-devel-5.7.37-1.el7.x86_64.rpm
apr-util-1.6.1 mysql-community-libs-5.7.37-1.el7.x86_64.rpm
apr-util-1.6.1.tar.gz mysql-community-server-5.7.37-1.el7.x86_64.rpm
httpd-2.4.53 php-7.4.29.tar.xz
httpd-2.4.53.tar.gz
[root@mingzi ~]# tar xf php-7.4.29.tar.xz
[root@mingzi ~]# ls
anaconda-ks.cfg mysql-community-client-5.7.37-1.el7.x86_64.rpm
apr-1.7.0 mysql-community-common-5.7.37-1.el7.x86_64.rpm
apr-1.7.0.tar.gz mysql-community-devel-5.7.37-1.el7.x86_64.rpm
apr-util-1.6.1 mysql-community-libs-5.7.37-1.el7.x86_64.rpm
apr-util-1.6.1.tar.gz mysql-community-server-5.7.37-1.el7.x86_64.rpm
httpd-2.4.53 php-7.4.29
httpd-2.4.53.tar.gz php-7.4.29.tar.xz
//解压
安装它需要的依赖包
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
过滤他需要安装的包
[root@mingzi php-7.4.29]# dnf list all|grep mysql|grep php
php-mysqlnd.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream
[root@mingzi php-7.4.29]# yum -y install php-mysqlnd
[root@mingzi php-7.4.29]# dnf -y install sqlite-devel
[root@mingzi php-7.4.29]# 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
[root@mingzi php-7.4.29]# dnf -y install libzip-devel
依赖包全部安装好了接下来编译安装php
[root@mingzi 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
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
make makeinstall安装好之后设置他的环境变量和头文件
[root@mingzi ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@mingzi ~]# source /etc/profile.d/php7.sh
启用代理模块
[root@mingzi conf]# vim httpd.conf
# Local access to the Apache HTTP Server Manual
LoadModule log_config_module modules/mod_log_config.so
#LoadModule log_debug_module modules/mod_log_debug.so
#LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
#LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
#LoadModule remoteip_module modules/mod_remoteip.so
LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
//找到这一行取消他的注释 fagi打开
创建一个测试网站的目录
[root@mingzi apache]# cd htdocs/
[root@mingzi htdocs]# ls
index.html
[root@mingzi htdocs]# mkdir test.com
[root@mingzi htdocs]# cd test.com/
[root@mingzi test.com]# ls
[root@mingzi test.com]# vim index.php
[root@mingzi test.com]# vim index.php
<?php
phpinfo();
?>
EOF
//打印php的信息
[root@mingzi apache]# vim conf/httpd.conf
[root@mingzi test.com]# cd ..
[root@mingzi htdocs]# ls
index.html test.com
SSLRandomSeed connect builtin
</IfModule>
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/test.com"
ServerName test.example.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test.com/$1
<Directory "/usr/local/apache/htdocs/test.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
-- INSERT --
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
//配置虚拟主机
配置php
[root@mingzi ~]# which php
/usr/local/php7/bin/php
[root@mingzi ~]# php -v
PHP 7.4.29 (cli) (built: Apr 21 2022 20:31:39) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
[root@mingzi php-7.4.29]# \cp php.ini-production /etc/php.ini
[root@mingzi php-7.4.29]# ls
appveyor configure.ac Makefile.fragments scripts
azure CONTRIBUTING.md Makefile.objects tests
azure-pipelines.yml docs modules travis
build ext NEWS TSRM
buildconf EXTENSIONS pear UPGRADING
buildconf.bat include php.ini-development UPGRADING.INTERNALS
CODING_STANDARDS.md libs php.ini-production win32
config.log libtool README.md Zend
config.nice LICENSE README.REDIST.BINS
config.status main run-tests.php
configure Makefile sapi
[root@mingzi php-7.4.29]# ls sapi/
apache2handler cgi cli embed fpm litespeed phpdbg
[root@mingzi php-7.4.29]# ls sapi/fpm/
config.m4 init.d.php-fpm.in php-fpm.8 php-fpm.service tests
CREDITS LICENSE php-fpm.8.in php-fpm.service.in www.conf
fpm Makefile.frag php-fpm.conf status.html www.conf.in
init.d.php-fpm php-fpm php-fpm.conf.in status.html.in
[root@mingzi php-7.4.29]# cp sapi/fpm/php-fpm /etc/init.d/php-fpm
[root@mingzi php-7.4.29]# ll /etc/init.d/php-fpm
-rwxr-xr-x 1 root root 54696280 Apr 21 21:00 /etc/init.d/php-fpm
//给他权限
root@mingzi php-7.4.29]# cd /usr/local/php7/
[root@mingzi php7]# cd etc/
[root@mingzi etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
[root@mingzi etc]# cp php-fpm.conf.default php-fpm.conf
[root@mingzi etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d
[root@mingzi etc]# cd php-fpm.d/
[root@mingzi php-fpm.d]# ls
www.conf.default
[root@mingzi php-fpm.d]# cp www.conf.default www.conf
[root@mingzi php-fpm.d]# ls
www.conf www.conf.default
查看是否有9000端口号
[root@mingzi php-fpm.d]# ls
www.conf.default
[root@mingzi php-fpm.d]# cp www.conf.default www.conf
[root@mingzi php-fpm.d]# ls
www.conf www.conf.default
[root@mingzi php-fpm.d]# pwd
/usr/local/php7/etc/php-fpm.d
[root@mingzi php-fpm.d]# vim www.conf
; Note: This value is mandatory.
listen = 127.0.0.1:9000
; Set listen(2) backlog.
接下来启动php
[root@mingzi ~]# /etc/init.d/php-fpm
[root@mingzi ~]# ss -ant
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
ESTAB 0 0 192.168.80.3:22 192.168.80.1:54624
ESTAB 0 0 192.168.80.3:22 192.168.80.1:55628
ESTAB 0 52 192.168.80.3:22 192.168.80.1:62761
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
//开启
//可以看到以下有3306 9000 80等端口号
用test.example.com访问