LAMP+phpMyAdmin

一、安装Apache

1. 准备环境

$ systemctl status httpd
Unit httpd.service could not be found.

# 卸载方法
$ yum remove httpd 
或
$ rpm -e httpd

# 安装依赖包
$ yum install apr-util-devel pcre-devel pkgconfig -y

# 防火墙放行
$ firewall-cmd --add-service=http --permanent 
$ firewall-cmd --reload

2. 下载源码包

$ wget -c https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.46.tar.bz2

3. 解包

$ tar -jxvf httpd-2.4.46.tar.bz2 -C /usr/src/

4. 配置

$ cd /usr/src/httpd-2.4.46/
$ ./configure --prefix=/usr/local/httpd \
                                  --enable-so \
                                  --enable-rewrite \
                                  --enable-charset-lite \
                                  --enable-cgi \
                                  --enable-mpms-shared=all

5. 编译及安装

$ make
$ make install

# 查看结果
ll /usr/local/httpd/
total 36K
drwxr-xr-x.  2 root root  262 Mar  5 06:43 bin/
drwxr-xr-x.  2 root root  167 Mar  5 06:43 build/
drwxr-xr-x.  2 root root   78 Mar  5 06:43 cgi-bin/
drwxr-xr-x.  4 root root   84 Mar  5 06:43 conf/
drwxr-xr-x.  3 root root 4.0K Mar  5 06:43 error/
drwxr-sr-x.  2 root root   24 Aug  1  2020 htdocs/
drwxr-xr-x.  3 root root 8.0K Mar  5 06:43 icons/
drwxr-xr-x.  2 root root 4.0K Mar  5 06:43 include/
drwxr-xr-x.  2 root root    6 Mar  5 06:43 logs/
drwxr-xr-x.  4 root root   30 Mar  5 06:43 man/
drwxr-sr-x. 14 root root 8.0K Aug  1  2020 manual/
drwxr-xr-x.  2 root root 4.0K Mar  5 06:43 modules/

6. 优化执行路径

