LNMP是指一組通常一起使用來運行動態網站或者服務器的自由軟體名稱首字母縮寫,L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python,
接上一篇博文
https://blog.csdn.net/qq_50216270/article/details/112533546
上一篇博文已經搭建好了Linux環境并且下載了Nginx,下面配置MySQL和php,從學長那學到的方法,
安裝mysql和php
apt install mysql-server mysql-client #安裝mysql(MariaDB)
mysql #默認無密碼,直接進入mysql命令列
UPDATE mysql.user SET authentication_string = PASSWORD('你的密碼'), plugin = 'mysql_native_password' WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
exit #退出mysql
service mysql restart #重啟mysql
# 因為Debian的阿里倉庫里只有php7.0,下面添加sury軟體源
# 四個命令
apt -y install software-properties-common apt-transport-https lsb-release ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://mirror.xtom.com.hk/sury/php/apt.gpg
sh -c 'echo "deb https://mirror.xtom.com.hk/sury/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
apt-get update #更新軟體源快取
# 下面安裝php7.3
apt install php7.3-fpm php7.3-mysql php7.3-curl php7.3-gd php7.3-mbstring php7.3-xml php7.3-xmlrpc php7.3-zip php7.3-opcache -y
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/7.3/fpm/php.ini #出于安全考慮
配置nginx
注釋掉默認的服務器配置,添加自定義內容,
server {
listen 80 default_server;
listen [::]:80 default_server;
# 這里是本機IP,也可以寫你系結的域名
server_name localhost;
# 定義網站根目錄
root /var/www;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
# 定義首頁索引檔案的名稱
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# PHP 腳本請求全部轉發到 FastCGI處理. 使用FastCGI協議默認配置.
# Fastcgi服務器和程式(PHP,Python)溝通的協議.
location ~ \.php$ {
# 設定監聽埠
fastcgi_pass 127.0.0.1:9000;
# 設定腳本檔案請求的路徑
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 引入fastcgi的組態檔
include fastcgi_params;
}
}
上面設定好了fastcgi去監聽9000埠的php內容,下面修改php的組態檔:
編輯/etc/php/7.3/fpm/pool.d目錄下的www.conf檔案
將listen = balabala 換成 listen = 127.0.0.1:9000
然后重新加載nginx組態檔:
nginx -s reload
重新啟動php-fpm:
service php7.3-fpm restart
下面測驗一下:
在nginx設定好的根目錄/var/www下,新建一個php檔案,內容是:
<?php phpinfo(); ?>`
到瀏覽器訪問一下
這樣LNMP環境就搭建好了
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/248565.html
標籤:其他
