lamp构建
1.源码安装https
在apache官网上下载好源码包,或者wget 下载 并解压
[root@192 ~]# wget https://dlcdn.apache.org/httpd/httpd-2.4.54.tar.gz
--2022-07-21 21:18:39-- https://dlcdn.apache.org/httpd/httpd-2.4.54.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9743277 (9.3M) [application/x-gzip]
Saving to: 'httpd-2.4.54.tar.gz'
httpd-2.4.54.tar.gz 100%[=================================================================================================>] 9.29M 12.2KB/s in 16m 26s
2022-07-21 21:35:09 (9.65 KB/s) - 'httpd-2.4.54.tar.gz' saved [9743277/9743277]
[root@192 ~]# ls
anaconda-ks.cfg httpd-2.4.54.tar.gz
[root@192 ~]# tar xf httpd-2.4.54.tar.gz
[root@192 ~]# mv httpd-2.4.54 /usr/src/
[root@192 ~]# cd /usr/src/
[root@192 src]# ls
debug httpd-2.4.54 kernels
[root@192 src]# groupadd -r apache
安装开发者工具
[root@192 src]# yum groups mark install "Development Tools"
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:02:40 ago on Thu Jul 21 21:35:38 2022.
Dependencies resolved.
========================================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================================
Installing Groups:
Development Tools
Transaction Summary
========================================================================================================================================================================================
Is this ok [y/N]: y
Complete!
安装apache所需依赖包
[root@192 src]# yum -y install openssl-devel pcre-devel expat-devel libtool epel-release
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:03:55 ago on Thu Jul 21 21:35:38 2022.
Dependencies resolved.
========================================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================================
Installing:
expat-devel x86_64 2.2.5-4.el8 base 55 k
libtool x86_64 2.4.6-25.el8 AppStream 709 k
.....
perl-constant-1.33-396.el8.noarch perl-interpreter-4:5.26.3-420.el8.x86_64 perl-libnet-3.11-3.el8.noarch
perl-libs-4:5.26.3-420.el8.x86_64 perl-macros-4:5.26.3-420.el8.x86_64 perl-parent-1:0.237-1.el8.noarch
perl-podlators-4.11-1.el8.noarch perl-threads-1:2.21-2.el8.x86_64 perl-threads-shared-1.58-2.el8.x86_64
zlib-devel-1.2.11-17.el8.x86_64
Complete!
下载apr和apr-util源码包(必须在1.4版本以上)
[root@192 src]# wget https://downloads.apache.org/apr/apr-1.6.5.tar.gz
--2022-07-21 21:48:08-- https://downloads.apache.org/apr/apr-1.6.5.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f9:3a:2c57::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1073556 (1.0M) [application/x-gzip]
Saving to: 'apr-1.6.5.tar.gz'
apr-1.6.5.tar.gz 100%[=================================================================================================>] 1.02M 23.1KB/s in 54s
2022-07-21 21:49:04 (19.4 KB/s) - 'apr-1.6.5.tar.gz' saved [1073556/1073556]
[root@192 src]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
--2022-07-21 21:49:16-- https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f9:3a:2c57::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 554301 (541K) [application/x-gzip]
Saving to: 'apr-util-1.6.1.tar.gz'
apr-util-1.6.1.tar.gz 100%[=================================================================================================>] 541.31K 12.9KB/s in 45s
2022-07-21 21:50:04 (11.9 KB/s) - 'apr-util-1.6.1.tar.gz' saved [554301/554301]
[root@192 src]# tar xf apr-1.6.5.tar.gz
[root@192 src]# tar xf apr-util-1.6.1.tar.gz
[root@192 apr-1.6.5]# vim configure
cfgfile="${ofile}T"
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
# $RM "$cfgfile" //将此行加上注释,或者删除此行
[root@192 apr-1.6.5]# cat configure | grep '# $RM '
# $RM "$cfgfile"
[root@192 apr-1.6.5]# ./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
。。。
config.status: creating include/arch/unix/apr_private.h
config.status: executing libtool commands
rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands
[root@192 apr-1.6.5]# echo $?
0
[root@192 apr-1.6.5]# make && make install
make[1]: Entering directory '/usr/src/apr-1.6.5'
/usr/src/apr-1.6.5/build/mkdir.sh tools
/bin/sh /usr/src/apr-1.6.5/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I./include -I/usr/src/apr-1.6.5/include/arch/uni
[root@192 apr-util-1.6.1]# make && make install
make[1]: Entering directory '/usr/src/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/src/apr-util-1.6.1/include -I/usr/src/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
/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
[root@192 apr-util-1.6.1]# echo $?
0
源码安装httpd
[root@192 apr-util-1.6.1]# cd /usr/src/httpd-2.4.54/
[root@192 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
...
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@192 httpd-2.4.54]# echo $?
0
[root@192 httpd-2.4.54]# make && make install
Making all in srclib
make[1]: Entering directory '/usr/src/httpd-2.4.54/srclib'
make[1]: Leaving dir
....
mkdir /usr/local/apache/manual
make[1]: Leaving directory '/usr/src/httpd-2.4.54'
[root@192 httpd-2.4.54]# echo $?
0
结尾工作配置环境变量和文件
[root@192 ~]# echo 'export PATH=/usr/local/httpd/bin:$PATH' > /etc/profile.d/apache.sh
[root@192 ~]# source /etc/profile.d/apache.sh
[root@192 ~]# which httpd
/usr/local/apache/bin/httpd
[root@192 ~]# ln -s /usr/local/httpd/include/ /usr/include/apache
[root@192 ~]# ll /usr/include/ |grep apache
lrwxrwxrwx. 1 root root 26 Jul 21 22:37 apache -> /usr/local/apache/include/
[root@192 ~]# vi /etc/man_db.conf
# every automatically generated MANPATH includes these fields
#
#MANDATORY_MANPATH /usr/src/pvm3/man
#
MANDATORY_MANPATH /usr/local/apache/man //添加这一行
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
[root@192 ~]# httpd
[root@192 ~]# ss -anltup | grep 80
tcp LISTEN 0 128 *:80 *:* users:(("httpd",pid=217055,fd=4),("httpd",pid=217054,fd=4),("httpd",pid=217053,fd=4),("httpd",pid=217052,fd=4),("httpd",pid=217051,fd=4),("httpd",pid=217050,fd=4))
2.二进制格式mysql安装
先关闭防火墙
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/sysconfig/selinux
官网上下载
[root@localhost ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
--2022-07-27 08:56:55-- https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
Resolving downloads.mysql.com (downloads.mysql.com)... 96.7.99.160, 2600:140e:6:9bc::2e31, 2600:140e:6:9a3::2e31
...
[root@localhost ~]# ls
anaconda-ks.cfg mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
bin games lib libexec sbin src
etc include lib64 mysql-5.7.37-linux-glibc2.12-x86_64 share
创建mysql用户和组
[root@localhost ~]# groupadd -r mysql
[root@localhost ~]# useradd -M -s /sbin/nologin -g mysql mysql
创建软连接
[root@localhost local]# ln -sv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.37-linux-glibc2.12-x86_64/'
[root@localhost 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 Jun 28 11:41 lib64
drwxr-xr-x. 2 root root 6 Jun 22 2021 libexec
lrwxrwxrwx. 1 root root 36 Jul 27 09:53 mysql -> mysql-5.7.37-linux-glibc2.12-x86
_64/
drwxr-xr-x. 9 root root 129 Jul 27 09:20 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 Jun 22 2021 sbin
drwxr-xr-x. 5 root root 49 Jun 28 11:41 share
drwxr-xr-x. 2 root root 6 Jun 22 2021 src
更改他们的用户和组
[root@localhost local]# chown -R mysql.mysql mysql*
[root@localhost 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 Jun 28 11:41 lib64
drwxr-xr-x. 2 root root 6 Jun 22 2021 libexec
lrwxrwxrwx. 1 mysql mysql 36 Jul 27 09:53 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 Jul 27 09:20 mysql-5.7.37-linux-glibc2.12-x86_64
添加环境变量 头文件 man文档
[root@192 local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@192 local]# . /etc/profile.d/mysql.sh
[root@192 local]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@192 profile.d]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@192 profile.d]# cd
[root@192 ~]# ll /usr/include/ | grep mysql
lrwxrwxrwx. 1 root root 25 Jul 27 18:30 mysql -> /usr/local/mysql/include/
[root@192 ~]# vim /etc/man_db.conf
[root@192 ~]# cat /etc/man_db.conf | grep mysql
MANDATORY_MANPATH /usr/local/mysql/man
建立数据存放目录
[root@192 ~]# mkdir /opt/data
[root@192 ~]# chown -R mysql.mysql /opt/data/
[root@192 ~]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jul 27 18:33 data
初始化数据库
[root@192 ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt
/data/
2022-07-27T10:34:34.587592Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is d
eprecated. Please use --explicit_defaults_for_timestamp server option (see documen
tation for more details).
...
2022-07-27T10:34:35.689625Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-27T10:34:35.852027Z 1 [Note] A temporary password is generated for root@localhost: Ok(,<wk?e6vs
将这个初始密码放入一个文件夹里,这个密码是随机的一定要记住
[root@192 ~]# echo 'Ok(,<wk?e6vs' >> lx
[root@192 ~]# cat lx
Ok(,<wk?e6vs
生成配置文件
[root@192 ~]# vim /etc/my.cnf
[root@192 ~]# 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@192 ~]# cd /lib/systemd/system
[root@192 system]# cp sshd.service mysql.service
[root@192 system]# vim mysql.service
[root@192 ~]# cat /lib/systemd/system/mysql.service
[Unit]
Description=mysql server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID
[root@192 ~]# systemctl restart mysql.service
[root@192 ~]# systemctl status mysql.service
● mysql.service - mysql server daemon
Loaded: loaded (/usr/lib/systemd/system/mysql.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2022-07-27 18:53:45 CST; 15s ago
Process: 392643 ExecStart=/usr/local/mysql/support-files/mysql.server start (code=exited, status=0/SUCCESS)
Main PID: 392656 (mysqld_safe)
Tasks: 28 (limit: 23503)
Memory: 175.8M
CGroup: /system.slice/mysql.service
├─392656 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
└─392856 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=192.168.132.135.err -->
Jul 27 18:53:44 192.168.132.135 systemd[1]: Starting mysql server daemon...
Jul 27 18:53:44 192.168.132.135 mysql.server[392643]: Starting MySQL.Logging to '/opt/data/192.168.132.135.err'.
Jul 27 18:53:45 192.168.132.135 mysql.server[392643]: SUCCESS!
Jul 27 18:53:45 192.168.132.135 systemd[1]: Started mysql server daemon.
[root@192 ~]# systemctl enable mysql.service
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /usr/lib/systemd/system/mysql.service.
查看启动的mysql
[root@192 ~]# ps -ef|grep mysql
root 392656 1 0 18:53 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql 392856 392656 0 18:53 ? 00:00:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=192.168.132.135.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root 472952 331142 0 19:37 pts/2 00:00:00 grep --color=auto mysql
[root@192 ~]# 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 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
3.源码安装php
如果不是在同一台虚拟机上安装请下载epel-release
安装依赖包
[root@localhost ~]# dnf -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
.....
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 libsqlite3x-devel
dnf -y install libzip-devel
下载包
[root@localhost ~]# wget https://www.php.net/distributions/php-7.4.30.tar.gz
.....
解压
[root@localhost ~]# tar -xf php-7.4.30.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache apr apr-util bin etc games include lib lib64 libexec mysql php-7.4.30 sbin share src
[root@localhost local]# cd php-7.4.30
编译
[root@localhost php-7.4.30]# ./configure --prefix=/usr/local/php7 --with-config-f
ile-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 --w
ith-jpeg --with-zlib-dir --with-freetype --with-gettext --enable-json --enable-mbs
tring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline
--enable-shmop --enable-simplexml --enable-sockets --with-zip --enable-mysqlnd-com
pression-support --with-pear --enable-pcntl --enable-posix
...
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
+--------------------------------------------------------------------+
| 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. |
+--------------------------------------------------------------------+
[root@localhost php-7.4.30]# make && make install
/bin/sh /usr/local/php-7.4.30/libtool --silent --preserve-dup-deps --mode=compile
cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/ -I/usr/local/php-7.4.30/ext/
opcache/ -DPHP_ATOM_INC -I/usr/local/php-7.4.30/include -I/usr/local/php-7.4.30/ma
...
编译安装后配置 环境变量
[root@localhost local]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost local]# source /etc/profile.d/php7.sh
[root@localhost local]# which php
/usr/local/php7/bin/php
//配置php-fpm
[root@localhost local]# cd php7
[root@localhost php7]# ls
bin etc include lib php sbin var
[root@localhost php7]# cd
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache apr-util etc include lib64 mysql php-7.4.30 share
apr bin games lib libexec php7 sbin src
[root@localhost local]# cd php-7.4.30/
[root@localhost php-7.4.30]# 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@localhost php-7.4.30]# cp php.ini-production /etc/php.ini
[root@localhost php-7.4.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.4.30]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-7.4.30]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-7.4.30]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
开机
[root@localhost php-fpm.d]# service php-fpm start
Starting php-fpm done
[root@localhost php-fpm.d]# ss -antl
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:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
设置开机自启
[root@localhost php-fpm.d]# chkconfig --add php-fpm
[root@localhost php-fpm.d]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost php-fpm.d]#