Ubuntu 安裝 Nginx PHP Mariadb (LEMP)
Step 1 安裝 Nginx
sudo apt install nginx
Step 2 安裝 Mariadb
sudo apt install mariadb-server
Mariadb 安全性設定,包括資料庫 root 密碼
sudo mysql_secure_installation
sudo systemctl status mysql
Step 3 安裝 PHP 7.2
sudo apt install php-fpm php-common php-mysql php-gd php-cli php-xml php-json php-mbstring
sudo systemctl status php7.2-fpm
sudo nano /etc/php/7.2/fpm/php.ini
修改 nginx 的預設檔
sudo nano /etc/nginx/sites-available/default
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
重新啟動 php , nginx
sudo systemctl restart php7.2-fpm
sudo systemctl restart nginx
如果想改安裝 PHP 7.4:
- 新增 SURY PHP PPA repository
sudo apt install lsb-release apt-transport-https ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
執行安裝 PHP 7.4
sudo apt update
sudo apt install php7.4-fpm php7.4-mbstring php7.4-mysql
Nginx 設定檔修改範例:
sudo nano /etc/nginx/sites-available/example.com
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/html;
index index.html index.htm index.php;
location / {
try_files uriuri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
Enjoy ~