LNMP架構編譯安裝(Linux、Nginx、Mysql、PHP)
LNMP架構編譯安裝
LNMP架構
LNMP平臺就是Linux、Ngnix、MySQL、PHP的組合架構,需要Linux伺服器、MySQL資料庫、PHP解析環境
Nginx是一個高效能的HTTP和反向代理伺服器,也是一個IMAP/POP3/SMTP代理伺服器。Mysql是一個小型關係型資料庫管理系統。PHP是一種在伺服器端執行的嵌入HTML文件的指令碼語言。
編譯安裝Nginx
[root@localhost ~]# yum -y install gcc gcc-c++ make pcre-devel zlib-devel
[root@localhost ~]# tar zxf nginx-1.12.2.tar.gz
[root@localhost ~]# cd nginx-1.12.2/
[root@localhost nginx-1.12.2]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module ###統計狀態模組
[root@localhost nginx-1.12.2]# make && make install
[root@localhost ~]# useradd -M -s /sbin/nologin nginx ###建立一個不可登入的程式使用者
[root@localhost ~]# ln -s /usr/local/nginx/sbin/nginx /usr/bin ###優化執行路徑
[root@localhost ~]# nginx ###啟動服務
[root@localhost ~]# netstat -anpt | grep nginx ###檢視nginx服務是否開啟
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 16429/nginx: master
[root@localhost ~]# killall -s QUIT nginx ###選項-s QUIT等於-3 停止服務
[root@localhost ~]# netstat -anpt | grep nginx
[root@localhost ~]# killall -s HUP nginx ###選項-s HUP等於-1 重新載入
[root@localhost ~]# netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 16488/nginx: master
[root@localhost ~]# vi /etc/init.d/nginx ###製作管理指令碼
#!/bin/bash
#chkconfig: 35 20 80
#description: nginx server
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
killall -s QUIT $PROG
rm -rf $PIDF
;;
restart)
$0 stop
$0 start
;;
reload)
killall -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|reload|status}"
exit 1
esac
exit 0
[root@localhost ~]# chmod +x /etc/init.d/nginx
[root@localhost ~]# chkconfig --add nginx
[root@server1 ~]# vi /etc/nginx.conf
[root@server1 ~]# nginx -t
語法檢查報錯,原因系統本地開啟資源數預設1024,設定超過預設值
[root@server1 ~]# ulimit -n 檢視開啟資源數
[root@server1 ~]# ulimit -n 65535 >> /etc/rc.local 修改資源數
[root@server1 ~]# ulimit -n
開啟統計模組
[root@server1 ~]# vi /etc/nginx.conf
[root@server1 ~]# systemctl stop nginx
[root@server1 ~]# systemctl start nginx
新增
location ~ /status { 匹配項只要URL路徑中出現/status就會定位到該模組
stub_status on; 功能開啟
access_log off; 不記錄日誌
}
測試驗證
在瀏覽器上進行訪問檢驗
http://192.168.200.40
http://192.168.200.40/status
配置nginx驗證
[root@server1 logs]# yum -y install httpd-tools
[root@server1 logs]# htpasswd -c /usr/local/nginx/passwd.db tg (使用者名稱)
[root@server1 ~]# vi /etc/nginx.conf
auth_basic "secret"; 設定檔案密文顯示
auth_basic_user_file /usr/local/nginx/passwd.db; 使用者檔案指向,生成檔案
[root@server1 ~]# systemctl restart nginx
拒絕訪問:先允許所有,後拒絕指定ip
[root@server1 ~]# vi /etc/nginx.conf
新增::
allow all;
deny 192.168.200.40;
auth_basic "secret";
auth_basic_user_file /usr/local/nginx/passwd.db;
[root@server1 ~]# systemctl restart nginx
配置虛擬主機功能
基於域名
[root@server1 ~]# vi /etc/nginx.conf
#gzip on;
server {
listen 192.168.200.40:80;
server_name www.aa.com;
charset utf-8;
access_log logs/aa.com.access.log main;
location / {
root /var/www/aa;
index index.html index.htm;
}
location ~ /status {
stub_status on;
access_log off;
}
————————————在HTTP中配置————————————————
server {
listen 80; 監聽埠
server_name www.123.com; 主機名
charset utf-8; 字符集
access_log logs/123.com.access.log; 訪問日誌檔案路徑
location / { 站點目錄
root /var/www/ab; 根
index index.html index.htm; 主頁
}
error_page 500 502 503 504 /50x.html; 錯誤日誌
location = /50x.html { 檔名
root html; 檔案路徑
}
}
}
建立主頁:
[root@server1 ~]# mkdir -p /var/www/aa
[root@server1 ~]# mkdir -p /var/www/ab
[root@server1 ~]# echo "<h1>this is aa.</h1>" > /var/www/aa/index.html
[root@server1 ~]# echo "<h1>123abc.</h1>" > /var/www/123/index.html
對映配置:
[root@server1 ~]# vi /etc/hosts
192.168.200.40 www.aa.com www.123.com
基於ip
[root@server1 ~]# ifconfig ens33:1 192.168.200.40/24
root@server1 ~]# vi /etc/nginx.conf
[root@server1 ~]# curl http://192.168.200.40
[root@server1 ~]# curl http://192.168.200.41
基於埠
[root@server1 ~]# vi /etc/nginx.conf
編譯安裝Mysql
[root@server1 ~]# yum -y install ncurses ncurses-devel bison cmake
ncurses ncurses-devel
建立程式使用者
[root@server1 ~]# useradd -s /sbin/nologin mysql
[root@server1 ~]# tar zxvf mysql-boost-5.7.20.tar.gz
[root@server1 ~]# cd mysql-5.7.20/
編輯安裝
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1
[root@localhost mysql-5.7.20]# cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
> -DSYSCONFDIR=/etc \
> -DSYSTEMD_PID_DIR=/usr/local/mysql \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
> -DMYSQL_DATADIR=/usr/local/mysql/data \
> -DWITH_BOOST=boost \
> -DWITH_SYSTEMD=1
[root@localhost mysql-5.7.20]# make && make install
對資料庫目錄進行許可權配置,屬主,屬組
[root@server1 ~]# chown -R mysql.mysql /usr/local/mysql/
[root@localhost ~]# vi /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
設定環境變數
[root@server1 ~]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@server1 ~]# source /etc/profile
[root@server1 ~]# echo $PATH
資料庫初始化設定
[root@server1 ~]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
--initialize-insecure
[root@server1 ~]# cd /usr/local/mysql/
[root@server1 mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system
[root@server1 ~]# systemctl start mysqld
設定資料庫登入密碼
[root@server1 ~]# mysqladmin -uroot -p password '123123'
[root@server1 ~]# mysql -uroot -p
編譯安裝PHP
[root@server1 ~]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel
[root@server1 ~]# tar jvxf php-7.1.10.tar.bz2
[root@server1 ~]# cd php-7.1.10/
[root@server1 php-7.1.10]# ./configure --prefix=/usr/local/php --with-mysql-sock=/usr/local/mysql/mysql.sock --with-mysqli --with-zlib --with-curl --with-gb --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-fpm --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo --enable-tokenizer --enable-zip
配置模組說明
./configure --prefix=/usr/local/php : 安裝路徑
–with-mysql-sock=/usr/local/mysql/mysql.sock :套接字路徑
–with-mysqli : 呼叫mysql儲存過程
–with-zlib : 開啟zlib函式庫
–with-curl : 呼叫curl規則
–with-gb : 影像處理
–with-jpeg-dir : 支援jpeg格式
–with-png-dir : 支援png格式
–with-freetype-dir :開啟字型引擎
–with-openssl : 開啟ssl套接字功能
–enable-fpm : 載入fpm模組
–enable-mbstring 支援utf-8功能
–enable-xml : 支援xml檔案格式
–enable-session : 開啟會話
–enable-ftp : 開啟ftp擴充套件
–enable-pdo : 訪問介面
–enable-tokenizer:分詞器
–enable-zip: 對zip檔案支援
[root@server1 php-7.1.10]# make && make install
[root@server1 ~]# cd php-7.1.10/
[root@server1 php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
[root@server1 php-7.1.10]# vi /usr/local/php/lib/php.ini
配置及優化FPM模組
[root@server1 ~]# cd /usr/local/php/etc
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 etc]# cp www.conf.default www.conf /usr/local/php/etc/php-fpm.d/
[root@server1 etc]# vi php-fpm.conf
取消註釋
pid = run/php-fpm.pid
啟動fpm模組
[root@server1 ~]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
[root@server1 ~]# ln -s /usr/local/php/bin/* /usr/bin
讓nginx支援PHP功能
[root@server1 ~]# vi /etc/nginx.conf
[root@server1 ~]# systemctl restart nginx
建立php網頁
[root@server1 ~]# vi /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
測試驗證
在瀏覽器上訪問:http://192.168.200.40/index.php
配置資料庫
[root@server1 ~]# mysql -uroot -p123123
mysql> create database bbs; 'bbsuser'@'localhost' identified by 'admin123';
mysql> grant all privileges on bbs.* to 'bbsuser'@'%' identified by 'admin123';
mysql> flush privileges;
mysql> exit
配置php網頁
[root@server1 ~]# vi /usr/local/nginx/html/index.php
<?php
$link=mysqli_connect ('20.0.0.10','bbsuser','admin123');
if($link) echo "<h1>Wa~~~</h1>";
else echo "Fail!!";
?>
在瀏覽器上訪問: http://192.168.200.40/index.php
部署Discuz論壇搭建
[root@server1 ~]# ls -lh
[root@server1 ~]# unzip Discuz_X3.4_SC_UTF8.zip
[root@server1 ~]# cd dir_SC_UTF8/
[root@server1 dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs
[root@server1 dir_SC_UTF8]# cd /usr/local/nginx/html/bbs/
[root@server1 bbs]# chown -R root.nginx ./config/
[root@server1 bbs]# chown -R root.nginx ./data/
[root@server1 bbs]# chown -R root.nginx ./uc_client/
[root@server1 bbs]# chown -R root.nginx ./uc_server/
[root@server1 bbs]# chmod -R 777 ./config/
[root@server1 bbs]# chmod -R 777 ./data/
[root@server1 bbs]# chmod -R 777 ./uc_client/
[root@server1 bbs]# chmod -R 777 ./uc_server/
測試驗證
在瀏覽器上訪問
http://192.168.200.
40/bbs/install/index.php
設定安裝目錄
[root@server1 ~]# cd /usr/local/nginx/html/bbs/
[root@server1 bbs]# mv install/ install.lock
[root@server1 bbs]# chmod 600 install.lock/
[root@server1 bbs]# ls -lh
相關文章
- 編譯安裝nginx-php-mysql編譯NginxPHPMySql
- Linux編譯安裝NginxLinux編譯Nginx
- php環境篇:linux編譯安裝nginx1.13.2PHPLinux編譯Nginx
- CentOS 7 利用yum安裝lnmp的教程(Linux+Nginx+PHP7.1+Mysql5.7)CentOSLNMPLinuxNginxPHPMySql
- centos 7 伺服器安裝LNMP環境 (Linux+Nginx+Mysql8+PHP)CentOS伺服器LNMPLinuxNginxMySqlPHP
- Linux 編譯 安裝 PHP 7.3.1Linux編譯PHP
- 1.8LNMP環境編譯安裝php-5.6.14LNMP編譯PHP
- 【MySQL安裝】Linux下安裝MySQL(預編譯)MySqlLinux編譯
- Docker安裝LNMP-ubuntu18.04+nginx1.14+mysql5.7+php7.3DockerLNMPUbuntuNginxMySqlPHP
- LNMP--mysql php安裝配置LNMPMySqlPHP
- PHP Linux安裝擴充套件(編譯安裝)PHPLinux套件編譯
- 基於centos7進行yum安裝lnmp linux+nginx+php7.1+mysql5.7CentOSLNMPLinuxNginxPHPMySql
- CentOS 下編譯安裝 PHP7.2(nginx 版)CentOS編譯PHPNginx
- Linux下安裝Nginx+PHP7.1+MySQL5.7LinuxNginxPHPMySql
- CentOS 7.2 下編譯安裝PHP7.0.10+MySQL5.7.14+Nginx1.10.1的方法CentOS編譯PHPMySqlNginx
- CentOS6.9原始碼編譯安裝nginx+php7+mysql環境CentOS原始碼編譯NginxPHPMySql
- Shell編譯安裝nginx編譯Nginx
- LNMP網站框架搭建(編譯安裝)LNMP網站框架編譯
- Linux下nginx編譯安裝教程和編譯引數詳解LinuxNginx編譯
- Nginx1.19 php8.0 原始碼編譯安裝NginxPHP原始碼編譯
- httpd編譯安裝phphttpd編譯PHP
- centos PHP 編譯安裝CentOSPHP編譯
- CentOS 下編譯安裝 NginxCentOS編譯Nginx
- macOS nginx 編譯安裝教程MacNginx編譯
- Nginx 實踐案例(原始碼編譯安裝方式):利用LNMP搭建wordpress站點Nginx原始碼編譯LNMP
- Linux下編譯安裝nginx1.8.1伺服器Linux編譯Nginx伺服器
- Docker環境下編譯安裝PHP7.1.4 Nginx1.12.0Docker編譯PHPNginx
- PHP7 編譯安裝PHP編譯
- 記錄 Ubuntu18.04 lnmp nginx1.14 PHP7.2 MySQL5.7 安裝 配置UbuntuLNMPNginxPHPMySql
- hi-nginx-1.3.4編譯安裝Nginx編譯
- nginx 編譯安裝與配置使用Nginx編譯
- Linux 編譯安裝 PythonLinux編譯Python
- ffmpeg安裝之linux編譯安裝Linux編譯
- Debian9(Stretch) 下編譯安裝LNMP環境編譯LNMP
- Debian9 (Stretch) 下編譯安裝 LNMP 環境編譯LNMP
- Centos 編譯安裝 PHP7.4.7CentOS編譯PHP
- Cnetos7編譯安裝Nginx教程。編譯Nginx
- nginx原始碼編譯安裝(詳解)Nginx原始碼編譯