Apache安装
安装依赖
# 获取apr
[root@VM_0_15_centos ~]# cd /usr/local
//目录名可自行更改
[root@VM_0_15_centos local]# wget http://mirror.bit.edu.cn/apache/apr/apr-1.7.0.tar.gz
[root@VM_0_15_centos local]# tar -zxvf apr-1.7.0.tar.gz
[root@VM_0_15_centos local]# cd apr-1.7.0
[root@VM_0_15_centos apr-1.7.0]# ./configure --prefix=/usr/local/apr-1.7.0
#报错 rm: cannot remove 'libtoolT': No such file or directory
#解决 vi ./configure;将 $RM "$cfgfile" 所在行删除或#号注释
[root@VM_0_15_centos apr-1.7.0]# ./configure --prefix=/usr/local/apr-1.7.0
[root@VM_0_15_centos apr-1.7.0]# make && make install
# 获取apr-util
[root@VM_0_15_centos local]# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[root@VM_0_15_centos local]# tar -zxvf apr-util-1.6.1.tar.gz
[root@VM_0_15_centos local]# cd apr-util-1.6.1
[root@VM_0_15_centos apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util-1.6.1 --with-apr=/usr/local/apr-1.7.0/
#报错 /bin/rm: cannot remove `libtoolT': No such file or directory
添加 expat-devel依赖
[root@VM_0_15_centos apr-util-1.6.1]# yum install expat-devel
[root@VM_0_15_centos apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util-1.6.1 --with-apr=/opt/local/apr-1.7.0/
[root@VM_0_15_centos apr-util-1.6.1]# make && make install
# 获取apr-iconv
[root@VM_0_15_centos local]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-iconv-1.2.2.tar.gz
[root@VM_0_15_centos local]# tar -zxvf apr-iconv-1.2.2.tar.gz
[root@VM_0_15_centos local]# cd apr-iconv-1.2.2
[root@VM_0_15_centos apr-iconv-1.2.2]# ./configure --prefix=/usr/local/apr-iconv-1.2.2 --with-apr=/usr/local/apr-1.7.0/
[root@VM_0_15_centos apr-iconv-1.2.2]# make && make install
# 获取apr-iconv
[root@VM_0_15_centos local]# wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
[root@VM_0_15_centos local]# tar -zxvf apcre-8.44.tar.gz
[root@VM_0_15_centos local]# cd pcre-8.44
[root@VM_0_15_centos pcre-8.44]# ./configure --prefix=/usr/local/pcre-8.44
[root@VM_0_15_centos pcre-8.44]# make && make install
开始安装apache
[root@VM_0_15_centos local]# wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.43.tar.gz
[root@VM_0_15_centos local]# tar -zxvf httpd-2.4.43.tar.gz
[root@VM_0_15_centos local]# cd httpd-2.4.43
[root@VM_0_15_centos httpd-2.4.43]# ./configure --prefix=/usr/local/httpd-2.4.43/ --with-apr=/usr/local/apr-1.7.0/bin --with-apr-util=/usr/local/apr-util-1.6.1/bin --with-pcre=/usr/local/pcre-8.44 --enable-so
[root@VM_0_15_centos httpd-2.4.43]# make && make install
#查看是否安装
[root@VM_0_15_centos httpd-2.4.43]# locate httpd | grep bin
# 添加到服务
[root@VM_0_15_centos httpd-2.4.43]# cp /usr/local/httpd-2.4.43/bin/apachectl /etc/rc.d/init.d/httpd
# 添加到守护进程
[root@VM_0_15_centos httpd-2.4.43]# chkconfig --add httpd
报错:service httpd does not support chkconfig
解决方法:vi /etc/rc.d/init.d/httpd 在 #!/bin/sh下添加如下代码
# Startup script for the Apache Web Server
#
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web server.
#
备注:#号必须有 其中:2345是设为要启动的运行级别,10是启动优先级,90是杀死进程的优先级,谁优先谁先挂的意思。
service httpd start //启动apache
直接浏览器IP访问
PHP安装
yum安装PHP 版本较低你,不建议使用
安装依赖
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers sqlite-devel
[root@VM_0_15_centos local]# wget https://www.php.net/distributions/php-7.4.6.tar.gz
[root@VM_0_15_centos local]# tar -zxvf php-7.4.6.tar.gz
//重命名文件
[root@VM_0_15_centos local]# mv php-7.4.6 php
[root@VM_0_15_centos local]# cd php
编译安装
//检查当前的环境是否满足要安装软件的依赖关系
[root@VM_0_15_centos php]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/bin/apxs --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-jpeg=/usr/local/jpeg --enable-fpm --with-curl --enable-mbstring --with-openssl --enable-gd --enable-static --enable-sockets --enable-inline-optimization --with-zlib --disable-ipv6
//编译安装,会生成bin、etc等文件
[root@VM_0_15_centos php]# make && make install
#查看是否安装成功
[root@VM_0_15_centos php]# /usr/local/php/bin/php -m
注:
--prefix=安装目录
--with-使用包名称[=包目录] 是指定依赖的资源库的位置 --with-依赖包名称[=依赖包目录],如果是默认位置,路径就可以留空。。
--enable-需要激活的功能 是启用软件源码包自带 --enable-包名[=arg],但是默认不启用的功能模块
--disable 禁用
报错:No package 'oniguruma' found
安装 oniguruma
yum -y install http://mirror.centos.org/centos-7/7.7.1908/cloud/x86_64/openstack-queens/oniguruma-6.7.0-1.el7.x86_64.rpm
安装 oniguruma-devel
yum -y install http://mirror.centos.org/centos-7/7.7.1908/cloud/x86_64/openstack-queens/oniguruma-devel-6.7.0-1.el7.x86_64.rpm
如果报其它错,自行网上查找答案
php与apache的绑定
vi /usr/local/httpd/conf/httpd.conf
添加如下代码
第一处:
LoadModule php7_module modules/libphp7.so
第二处:
添加:ServerName localhost:80
第三处:
SetHandler application/x-httpd-php
重启apache:service httpd restart
php-fpm配置 (可先忽略)
[root@VM_0_15_centos php]# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@VM_0_15_centos php]# chmod +x /etc/init.d/php-fpm
[root@VM_0_15_centos php]# cp ./etc/php-fpm.d/www.conf.default ./etc/php-fpm.d/www.conf
//添加php.ini配置文件 可以由php.ini-production或者php.ini-production生成
[root@VM_0_15_centos php]#cp php.ini-production /usr/local/php/php.ini
[root@VM_0_15_centos php]# /usr/local/php/bin/php -v
PHP 7.4.6 (cli) (built: May 15 2020 11:15:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
启动php-fpm
[root@VM_0_15_centos php]# service php-fpm start
mysql安装
直接下载完整版的mysql,阉割版的会很头大(阉割版的需要装cmake,还需要gcc5.3版本以上支持,gcc坑有点深,初学者不建议尝试(make大概要花几十分钟,重点是花了几十分钟还报错))
安装依赖
yum -y install libnuma numactl
[root@VM_0_15_centos local]# wget -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
#注:下载很慢,建议先用迅雷下载,然后导到服务器
# 解压
[root@VM_0_15_centos local]# tar -xvjf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
# 重命名文件夹
[root@VM_0_15_centos local]# mv mysql-8.0.20 mysql
# 创建用户
[root@VM_0_15_centos local]# useradd -r mysql
# mysql文件夹赋权给用户
[root@VM_0_15_centos local]# chown mysql:mysql -R /usr/local/mysql
#chown mysql:mysql -R /usr/local/mysql写成 chown -R mysql . 也可以
[root@VM_0_15_centos local]# cd mysql
配置mysql配置文件夹 vi /etc/my.cnf
[mysql]
default-character-set=utf8
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/tmp/mysql.sock
character-set-server=utf8
default-storage-engine=InnoDB
[client]
port=3306
default-character-set=utf8
socket=/usr/local/mysql/tmp/mysql.sock
初始化数据库
[root@VM_0_15_centos mysql]# bin/mysqld --initialize --user=mysql
#如果my.cnf配置文件里未写basedir和datadir,可用下面方式初始化,写了就不必用下面方式初始化,不然会报参数过多的错误
/** bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data */
安装成功后会给账号和密码
建立MySQL服务
[root@VM_0_15_centos mysql]# cp cp -a ./support-files/mysql.server /etc/init.d/mysql
[root@VM_0_15_centos mysql]# chmod +x /etc/init.d/mysql
增加系统服务
[root@VM_0_15_centos mysql]# chkconfig --add mysqld
检查服务是否生效
[root@VM_0_15_centos mysql]# chkconfig --list mysqld
配置全局环境变量
[root@VM_0_15_centos mysql]# vi /etc/profile
PATH后加上:/usr/local/mysql/bin:/usr/local/mysql/lib
刷新环境变量
source /etc/profile
启动mysql服务
service mysql start
[root@VM_0_15_centos mysql]# mysql -u root -p
Enter password:
/**
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.20
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
剩下就是防火墙开启3306端口,以及设置远程ip访问服务器数据库,这里不做介绍