1. 程式人生 > >centOS7 搭建LAMP伺服器(apache+php+MariaDB)

centOS7 搭建LAMP伺服器(apache+php+MariaDB)

安裝httpd

yum install httpd

配置ServerName

vi /etc/httpd/conf/httpd.conf

將#ServerName www.example.com:80修改為ServerName localhost:80 外部機器此時輸入伺服器的IP地址,應該看到apache的服務頁面,埠不用輸,apache預設就是使用80埠

systemctl start httpd.service #開啟httpd服務 systemctl enable httpd.service#配置httpd服務開機自啟

關閉防火牆

Systemctl stop firewalld.service systemctl disable firewalld.service #禁止firewall開機啟動 firewall-cmd --state #檢視預設防火牆狀態(關閉後顯示notrunning, 開啟後顯示running)

安裝php

yum install php

重啟apache服務

Systemctl httpd restart

在這裡插入圖片描述

安裝mysql

1、安裝MariaDB 安裝命令

yum -y install mariadb mariadb-server

安裝完成MariaDB,首先啟動MariaDB

systemctl start mariadb

設定開機啟動

systemctl enable mariadb

接下來進行MariaDB的相關簡單配置

mysql_secure_installation

首先是設定密碼,會提示先輸入密碼 Enter current password for root (enter for none):<–初次執行直接回車 設定密碼 Set root password? [Y/n] <– 是否設定root使用者密碼,輸入y並回車或直接回車 New password: <– 設定root使用者的密碼 Re-enter new password: <– 再輸入一次你設定的密碼 其他配置 Remove anonymous users? [Y/n] <– 是否刪除匿名使用者,回車 Disallow root login remotely? [Y/n] <–是否禁止root遠端登入,n,否則無法遠端管理 Remove test database and access to it? [Y/n] <– 是否刪除test資料庫,回車 Reload privilege tables now? [Y/n] <– 是否重新載入許可權表,回車 初始化MariaDB完成,接下來測試登入

mysql -u root -p enter password:

進入mariaDB頁面