最後更新日期:2024 年 08 月 27 日
跟大家分享我的操作步驟。
Table of Contents
Linux 伺服器基本資料設定
時區:Asia/Taipei
主機名稱:oak
操作人員帳號:david
apt update && apt upgrade
timedatectl list-timezones
timedatectl set-timezone 'Asia/Taipei'
date
hostnamectl set-hostname oak
adduser david
adduser david sudo
Apache 安裝設定
sudo apt update
sudo apt install apache2
sudo systemctl status apache2
hostname -I
curl http://<IP_ADDR>
// stop your web server
sudo systemctl stop apache2
sudo systemctl start apache2
sudo systemctl restart apache2
// If you are simply making configuration changes, Apache can often reload without dropping connections.
sudo systemctl reload apache2
//By default, Apache is configured to start automatically when the server boots. If this is not what you want, disable this behavior by running:
sudo systemctl disable apache2
// To re-enable the service to start up at boot, run:
sudo systemctl enable apache2
預設的網頁檔案根目錄是 /var/www/html
MySQL 安裝設定
sudo apt install mysql-server
sudo mysql -u root
CREATE DATABASE webdata;
CREATE USER 'webuser' IDENTIFIED BY 'password';
GRANT ALL ON webdata.* TO 'webuser';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'password';
PHP 安裝設定
sudo apt install php libapache2-mod-php php-mysql
sudo apt install php-curl php-json php-cgi
sudo apt install php-gd php-mbstring php-xml php-xmlrpc
sudo apt install php-bcmath php-zip php-pdo php-common php-tokenizer
# composer create-project 需要 zip
驗證 LAMP 是否成功運作
/var/www/php.index
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Welcome to the Site!</p>';
// When running this script on a local database, the servername must be 'localhost'. Use the name and password of the web user account created earlier. Do not use the root password.
$servername = "localhost";
$username = "webuser";
$password = "password";
// Create MySQL connection
$conn = mysqli_connect($servername, $username, $password);
// If the conn variable is empty, the connection has failed. The output for the failure case includes the error message
if (!$conn) {
die('<p>Connection failed: </p>' . mysqli_connect_error());
}
echo '<p>Connected successfully</p>';
?>
</body>
</html>
參考資料
Guides – Setting Up and Securing a Compute Instance
Comments