【LAMP 基于 Red Hat Linux 7】
生活随笔
收集整理的這篇文章主要介紹了
【LAMP 基于 Red Hat Linux 7】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本指南搭建基于 rhel 7.5 的 Apache,MariaDB 和 PHP,并創建自定義數據測試系統。
1. Linux 版本說明
Red Hat Enterprise Linux Server release 7.5 (Maipo)
使用對應的 Linux 系統 iso 文件中的包完成 Apache,MariaDB 和 PHP 的安裝。
2. 環境準備
2.1. 關閉防火墻 # systemctl stop firewalld 2.2. 設置 selinux 為寬容模式 # setenforce 0 2.3. 配置本地光盤為 yum 源 2.3.1. 連接 iso 文件到 CD/DVD 設備
2.3.2. 掛載 CD/DVD 設備
# mount /dev/cdrom /media/cdrom?2.3.3. 生成 dvd.repo 文件
3. 安裝 Apache 1. 使用 yum 命令安裝 httpd 軟件包 # yum -y install httpd 2. 啟動 httpd 服務,并配置開機啟動 # systemctl start httpd # systemctl enable httpd 3. 關閉防火墻,并配置開機不啟動 # systemctl stop firewalld # systemctl disable firewalld 4. 查看 httpd 服務運行狀態和鏈接狀態 # systemctl status httpd # ss -antup | grep 80 5. 測試 httpd 服務 # 在 /var/www/html 目錄下寫入主頁文件 [root@localhost ~]# echo "Hello World" > /var/www/html/index.html[root@localhost ~]# curl localhost Hello World 4. 安裝 MariaDB 服務器和客戶端 4.1. 通過 yum 命令安裝 MariaDB 服務器和客戶端軟件 # yum -y install mariadb-server mariadb 4.2. 啟動 mariadb 服務 [root@localhost ~]# systemctl start mariadb [root@localhost ~]# systemctl status mariadb ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2021-11-28 16:29:14 PST; 6h ago Main PID: 1408 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─1408 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─1678 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql -- plugin-dir=/usr/lib64/mysql/plugin --log-error... Nov 28 16:29:09 localhost.localdomain systemd[1]: Starting MariaDB database server... Nov 28 16:29:10 localhost.localdomain mariadb-prepare-db-dir[1295]: Database MariaDB is probably initialized in /var/lib/m...one. Nov 28 16:29:10 localhost.localdomain mysqld_safe[1408]: 211128 16:29:10 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. Nov 28 16:29:10 localhost.localdomain mysqld_safe[1408]: 211128 16:29:10 mysqld_safe Starting mysqld daemon with database...mysql Nov 28 16:29:14 localhost.localdomain systemd[1]: Started MariaDB database server. Hint: Some lines were ellipsized, use -l to show in full. 4.3. 配置 mariadb 服務開機啟動 # systemctl enable mariadb 4.4. 初始化數據庫安全 通過 mysql_secure_installation 安全腳本,可以快速配置數據庫安全:為 root 用戶設置密碼;禁止 root 用戶遠程登錄;刪除匿名賬號;刪除 test 數據庫; [root@localhost ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): # 輸入 root 當前密碼,沒有密碼,直 接按回車 OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y # 是否設置 root 密碼 --> 選擇Y,密碼設置為123456 New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y # 是否刪除匿名賬號 --> 輸入 n ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y # 是否允許 root 遠程登錄 --> 輸入 n ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.Remove test database and access to it? [Y/n] y # 是否刪除 test 數據庫,及其訪問權限 --> 輸入 n - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y # 是否立即加載權限表 --> 輸入 Y ... Success! Cleaning up...All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB! 5. 安裝 php 使用 yum 命令安裝 php和php-mysql,php-mysql 可以讓 PHP 連接數據庫。 # yum install -y php php-mysql 6. 重啟 httpd 服務 # systemctl restart httpd 7. 創建 php 信息頁面測試 1. 在 /var/www/html目錄下創建 info.php文件,內容如下: <?php phpinfo();?> 2. 查看 Linux 虛擬機 ip 地址 # ip a 2. 到 Windows 宿主機,使用瀏覽器訪問 info.php頁面 地址示例:http://192.168.206.128/info.php 8. 使用 php 連接數據庫 8.1. 通過文件導入數據庫測試數據 #mysql -u root -p123456 < student.sql 8.2. 將 php 腳本文件上傳到 /var/www/html/目錄 使用 MobaXterm 將 student_info.php 文件上傳到 /var/www/html目錄中:8.3. 通過 Windows 瀏覽器訪問 student_info.php 頁面
?
?
?
?
總結
以上是生活随笔為你收集整理的【LAMP 基于 Red Hat Linux 7】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 搭建服务器 运用阿里云DNS自己实现DD
- 下一篇: excel数据多列排序