LAMP(Linux、Apache、MariaDB/MySQL、PHP)是最經典的網站伺服器組合之一。本文以 CentOS 7 為例,示範如何一步步把整套環境架起來。
CentOS 7 預設採用 firewalld 作為防火牆,為了避免後續測試受阻,可先關閉:
systemctl stop firewalld.service # 停止 firewall systemctl disable firewalld.service # 禁止 firewall 開機啟動
接著關閉 SELinux:
vi /etc/selinux/config # 將 SELINUX=enforcing 註解掉 # 新增 SELINUX=disabled :wq! # 保存退出 setenforce 0 # 使設定立即生效
yum install httpd # 依提示輸入 Y 完成安裝 systemctl start httpd.service # 啟動 systemctl stop httpd.service # 停止 systemctl restart httpd.service # 重啟 systemctl enable httpd.service # 設為開機啟動
yum install mariadb mariadb-server # 輸入 Y 自動安裝 systemctl start mariadb.service # 啟動 systemctl enable mariadb.service # 開機啟動
修改 root 密碼與設定遠端授權:
set password for 'root'@'localhost'=password('root');
grant all on *.* to root identified by 'root';
yum install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash systemctl restart mariadb.service systemctl restart httpd.service
建立測試頁面:
cd /var/www/html vi index.php <?php phpinfo(); ?> :wq!
在用戶端瀏覽器輸入伺服器 IP,若能看到 PHP 設定資訊頁,代表整套 LAMP 環境已成功運作。