*安装MySQL
(1)上传mysql安装包到/usr/local/src下并解压
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# ls
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
(2)解压完成后移动到/usr/local下并创建一个mysql的目录方便存放信息
[root@localhost src]# mv mysql-5.6.43-linux-glibc2.12-x86_64 /usr/local/mysql
创建用户
[root@localhost mysql]# useradd -s /sbin/nologin mysql
创建目录并修改权限
[root@localhost mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql
查看权限
[root@localhost mysql]# ls -la /data/mysql/
total 0
drwxr-xr-x. 2 mysql mysql 6 May 24 04:48 .
drwxr-xr-x. 3 root root 18 May 24 04:48 ..
安装环境
[root@localhost mysql]# yum install perl-Module-Install -y
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
覆盖掉
[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
修改配置文件
vi/etc/my.cnf
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
server_id = 78
socket = /tmp/mysql.sock
修改启动脚本
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# vim /etc/init.d/mysqld
basedir= /usr/local/mysql
datadir= /data/mysql
启动出现错误,解决方法
[root@localhost mysql]# service mysqld start
Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'.
. SUCCESS!
[root@localhost mysql]# yum -y install autoconf -y
再次启动并查看端口
[root@localhost mysql]# netstat -ntpl |grep mysql
tcp6 0 0 :::3306 :::* LISTEN 11511/mysqld
安装Apache
上传安装包并解压
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ls
apr-1.6.5.tar.gz
apr-util-1.6.1.tar.gz
httpd-2.4.46.tar.gz
mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
[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]# yum install libtool* -y
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.5]# make && make install
**编译安装apr-utils**
[root@localhost apr-1.6.5]# cd ..
[root@localhost src]# cd apr-util-1.6.1
[root@localhost src]#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# yum install expat-devel -y
[root@localhost apr-util-1.6.1]# make && make install
**安装apache**
[root@localhost src]# cd httpd-2.4.46/
[root@localhost httpd-2.4.46]# yum install pcre-devel -y
[root@localhost src]# cp -r apr-1.6.5 httpd-2.4.46/srclib/apr
[root@localhost src]# cp -r apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
[root@localhost src]# cd httpd-2.4.46/
[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-shared=all --with-mpm=prefork
[root@localhost httpd-2.4.46]#make j4 && make install
查看模块
[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 (shared)
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]# ls
apr-1.6.5
apr-1.6.5.tar.gz
apr-util-1.6.1
apr-util-1.6.1.tar.gz
httpd-2.4.46
httpd-2.4.46.tar.gz
mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
php-7.4.19.tar.gz
[root@localhost src]# tar zxf php-7.4.19.tar.gz
[root@localhost php-7.4.19]#yum install libxml2-devel bzip bzip-devel libpng libpng-devel openssl openssl-devel freetype freetype-devel opel-release -y
[root@localhost php-7.4.19]# yum install epel-release -y
[root@localhost php-7.4.19]# yum install libmcrypt -y
[root@localhost php-7.4.19]# yum -y install sqlite-devel
[root@lamp php-7.4.19]# yum -y install oniguruma-devel
[root@localhost php-7.4.19]# yum install epel-release -y
[root@localhost php-7.4.19]# yum install libmcrypt-devel
[root@localhost php-7.4.19]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --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
[root@localhost php-7.4.19]# make && make install
检验安装是否成功
[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 (shared)
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@lamp php-7.4.19]# cp php.ini-production /usr/local/php7/etc/php.ini
[root@lamp php-7.4.19]# cd /usr/local/php7/etc/
[root@lamp etc]# ls
php.ini
httpd解析PHP
[root@lamp conf]# vim httpd.conf
//编辑httpd的主配置文件
搜索ServerName,把ServerName www.example.com:80前#去掉;
<Directory />
AllowOverride none
Require all denied
</Directory>
改成:
<Directory />
AllowOverride none
Require all granted
</Directory> //目的允许所有请求访问
搜索AddType application/x-gzip .gz .tgz,在下面添加一行 AddType application/x-httpd-php .php;
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
改成:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
(4)测试安装
① 测试配置文件是否正确
//检验配置文件是否正确
[root@lamp conf]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
启动httpd
重新加载apache服务
/usr/local/apache2.4/bin/apachectl graceful
httpd not running, trying to start
[root@lamp conf]# ps -ef | grep http
daemon 32703 1 0 08:20 ? 00:00:00 /usr/local/apache2.4/bin/httpd -k graceful
daemon 32704 1 0 08:20 ? 00:00:00 /usr/local/apache2.4/bin/httpd -k graceful
daemon 32705 1 0 08:20 ? 00:00:00 /usr/local/apache2.4/bin/httpd -k graceful
daemon 32706 1 0 08:20 ? 00:00:00 /usr/local/apache2.4/bin/httpd -k graceful
daemon 32707 1 0 08:20 ? 00:00:00 /usr/local/apache2.4/bin/httpd -k graceful
root 32715 11079 0 08:26 pts/2 00:00:00 grep --color=auto http
只保留最后一个进程
[root@lamp conf]# kill -9 32703
[root@lamp conf]# kill -9 32706
启动
[root@lamp conf]# /usr/local/apache2.4/bin/apachectl start
查看是否启动
[root@lamp conf]# ps -ef | grep http
root 32725 1 0 08:32 ? 00:00:00 /usr/local/apache2.4/bin/httpd -k start
daemon 32726 32725 0 08:32 ? 00:00:00 /usr/local/apache2.4/bin/httpd -k start
daemon 32727 32725 0 08:32 ? 00:00:00 /usr/local/apache2.4/bin/httpd -k start
daemon 32728 32725 0 08:32 ? 00:00:00 /usr/local/apache2.4/bin/httpd -k start
daemon 32729 32725 0 08:32 ? 00:00:00 /usr/local/apache2.4/bin/httpd -k start
daemon 32730 32725 0 08:32 ? 00:00:00 /usr/local/apache2.4/bin/httpd -k start
root 32733 11079 0 08:33 pts/2 00:00:00 grep --color=auto http
/使用curl命令简单测试,,显示了就是成功
[root@lamp conf]# curl localhost
<html><body><h1>It works!</h1></body></html>
网页内容在这里也可以查看到
[root@lamp conf]# cd ..
[root@lamp apache2.4]# cd htdocs/
[root@lamp htdocs]# cat index.html
<html><body><h1>It works!</h1></body></html>
可以使用浏览器访问
需要修改本地hosts文件
把ip添加进去
② 测试是否正确解析PHP
[root@lamp conf]# vim /usr/local/apache2.4/htdocs/1.php
<?
echo "php解析正确"
?>
//编写一个测试脚本
[root@lamp ~]# /usr/local/apache2.4/bin/apachectl restart
[root@lamp conf]# curl localhost/1.php
php解析正确 //编写一个测试脚本
默认虚拟主机
修改主配置文件
[root@lamp ~]# cd /usr/local/apache2.4/conf/
[root@lamp conf]# vim httpd.conf
搜索/vhost把前面的#去掉
[root@lamp conf]# vim extra/httpd-vhosts.conf
备份vhost文件
[root@lamp conf]# cd extra/
[root@lamp extra]# cp httpd-vhosts.conf httpd-vhosts.conf-bak
创建网站
[root@lamp ~]# cd /usr/local/apache2.4/
[root@lamp apache2.4]# mkdir docs
[root@lamp apache2.4]# cd !$
cd docs
[root@lamp docs]# mkdir abc.com
[root@lamp docs]# mkdir 111.com
[root@lamp docs]# vim abc.com/index.html
abc.com
[root@lamp docs]# vim 111.com/index/html
111.com
~
[root@lamp docs]# curl -xlocalhost:80 111.com
<html><body><h1>It works!</h1></body></html>
http的用户认证
[root@lamp extra]# cd /usr/local/apache2.4/docs/
[root@lamp docs]# ls
111.com abc.com
[root@lamp docs]# cd abc.com/
[root@lamp abc.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@lamp extra]# /usr/local/apache2.4/bin/htpasswd -cm /usr/local/apache2.4/docs/.htpasswd wrx
New password: 000000
Re-type new password: 000000
Adding password for user wrx
访问
[root@lamp extra]# curl -xlocalhost:80 wrx:000000 abc.com -I
HTTP/1.1 200 OK
Date: Sat, 10 Apr 2021 17:49:49 GMT
Server: Apache/2.4.46 (Unix) PHP/7.4.19
Last-Modified: Mon, 11 Jun 2007 18:53:14 GMT
ETag: "2d-432a5e4a73a80"
Accept-Ranges: bytes
Content-Length: 45
Content-Type: text/html
HTTP/1.1 200 OK
Date: Sat, 10 Apr 2021 17:49:49 GMT
Server: Apache/2.4.46 (Unix) PHP/7.4.19
Last-Modified: Mon, 11 Jun 2007 18:53:14 GMT
ETag: "2d-432a5e4a73a80"
Accept-Ranges: bytes
Content-Length: 45
Content-Type: text/html