底下紀錄如何在 Ubuntu 18.04 上建立 LEMP 的環境。
This note demonstrates how to create a LEMP environment on an Ubuntu 18.04 server.
步驟一:安裝 Nginx Web Server (Step One: Installing nginx web server)
Open a console and input the following commands to install nginx.- sudo apt-get update
- sudo apt-get install nginx
接著查詢主機IP
You can find your server's public IP address by the following command:
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
在瀏覽器鍵入 local host ip。
Type the address in your web browser(Google chrome or firefox .etc).
http://server_domain_name_or_IP
若在瀏覽器上看到下圖,表示 nginx 已安裝成功。If you see the below message, your nginx installation is completed.
可看到上圖時,nginx便已經可跑靜態網頁了,預設的html檔案存放位置為 /var/www/htmlType the address in your web browser(Google chrome or firefox .etc).
http://server_domain_name_or_IP
步驟二:安裝MySql(Step Two: Installing mysql
Open a console and input the following commands to install mysql.
sudo apt-get install mysql-server
安裝完後輸入以下指令進行安全性設定Type the following command to secure the MySQL installation:
sudo mysql_secure_installation
步驟三:安裝php與設定 php.ini(Step Three: Installing php and configuring the php.ini)
Installing php:
;cgi.fix_pathinfo=1
with
cgi.fix_pathinfo=0
Save and restart php service:
sudo apt-get install php-fpm php-mysql
Modifying php.ini file:sudo nano /etc/php/7.2/fpm/php.iniReplace this line:
;cgi.fix_pathinfo=1
with
cgi.fix_pathinfo=0
Save and restart php service:
sudo service php7.2-fpm restart
Create the configuration file for nginx:
sudo nano /etc/nginx/sites-available/test.comInput the below text to the configuration file:
server {
listen 80;
root /var/www/html;
index index.php index.html index.htm;
server_name test.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
步驟五:建立php測試檔案(Step Five: Create a php file to test)# Creating a symbolic link to enable the new server block. sudo ln -s /etc/nginx/sites-available/test.com /etc/nginx/sites-enabled/ # Unlink the default configuration sudo unlink /etc/nginx/sites-enabled/default # Checking the new configuration file sudo nginx -t # Reload Nginx sudo service nginx reload
# Creating the test php file sudo nano /var/www/html/info.phpInput the following php code into the new file(info.php).
<?php phpinfo();
http://your_server_domain_or_IP/info.php
參考資料:
沒有留言:
張貼留言