安装MySQL
初始化
软件包放在在例方便管理
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# ll
total 321036
-rw-r–r--. 1 root root 328740156 Nov 10 01:37 mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
解压源码包
[root@localhost src]# tar -zxf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
移动mysql文件的位置
[root@localhost src]# mv mysql-5.6.43-linux-glibc2.12-x86_64 /usr/local/mysql/
建立mysql用户,因为启动MySQL需要改用户
[root@localhost src]# useradd -s /sbin/nologin mysql
创建datadir,数据库文件会放到这里面,并更改权限,不更改后续操作会出现问题
[root@localhost src]# cd /usr/local/mysql/
[root@localhost mysql]# mkdir -p /data/mysql; chown -R mysql:mysql /data/mysql
[root@localhost mysql]# cd /data/mysql
[root@localhost mysql]# ls -la
total 110600
drwxr-xr-x. 5 mysql mysql 104 Nov 10 02:11 .
drwxr-xr-x. 3 root root 18 Nov 10 01:46 …
报错:缺少包perl-Module-Install而导致报错
[root@localhost mysql]# cd /usr/local/mysql/
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
![在这里插入图片描述]([root@localhost php-7.4.19]# cd /usr/local/php7/
[root@localhost php7]# ls
bin include lib php php.ini var
//–user表示定义数据库的以哪个用户的身份运
//–datadir表示定义数据库的安装目录
[root@localhost mysql]# yum install -y perl-Module-Install
执行完成后会出现两个OK,并且在/data/mysql 目录下会生成几个文件和目录,说明MySQL安装成功啦
[root@localhost src]# cd /usr/local/mysql/
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
配置MySQL
复制配置文件
[root@localhost mysql]# cd /usr/local/mysql/
[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y (是否覆盖)
打开配置文件,做一下配置
[root@localhost support-files]# vi /etc/my.cnf
[mysqld]
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
server_id = 25
socket = /tmp/mysql.sock
复制启动脚本文件并修改其属性
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod 777 /etc/init.d/mysqld
修改启动脚本,并把它加入系统服务项,并设定开机启动MySQL
[root@localhost mysql]# vi /etc/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysql
[root@localhost mysql]# chkconfig mysql on
[root@localhost mysql]# service mysqld start
Starting MySQL.Logging to ‘/data/mysql/localhost.localdomain.err’.
SUCCESS!
[root@localhost mysql]# ps aux | grep mysql
root 19482 0.0 0.0 11824 1624 pts/1 S 01:51 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid
mysql 19659 2.1 24.2 1302756 452908 pts/1 Sl 01:51 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root 19685 0.0 0.0 112812 968 pts/1 S+ 01:52 0:00 grep --color=auto mysql
[root@localhost mysql]# yum install -y net-tools
[root@localhost mysql]# netstat -ntpl | grep 3306
tcp6 0 0 :::3306 ::😗 LISTEN 19659/mysqld
详解:
安装Apache
① 安装apr
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# tar -zxf apr-1.6.5.tar.gz
[root@localhost src]# tar -zxf apr-util-1.6.1.tar.gz
[root@localhost src]# tar -zxf httpd-2.4.46.tar.gz
[root@localhost src]# cd apr-1.6.5/
[root@localhost apr-1.6.5]# ls
apr-config.in CMakeLists.txt libapr.mak poll
apr.dep config.layout libapr.rc random
apr.dsp configure LICENSE README
apr.dsw configure.in locks README.cmake
apr.mak docs Makefile.in shmem
apr.pc.in dso Makefile.win strings
apr.spec emacs-mode memory support
atomic encoding misc tables
build file_io mmap test
buildconf helpers network_io threadproc
build.conf include NOTICE time
build-outputs.mk libapr.dep NWGNUmakefile tools
CHANGES libapr.dsp passwd user
注意:(环境比较干净,缺少libtoolT)
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr
。。。
rm: cannot remove ‘libtoolT’: No such file or directory
config.status: executing default commands
解决:
[root@localhost apr-1.6.5]# yum install -y libtool*
再次编译:
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr
(可忽略)
②安装apr-util
[root@localhost apr-1.6.5]# cd …
[root@localhost src]# 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 && make install
[root@localhost apr-util-1.6.1]# yum install -y expat-devel
再次运行
[root@localhost apr-util-1.6.1]# make && make install(无报错)
[root@localhost apr-util-1.6.1]# echo $?
0
[root@localhost apr-util-1.6.1]# cd …
[root@localhost src]#
[root@localhost src]#
[root@localhost src]# ls /usr/local/
apr bin games lib libexec sbin src
apr-util etc include lib64 mysql share
③安装httpd
[root@localhost src]# cd httpd-2.4.46
//这里的反斜杠是脱义字符,加上它我们可以把一行命令写成多行
[root@localhost httpd-2.4.46]# ./configure \
> --prefix=/usr/local/apache2.4 \
> --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util \
> --enable-so \
> --enable-mods-shared=most
报错:
为避免make时候出现错误,提前安装库的文件。·
解决:
[root@localhost httpd-2.4.46]# yum install -y pcre-devel
再次运行:(0 表示没问题)
[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@localhost httpd-2.4.46]# echo $?
0
[root@localhost httpd-2.4.46]# make && make install
解决(成功)
[root@localhost httpd-2.4.46]# cd srclib/
[root@localhost srclib]# ls
apr apr-util Makefile Makefile.in
[root@localhost srclib]#
[root@localhost srclib]#
[root@localhost srclib]# cd …
[root@localhost httpd-2.4.46]#
[root@localhost httpd-2.4.46]# ls
ABOUT_APACHE config.log InstallBin.dsp os
acinclude.m4 config.nice LAYOUT README
Apache-apr2.dsw config.status libhttpd.dep README.cmake
Apache.dsw configure libhttpd.dsp README.platforms
apache_probes.d configure.in libhttpd.mak ROADMAP
ap.d docs LICENSE server
build emacs-style Makefile srclib
BuildAll.dsp httpd.dep Makefile.in support
BuildBin.dsp httpd.dsp Makefile.win test
buildconf httpd.mak modules VERSIONING
CHANGES httpd.spec modules.c
CMakeLists.txt include NOTICE
config.layout INSTALL NWGNUmakefile
[root@localhost httpd-2.4.46]# make clean
[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/apache2.4 --enable-so --with-pcre --with-included-apr --enable-modules=most --enable-mpms-share=all --with-mpm=prefork
[root@localhost httpd-2.4.46]# echo $?
0
[root@localhost httpd-2.4.46]# make && make install
[root@localhost httpd-2.4.46]# echo $?
0
[root@localhost src]# cd httpd-2.4.46
[root@localhost httpd-2.4.46]# cd /usr/local/
[root@localhost local]# du -sh apache2.4/
42M apache2.4/
[root@localhost local]# cd apache2.4/
查看加载的模块:带shared表示该模块为动态共享模块(独立存在的文件);static为静态模块(直接和主程序绑在一起)
[root@localhost apache2.4]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName’ directive globally to suppress this message
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_prefork_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
安装PHP
[root@localhost src]# tar -zxf php-7.4.19.tar.gz
[root@localhost src]# cd php-7.4.19
[root@localhost php-7.4.19]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
但会提示以下内容:
No package ‘libxml-2.0’ found
解决:
[root@localhost src]# yum install libxml2-devel bzip2 bzip2-devel libpng libpng-devel openssl openssl-devel freetype freetype-devel opel-release -y
也许还会报错把 --with-jpeg-dir(图片)删除
[root@localhost src]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
报错:
[root@localhost php-7.4.19]# yum install -y sqlite-devel
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
No package 'sqlite3' found
configure: error: Package requirements (oniguruma) were not met:
No package 'oniguruma' found
https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz
[root@localhost ~]# tar -zxf oniguruma-6.9.4.tar.gz
[root@localhost oniguruma-6.9.4]# cd oniguruma-6.9.4/
[root@localhost oniguruma-6.9.4]# ./autogen.sh
[root@localhost oniguruma-6.9.4]# ./configure --prefix=/usr --libdir=/lib64
//64位的系统一定要标识 --libdir=/lib64 否则还是不行
[root@localhost oniguruma-6.9.4]# make && make install
[root@localhost oniguruma-6.9.4]# echo $?
0
[root@localhost src]# cd php-7.4.19
[root@localhost php-7.4.19]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
[root@localhost php-7.4.19]# make && make install
[root@localhost php-7.4.19]# echo $?
0
[root@localhost php-7.4.19]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName’ directive globally to suppress this message
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_prefork_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
php7_module (shared)
[root@localhost php-7.4.19]# cd /usr/local/apache2.4/modules/
查看php的安装信息
最后备份配置文件
[root@localhost php-7.4.19]# cp php.ini-production /usr/local/php7/php.ini
[root@localhost php-7.4.19]# cd /usr/local/php7/
[root@localhost php7]# ls
bin include lib php php.ini
var
安装完成。