$ ln -s /usr/local/httpd/bin/* /usr/local/bin/
$ httpd -v
Server version: Apache/2.4.46 (Unix)
Server built:   Mar  5 2021 06:42:06

7. 添加httpd服务启动脚本

$ vim /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/httpd/logs/httpd.pid
ExecStart= /usr/local/bin/apachectl $OPTIONS
ExecReload= /bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target

# 启动
$ systemctl daemon-reload 
$ systemctl start httpd
$ systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2021-03-05 06:49:40 EST; 7s ago
  Process: 20356 ExecStart=/usr/local/bin/apachectl $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 20359 (httpd)
   CGroup: /system.slice/httpd.service
           ├─20359 /usr/local/httpd/bin/httpd
           ├─20360 /usr/local/httpd/bin/httpd
           ├─20361 /usr/local/httpd/bin/httpd
           └─20362 /usr/local/httpd/bin/httpd

Mar 05 06:49:40 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Mar 05 06:49:40 localhost.localdomain apachectl[20356]: AH00558: httpd: Could not reliably determine the server's ...sage
Mar 05 06:49:40 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
$ systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

二、Apache服务器配置

1. 添加hosts文件解析

$ vim /etc/hosts
192.168.119.136 www.cisco.com
192.168.119.136 www.huawei.com

2. 构建虚拟主机

# 创建网站默认文件
$ cd /usr/local/httpd/htdocs/
$ mkdir cisco
$ mkdir huawei
$ vim ./cisco/index.html
	<html><body><h1>www.cisco.com</h1></body></html>
$ vim ./huawei/index.html 
	<html><body><h1>www.huawei.com</h1></body></html>
	
# 修改主配置文件
$ vim /usr/local/httpd/conf/httpd.conf
	# Virtual hosts
	Include conf/extra/httpd-vhosts.conf

$ vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/httpd/htdocs/cisco"
    ServerName www.cisco.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common

    <Directory '/usr/local/httpd/htdocs/cisco'>
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/usr/local/httpd/htdocs/huawei"
    ServerName www.huawei.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common

    <Directory '/usr/local/httpd/htdocs/huawei'>
        Require all granted
    </Directory>
</VirtualHost>
$ apachectl -t
	Syntax OK
$ systemctl restart httpd

3. 使用终端浏览器访问

# 路径:C:\Windows\System32\drivers\etc
# 修改终端hosts文件,添加如下内容
	192.168.119.136 www.cisco.com
	192.168.119.136 www.huawei.com

三、MySQL安装

1. 环境准备

$ yum install libaio -y

# 创建用户
$ groupadd mysql
$ useradd -r -g mysql -s /bin/flsse mysql

# 下载二进制安装包
https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz

2. 解压安装包

$ xz -d mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz 
$ tar -xvf mysql-8.0.23-linux-glibc2.12-x86_64.tar -C /usr/local/

3. 创建链接文件mysql

$ cd /usr/local/
$ mv mysql-8.0.23-linux-glibc2.12-x86_64/ mysql
$ cd mysql
$ ls 
	bin  docs  include  lib  LICENSE  man  README  share  support-files

4. 添加环境变量

$ vim /root/.bash_profile
	export PATH=$PATH:/usr/local/mysql/bin

$ source /root/.bash_profile

5. 安装后设置

$ cd /usr/local/mysql
$ mkdir mysql-files

# 设置属主属组为mysql,并设置权限
$ chown mysql:mysql ./mysql-files/
$ chmod 750 ./mysql-files/

# my.cnf
	[mysqld]
	datadir=/usr/local/mysql/data
	basedir=/usr/local/mysql
	socket=/tmp/mysql.sock
	port=3306
	log-error=/usr/local/mysql/data/www.shengzhe.com.err
	user=mysql
	secure_file_priv=/usr/local/mysql/mysql-files
	local_infile=OFF
$ chmod 644 /etc/my.cnf

# 初始化
$ mysqld --initialize --user=mysql
2021-03-08T02:01:01.726131Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 2129
2021-03-08T02:01:01.769911Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-03-08T02:01:03.007141Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-03-08T02:01:04.249511Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Yret+Q*EN9m)

$ mysqld_safe --user=mysql &
[1] 2187
$ Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
2021-03-08T02:01:09.995113Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

6.测试,并修改root密码

$ mysql -uroot -pYret+Q*EN9m)
mysql> alter user 'root'@'localhost' identified by 'Com.123456'; 
Query OK, 0 rows affected, 1 warning (0.00 sec)

7. 构建systemd服务单元配置文件

$ vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=notify

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Start main service
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf $MYSQLD_OPTS 

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 10000

Restart=on-failure

RestartPreventExitStatus=1

# Set environment variable MYSQLD_PARENT_PID. This is required for restart.
Environment=MYSQLD_PARENT_PID=1

PrivateTmp=false

8. 配置MySQL开机启动

$ systemctl daemon-reload 
$ systemctl enable mysqld.service 
$ systemctl start mysqld.service 

四、安装PHP运行环境

1. 安装PHP的yum源

$ rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2. 安装PHP7.2

$ yum install php72w php72w-cli php72w-common php72w-gd php72w-ldap php72w-mbstring php72w-mcrypt php72w-mysql php72w-pdo php72w-opcache -y

3. 复制PHP模块到Apache模块目录

$ find / -name '*php*.so'
/usr/lib64/httpd/modules/libphp7-zts.so
/usr/lib64/httpd/modules/libphp7.so
$ cp /usr/lib64/httpd/modules/libphp7-zts.so /usr/lib64/httpd/modules/libphp7.so /usr/local/httpd/modules/

4. 修改Apache主配置文件

$ vim /usr/local/httpd/conf/httpd.conf
	LoadModule php7_module modules/libphp7.so
	LoadModule authn_file_module modules/mod_authn_file.so
	LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

# 激活额外MPM配置文件
	Include conf/extra/httpd-mpm.conf

# 增加内容
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    AddType application/x-httpd-source .phps
    
# 增加默认首页index.php
	DirectoryIndex index.html index.php
	
# 重启服务
$ systemctl restart httpd

5. 创建test.php测试

$ cd /usr/local/httpd/htdocs
$ vim ./cisco/test.php
	<?php
	phpinfo();
	?>

6. 创建MySQL管理员

mysql> create user 'dbadmin'@'%' identified with mysql_native_password by 'Com.123456';
Query OK, 0 rows affected (0.02 sec)

mysql> grant all on *.* to 'dbadmin'@'%';
Query OK, 0 rows affected (0.01 sec)s

mysql> grant GRANT OPTION  on *.* to 'dbadmin'@'%';
Query OK, 0 rows affected (0.01 sec)

7. 修改PHP的配置文件

$ vim /etc/php.ini
	mysqli.default_socket = /tmp/mysql.sock

8. 创建测试文件

$ vim /usr/local/httpd/htdocs/cisco/mysqltest.php
<?PHP
    $conn=mysqli_connect("localhost","dbadmin","123456Abc!");
    if($conn){
        echo"ok";
    }else{
        echo"error";
    }
?>

$ systemctl restart httpd
$ curl www.cisco.com/mysqltest.php
ok

9. 安装phpMyAdmin

# 下载源码包
https://files.phpmyadmin.net/phpMyAdmin/5.1.0/phpMyAdmin-5.1.0-all-languages.tar.gz

# 解压
$ tar -zxvf phpMyAdmin-5.1.0-all-languages.tar.gz -C /usr/local/httpd/htdocs/cisco/

$ cd /usr/local/httpd/htdocs/cisco/
$ mv phpMyAdmin-5.1.0-all-languages phpmyadmin
$ cd phpmyadmin
$ cp config.sample.inc.php config.inc.php
$ vim config.inc.php
cfg['blowfish_secret'] = 'dbadmin'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

# 访问http://www.cisco.com/phpmyadmin/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值