编译安装httpd
//准备工作
[root@xz ~]# yum groups mark install "Development Tools" //安装开发工具包
[root@xz ~]# useradd -r -M -s /sbin/nologin apache
//创建apache服务的用户和组
[root@xz ~]# id apache
uid=995(apache) gid=992(apache) groups=992(apache)
[root@xz ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
[root@xz ~]# yum - y install make
//安装依赖包
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
下载源码包并解压
[root@xz ~]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
[root@xz ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@xz ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@xz ~]# tar -xf apr-1.7.0.tar.gz
[root@xz ~]# tar -xf apr-util-1.6.1.tar.gz
[root@xz~]# tar -xf httpd-2.4.53.tar.gz
//安装apr
[root@xz ~]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# vim configure
# $RM "$cfgfile" //注释掉或者删除这一行
[root@xz apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@xz apr-1.7.0]# make
[root@xz apr-1.7.0]# make install
//安装apr-util
[root@xz ~]# cd apr-util-1.6.1/
[root@xz apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr //apr-util是apr的子包 所以需要指定指定主包的位置
[root@xz apr-1.7.0]# make
[root@xz apr-1.7.0]# make install
//安装httpd
[root@xz ~]# cd httpd-2.4.53/
[root@xz httpd-2.4.53]# ./configure --prefix=/usr/local/apache \
--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
[root@xz apr-1.7.0]# make
[root@xz apr-1.7.0]# make install
设置环境变量
[root@xz ~]# ls /usr/local/
apache apr-util etc include lib64 sbin src
apr bin games lib libexec share
[root@xz ~]# cd /usr/local/apache/
[root@xz apache]# ls //环境变量的目录
bin cgi-bin error icons logs manual
build conf htdocs include man modules
[root@xz ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@xz ~]# source /etc/profile.d/apache.sh
[root@xz ~]# which httpd
/usr/local/apache/bin/httpd
[root@xz ~]# which apachectl
/usr/local/apache/bin/apachectl
配置映射关系
[root@xz ~]# ls /usr/local/apache/ //有头文件include所以需要做链接
bin cgi-bin error icons logs manual
build conf htdocs include man modules
[root@xz ~]# ln -s /usr/local/apache/include /usr/include/apache
配置man文档
[root@xz ~]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/local/apache/man //添加这行
关闭防火墙
[root@xz ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
查看防火墙状态
[root@xz ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor pre>
Active: inactive (dead)
Docs: man:firewalld(1)
Apr 17 10:41:43 xz systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 17 10:41:45 xz systemd[1]: Started firewalld - dynamic firewall daemon.
Apr 17 10:41:46 xz firewalld[1065]: WARNING: AllowZoneDrifting is enabled. This is>
Apr 17 13:05:21 xz systemd[1]: Stopping firewalld - dynamic firewall daemon...
Apr 17 13:05:21 xz systemd[1]: firewalld.service: Succeeded.
Apr 17 13:05:21 xz systemd[1]: Stopped firewalld - dynamic firewall daemon.
lines 1-11/11 (END)
[root@xz ~]# setenforce 0
[root@xz ~]# getenforce
Permissive
[root@xz ~]# vim /etc/selinux/config
SELINUX=disabled //让它永久生效
[root@xz ~]# 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 [::]:22 [::]:*
[root@xz ~]# which apachectl
/usr/local/apache/bin/apachectl
[root@xz ~]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe09:8f36%ens160. Set the 'ServerName' directive globally to suppress this message
[root@xz ~]# 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 [::]:22 [::]:*
LISTEN 0 128 *:80 *:*
部署成功
使用systemctl命令设置httpd
使用源码包安装apache服务 默认是不能用systemctl的
任何源码安装的服务都适用
[root@xz ~]# cd /usr/lib/systemd/system
[root@xz system]# ls sshd.service
sshd.service
[root@xz system]# cp sshd.service httpd.service //复制一份这个文件改名为httpd.service
[root@xz system]# vim httpd.service //编辑这个文件
[root@xz system]# cat httpd.service
[Unit]
Description=httpd server daemon //修改为httpd
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start //更改为apachectl的路径 开启
ExecStop=/usr/local/apache/bin/apachectl stop //关闭
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@xz ~]# systemctl daemon-reload //重启让其生效
安装mysql
//准备工作
配置mysql的yum源
[root@xz ~]#wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm //下载
[root@xz ~]# rpm -ivh mysql57-community-release-el7-10.noarch.rpm //安装
[root@xz ~]# yum clean all //清理缓存
[root@xz ~]# yum makecache //建立本地缓存方便下载
[root@xz ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.37-1.el7.x86_64.rpm
[root@xz ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.37-1.el7.x86_64.rpm
[root@xz ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-devel-5.7.37-1.el7.x86_64.rpm
[root@xz ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.37-1.el7.x86_64.rpm
[root@xz ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-server-5.7.37-1.el7.x86_64.rpm
[root@xz ~]# dnf -y install *.rpm //安装此目录下的所有rpm包
[root@xz ~]# rpm -qa|grep mysql
mysql57-community-release-el7-10.noarch
mysql-community-common-5.7.37-1.el7.x86_64
mysql-community-client-5.7.37-1.el7.x86_64
mysql-community-devel-5.7.37-1.el7.x86_64
mysql-community-libs-5.7.37-1.el7.x86_64
mysql-community-server-5.7.37-1.el7.x86_64
配置mysql
[root@xz ~]# systemctl status mysqld //查看状态
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: d>
Active: inactive (dead)
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@xz ~]# systemctl enable --now mysqld //设置开机自启
[root@xz ~]# ss -antl //查看mysql的端口号是否开启 默认为3306
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@xz ~]# grep "password" /var/log/mysqld.log //查看临时密码
2022-04-21T17:55:37.423426Z 1 [Note] A temporary password is generated for root@localhost: zN7IonUq;Riv
[root@xz ~]# mysql -uroot -p'zN7IonUq;Riv'; //临时密码的登录
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 3
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> set password = password('Runtime.123!'); //修改密码
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@xz ~]# mysql -uroot -p'Runtime.123!' //新密码登录
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 4
Server version: 5.7.37 MySQL Community Server (GPL)
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> quit
root@xz ~]# rpm -qa |grep mysql
mysql57-community-release-el7-10.noarch
mysql-community-common-5.7.37-1.el7.x86_64
mysql-community-client-5.7.37-1.el7.x86_64
mysql-community-devel-5.7.37-1.el7.x86_64
mysql-community-libs-5.7.37-1.el7.x86_64
mysql-community-server-5.7.37-1.el7.x86_64
//为避免mysql自动升级,这里需要卸载最开始安装的yum源
[root@xz ~]# rpm -e mysql57-community-release
[root@xz ~]# rpm -qa |grep mysql
mysql-community-common-5.7.37-1.el7.x86_64
mysql-community-client-5.7.37-1.el7.x86_64
mysql-community-devel-5.7.37-1.el7.x86_64
mysql-community-libs-5.7.37-1.el7.x86_64
mysql-community-server-5.7.37-1.el7.x86_64
安装php
//准备工作
安装依赖包
[root@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 sqlite-devel libzip-devel
[root@xz ~]# wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz //下载php源码包
[root@xz ~]# tar -zxf oniguruma-6.9.4.tar.gz //解压
编译php
[root@xz ~]# cd oniguruma-6.9.4
[root@xz oniguruma-6.9.4]# ./autogen.sh && ./configure --prefix=/usr //设置存放位置
[root@xz oniguruma-6.9.4]# make
[root@xz oniguruma-6.9.4]# make install
[root@xz ~]# wget https://www.php.net/distributions/php-7.4.29.tar.xz //下载php的源码包
[root@xz ~]# tar xf php-7.4.29.tar.xz //解压
[root@xz ~]# cd 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
[root@xz php-7.4.29]# make
[root@xz php-7.4.29]# make install
配置php
//配置php
设置环境变量
[root@xz ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@xz ~]# source /etc/profile.d/php7.sh //读取,生效
[root@xz ~]# which php
/usr/local/php7/bin/php
//配置php-fpm
[root@xz~]# cd php-7.4.29/
[root@xz php-7.4.29]# cp php.ini-production /etc/php.ini //将生产环境文件 复制到etc下
[root@xz php-7.4.29]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@xz fpm]# chmod +x /etc/rc.d/init.d/php-fpm //此文件需要执行权限所以复制过去要看是否有执行(x)权限
[root@xz php-7.4.29# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf //将php-fpm.conf.default 复制一份名为php-fpm.conf
[root@xz php-7.4.29]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf //将www.conf.default 复制一份名为www.conf
开启服务检查端口
//创建测试文件
[root@xz ~]# cd /usr/local/apache/htdocs/ //进入网页目录
[root@xz htdocs]# mkdir test.com //创建存放网页的目录
[root@xz htdocs]# chown -R apache.apache /usr/local/apache/ //设置apache下的文件目录属组属主都为apache
[root@xz htdocs]# cd test.com/
[root@xz test.com]# vim index.php //创建一个index.php的测试文件
<?php
phpinfo();
?>
[root@xz htdocs]# ll
total 4
-rw-r--r--. 1 apache apache 45 Jun 12 2007 index.html
drwxr-xr-x. 2 apache apache 23 Apr 22 02:32 test.com
启动代理模块
[root@xz ~]# cd /usr/local/apache/conf/
[root@xz conf]# vim httpd.conf
LoadModule proxy_module modules/mod_proxy.so //将这两行注释取消
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
配置虚拟主机
[root@xz conf]# vim httpd.conf
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 //在index.html前面添加index.php 让网站能够访问到php类型
</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>
域名是无法直接访问的,要把真机上的c:\windows\system32\drivers\etc\hosts文件修改
添加域名与IP的映射
//重启apache服务
[root@xz ~]# apachectl stop
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.74.129. Set the 'ServerName' directive globally to suppress this message
[root@xz ~]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.74.129. Set the 'ServerName' directive globally to suppress this message
[root@xz ~]# 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:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
验证
ip访问
域名访问