LAMP架构超详细搭建步骤
LAMP介紹:
Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一組常用來搭建或者服務器的開源軟件,本身都是各自獨立的程序,但是因為常被放在一起使用,擁有了越來越高的兼容度,共同組成了一個強大的Web應用程序平臺。
目前LAMP架構是大多數中小企業最青睞的PHP架構選擇,也是眾多Linux?SA喜歡選擇的一套架構。
版本要求:
Apache/2.4.68
5.5.68-MariaDB
PHP?8.0.17
phpMyAdmin-4.4.15.10-6.el7.noarch
一.環境配置:
1.初始環境ping通網絡即可。模式nat網絡下
[root@localhost ~]cd /etc/yum.repo ???????????#切換到yum源下
[root@localhost yum.repos.d]# setenforce 0 ???#設置SELinux 成為permissive模式permissive(寬松模式)
[root@localhost ~]mkdir /mnt/centos?????????????????#創建掛載點
[root@localhost ~]mount /dev/cdrom /mnt/centos??#掛載在/dev/cdrom/mnt/下
[root@localhost ~]vim /etc/yum.repos.d/local.repo???????????????????#編輯yum源
[centos] ????????????????????????????????????????????????#yum源名字
name=centos ?????????????????????????????????????????????#倉庫名字
baseurl=file:///mnt/centos ???????????????????#掛載鏡像創建的目錄及路徑
enabled=1 ???????????????????????????????#yum源是否啟用 1-啟用 0-不啟用
gpgcheck=0 ???????????????????????????????#安全檢測 1-開啟 0-不開啟
[root@localhost ~]yum makecache??????????????????????#建立緩存 解決睡眠問題:rm -rf /var/run/yum.pid?????????????????#激活睡眠程序
[root@localhost ~]yum repolist?????????????????????????#檢測yum源是否能用
[root@localhost ~]# cd /etc/yum.repos.d ????????????????#切換到yum源目錄下
2.需配網絡yum源,ip為自動獲取:
[root@localhost ~]# cd /etc/yum.repos.d #切換到yum倉庫下
[root@localhost yum.repos.d]# rm -rf* #刪除自帶yum源
[root@localhost yum.repos.d]wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #下載阿里yum源
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache #清除yum緩存及更新yum
二.Apache安裝及配置
[root@localhost yum.repos.d]# yum -y install httpd #安裝Apacher軟件包
[root@localhost yum.repos.d]# httpd –v #查看Apache版本信息
[root@localhost yum.repos.d]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bask #備份主配置文件
[root@localhost yum.repos.d]# vim /etc/httpd/conf/httpd.conf #編輯主配置文件????
將125行中AllowOverride?None?中的?None?改為?All如下圖
[root@localhost yum.repos.d]# systemctl restart httpd #重啟服務
[root@localhost yum.repos.d]# systemctl enable httpd #設置開機自啟
[root@localhost yum.repos.d]# systemctl status httpd #查看httpd服務狀態,及目的查看httpd是否運行運行及正確:
[root@localhost yum.repos.d]# netstat -lntup | grep httpd #查看httpd端口
三.MariaDB安裝及配置
[root@localhost yum.repos.d]# yum install mariadb-server mariadb #安裝數據庫軟件[root@localhost yum.repos.d]# systemctl restart mariadb.service #重啟數據庫 [root@localhost yum.repos.d]# systemctl enable mariadb.service #設置開機自啟
[root@localhost yum.repos.d]# systemctl status mariadb.service #查看數據庫是否運行狀態
[root@localhost yum.repos.d]# mysql_secure_installation #初始化數據庫及進行圖下操作
Enter current password for root (enter for none): 【輸入數據庫超級管理員root密碼,注意不是系統root的密碼,第一次進入還沒有設置直接回車】
Set root password? [Y/n] Y 【設置密碼】New password:Re-enter new password: 【再次輸入密碼】
Remove anonymous users? [Y/n] y 【移除匿名用戶Y】
Disallow root login remotely? [Y/n] n 【拒絕root遠程登錄n】
Remove test database and access to it? [Y/n] y 【刪除test數據庫,y:刪除】
Reload privilege tables now? [Y/n] y 【重新加載權限表y】
[root@localhost yum.repos.d]# mysql -u root -p #登錄mysql
四.PHP安裝及配置
[root@localhost yum.repos.d]# yum -y install epel-release yum-utils ????#安裝?epel-release源和?源管理工具yum-utils
[root@localhost yum.repos.d]# yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm #安裝Remi軟件源
[root@localhost yum.repos.d]# yum-config-manager --enable remi-php80 #啟用remi源的php8.0模塊
[root@localhost yum.repos.d]# yum -y install yum-utils #安裝php插件
[root@localhost yum.repos.d]# yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis ????#安裝php軟件包
[root@localhost yum.repos.d]# php -v #查看php版本信息
五.phpMyAdmin安裝及配置
[root@localhost yum.repos.d]# yum -y install epel-release #安裝依賴環境
[root@localhost yum.repos.d]# yum -y install phpmyadmin #安裝軟件包
[root@localhost yum.repos.d]# vim /etc/httpd/conf.d/phpMyAdmin.conf #修改主配置
文件
編輯17行與18行在它們前面添加#號
[root@localhost yum.repos.d]# systemctl restart httpd.service # 重啟 httpd服務
[root@localhost yum.repos.d]# setenforce 0 #修改seliunx狀態
[root@localhost yum.repos.d]# ifconfig #查詢IP
訪問數據庫:
1.在瀏覽器輸入http://172.20.10.9/phpmyadmin
2.進入登陸頁面
3.輸入密碼及剛才設置的mysql新密碼
4.進入mysql界面
六.基于lAMP架構部署wordpress項目
[root@localhost yum.repos.d]# mkdir -p /www/html #批量創建/www/html/文件
[root@localhost yum.repos.d]# cd /var/www/html #切換到網站根目錄下
[root@localhost html]# wget https://cn.wordpress.org/wordpress-5.9.3-zh_CN.tar.gz #下載安裝包
[root@localhost html]# tar zxvf wordpress-5.9.3-zh_CN.tar.gz ????#解壓安裝包
[root@localhost html]# cd wordpress/ ????#進入項目
[root@localhost wordpress]# mv * /var/www/html/ ????#將網站默認頁面移至根目錄
[root@localhost wordpress]# chmod -R 775 /var/www/html/ ????#更改網站目錄權限
[root@localhost wordpress]# chown -R apache:root /var/www/html/ #更改文件屬主
[root@localhost wordpress]# mysql -u root -p ????#登錄數據庫
Create database wordpressdb;????
Create user wsz@localhost identified by '123456';
Grant all privileges on wordpressdb.* to pgz@localhost;? ? ?(自己名字)
Flush privileges;
Exit
創建數據庫,創建用戶,賦予權限
systemctl restart httpd
systemctl restart mariadb #重啟服務
cd /var/www/html/ #切換網站根目錄
cp wp-config-sample.php wp-config.php #拷貝文件
vim wp-config.php #編輯php配置文件
[root@localhost html]# vim /etc/hosts ?????#修改hosts文件
把文件內容刪完,添加內容為自己IP加www.pgz.com.com(域名 可以任意修改)。
驗證:打開火狐輸入IP或域名即可,成功及為下圖:
七.Wordpress主題設置
[root@localhost html]# cd /var/www/html/wp-content/themes #切換至wordores主題目錄下
[root@localhost themes]# wget https://github.com/mashirozx/sakura/archive/refs/heads/3.x.zip #下載自選主題
[root@localhost themes]# yum install unzip ????#安裝解壓工具
[root@localhost themes]# unzip 3.x.zip ????#解壓主題包
[root@localhost themes]# mv sakura-3.x/ Sakura ????#重命名
八.實驗最后驗證:瀏覽器完成
1.在虛擬機上直接輸入IP(172.20.10.9)會出現如下圖:
2.按要求輸入,登錄即可。
3.出現下圖即為成功
總結
以上是生活随笔為你收集整理的LAMP架构超详细搭建步骤的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JBoss下载and安装
- 下一篇: 数据结构视频教程 -《[猎豹网校]数据结