安装Apache
[root@localhost src]# ls
apr-1.7.0.tar.bz2 apr-util-1.6.1.tar.bz2 debug kernels
[root@localhost src]# tar xf apr-1.7.0.tar.bz2
[root@localhost src]# tar xf apr-util-1.6.1.tar.bz2
[root@localhost src]# ls
apr-1.7.0 apr-util-1.6.1 debug
apr-1.7.0.tar.bz2 apr-util-1.6.1.tar.bz2 kernels
[root@localhost src]# cd apr-1.7.0
[root@localhost apr-1.7.0]# vi configure
# $RM "$cfgfile" //将此行加上注释,或者删除此行
root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make && make install //安装
[root@localhost apr-1.7.0]# cd /usr/src/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 src]# cd httpd-2.4.43
[root@localhost httpd-2.4.43]# ./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
[root@localhost httpd-2.4.43]# make && make install
安装后配置
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
取消ServerName前面的注释
[root@100 ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
查看端口
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 *:80 *:*
安装MySQL
# 安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
# 安装编译工具
[root@localhost ~]#yum -y install gcc gcc-c++
# 创建用户和组
[root@localhost src]# groupadd -r -g 306 mysql
[root@localhost src]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
解压软件包
[root@localhost src]# ls
debug kernels mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# ls /usr/local/
bin games lib libexec sbin src
etc include lib64 mysql-5.7.33-linux-glibc2.12-x86_64 share
[root@localhost local]# ln -sv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.33-linux-glibc2.12-x86_64/'
修改目录/usr/local/mysql的属主属组
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
添加环境变量
[root@localhost ~]# ls /usr/local/mysql
LICENSE README bin docs include lib man share support-files
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# . /etc/profile.d/mysql.sh
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
建立数据存放目录
[root@localhost mysql]# mkdir /opt/data
[root@localhost mysql]# chown -R mysql.mysql /opt/data/
[root@localhost mysql]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 May 13 00:10 data
初始化数据库
[root@localhost mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2021-05-12T16:11:19.045265Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-12T16:11:19.199794Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-12T16:11:19.225937Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-12T16:11:19.281830Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: afbe2dda-b33c-11eb-ae1e-000c29f0be77.
2021-05-12T16:11:19.282603Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-12T16:11:20.304302Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-12T16:11:20.430687Z 1 [Note] A temporary password is generated for root@localhost: N*u6wvErqXuA
配置mysql
[root@localhost mysql]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
'/usr/local/include/mysql' -> '/usr/local/mysql/include/'
[root@localhost mysql]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# ldconfig -v
生成配置文件
[root@localhost mysql]# cat > /etc/my.cnf <<EOF
> [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
> EOF
配置服务启动
[root@localhost mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@localhost mysql]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld
启动mysql
[root@localhost mysql]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
SUCCESS!
[root@localhost mysql]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 80 *:3306 *:*
修改密码
[root@localhost ~]# cd /usr/local
[root@localhost local]# mysql -uroot -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@localhost local]# dnf provides libncurses.so.5
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 22:45:44 ago on Wed May 12 01:34:03 2021.
ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
Repo : a1
Matched from:
Provide : libncurses.so.5
[root@localhost local]# dnf -y install ncurses-compat-libs
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 22:45:55 ago on Wed May 12 01:34:03 2021.
Dependencies resolved.
==================================================================================
Package Architecture Version Repo Size
==================================================================================
Installing:
ncurses-compat-libs x86_64 6.1-7.20180224.el8 a1 331 k
Transaction Summary
==================================================================================
Install 1 Package
Total size: 331 k
Installed size: 1.2 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : ncurses-compat-libs-6.1-7.20180224.el8.x86_64 1/1
Running scriptlet: ncurses-compat-libs-6.1-7.20180224.el8.x86_64 1/1
/sbin/ldconfig: File /lib64/libgpm.so.2 is empty, not checked.
/sbin/ldconfig: File /lib64/libgpm.so.2.1.0 is empty, not checked.
Verifying : ncurses-compat-libs-6.1-7.20180224.el8.x86_64 1/1
Installed products updated.
Installed:
ncurses-compat-libs-6.1-7.20180224.el8.x86_64
Complete!
[root@localhost local]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33
Copyright (c) 2000, 2021, 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('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@localhost local]# mysql -uroot -p'root'
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.33 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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>
配置apache
配置apache
在apache的主配置文件中取消以下注释即可配置虚拟主机
[root@localhost ~]# vim /etc/http24/http.cnf
Include /etc/httpd24/extra/httpd-vhosts.conf
在apache的主配置文件中取下以下两行注释开启apache的代理模块
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
在apache的主配置文件中找到以下代码,在index.html前面添加index.php使apaache服务能够第一个找到php的初始页面
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
在apache主配置文件中添加以下两行
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .phe //添加此行
AddType application/x-httpd-php-source .phps //添加此行
创建虚拟主机的根目录并设置属组为apache
[root@localhost httpd-2.4.43]# mkdir /usr/local/php
[root@localhost httpd-2.4.43]# mkdir /usr/local/php/huang
[root@localhost local]# chown -R apache.apache php
配置虚拟主机
[root@localhost ~]# vim /etc/httpd24/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/php/huang"
ServerName www.huang.com
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.11.136:9000/usr/local/apache/php/huang/$1
<Directory "/usr/local/php/huang">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
安装php
安装php
[root@localhost ~]# dnf -y install php*
启动php-fpm
[root@localhost ~]# service php-fpm start
监听端口并重启服务
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
[root@localhost ~]# head -38 /etc/php-fpm.d/www.conf |tail -2
; Note: This value is mandatory.
listen = /run/php-fpm/www.sock
[root@localhost ~]# service php-fpm restart
[root@localhost ~]# ss -anlt
[root@localhost ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*