LNMP是Linux+Nginx+Mysql+PHP所構建的一個動態開發環鏡
我這里使用的系統是華為的OpenEnler系統,使用了Nginx1.12版本、Mysql8和PHP7.4
如果有出錯的地方可能是作者沒做到位,見諒
安裝依賴包并安裝nginx:
# mount /dev/cdrom /mnt/ #掛在磁盤
# dnf clean all #清理之前創建的快取
# dnf makecache #創建新快取
# dnf install nginx -y #安裝nginx
# dnf list all | grep nginx #查看安裝的nginx
# systemctl start nginx #啟動nginx
# systemctl enable nginx #設定開機自啟動
# netstat -anlpt | grep nginx #查看nginx行程是否已啟動

# firewall-cmd --permanent --add-service=http #防火墻永久放行http
# firewall-cmd --reload #重繪規則
# firewall-cmd --list-all #查看防火墻

安裝mysql:
# wget http://repo.mysql.com/mysql80-community-release-el8-4.noarch.rpm #下載mysql軟體包
# rpm -ivh mysql80-community-release-el7-4.noarch.rpm #安裝軟體包
# dnf clean all
# dnf makecache #創建新快取
# dnf install mysql-community-server -y #安裝mysql-server
# chown -R mysql:mysql /var/lib/mysql
# systemctl start mysqld #啟動mysql服務
# systemctl enable mysqld #開機自啟動

# firewall-cmd --permanent --add-port=3306/tcp #防火墻放行mysql的3306埠
# firewall-cmd --reload
# firewall-cmd --list-all

# grep "password" /var/log/mysqld.log #查看root用戶的默認密碼
可以看見圖片中root@localhost后面的字符就是密碼了
使用root用戶進入到mysql中

這里進入了之后需要重新設定root用戶的密碼(mysql是有密碼復雜性要求的)

安裝PHP:
# dnf -y install cmake libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libzip libzip-devel libsodium sqlite sqlite-devel oniguruma oniguruma-devel libwebp-devel
# cd /usr/local
# wget https://www.php.net/distributions/php-7.4.9.tar.gz
# tar -xvf php-7.4.9.tar.gz
# cd php-7.4.9
# ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-config-file-scan-dir=/usr/local/php7/etc/php.d --enable-mysqlnd --with-mysqli --with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-gd --with-iconv --with-zlib --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-ftp --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --with-zip --with-jpeg --with-webp --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-freetype --enable-opcache --disable-fileinfo
配置安裝引數,成功后有下圖提示

# make && make install #編譯并安裝
# ln -s /usr/local/php7/bin/php /usr/bin/php #創建鏈接
配置php-fpm開機啟動
# cp php.ini-production /usr/local/php7/etc/php.ini
# cd /usr/local/php7/etc/
# cp php-fpm.conf.default php-fpm.conf
# cp php-fpm.d/www.conf.default php-fpm.d/www.conf
# cp /usr/local/php-7.4.9/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
# systemctl start php-fpm
查看php-fpm的狀態

為了使nginx能與PHP聯動要對nginx的組態檔進行修改、添加內容
vi /etc/nginx/nginx.conf
### 組態檔的原內容
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
### 修改并添加代碼后的檔案內容
server {
listen 80;
listen [::]:80;
server_name 192.168.28.11;
root /usr/share/nginx/html;
# 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 {
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
:wq
nginx -t #檢查組態檔是否有誤,無誤重啟nginx
systemctl restart nginx

為了試驗能不能聯動,在nginx的html目錄中添加info.php檔案
vi /usr/share/nginx/html/info.php
#檔案添加以下內容
<?php
phpinfo();
:wq
然后在你的瀏覽器上輸入 http://ip地址/info.php

那么LNMP已經是成功部署了,可以開始搭建自己喜歡的網站
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/488466.html
標籤:Linux
