您好,登錄后才能下訂單哦!
LNMP代表的就是:Linux系統下Nginx+MySQL+PHP這種網站服務器架構。
Linux是一類Unix計算機操作系統的統稱,是目前最流行的免費操作系統。代表版本有:debian、centos、ubuntu、fedora、gentoo等。
Nginx是一個高性能的HTTP和反向代理服務器,也是一個IMAP/POP3/SMTP代理服務器。
Mysql是一個小型關系型數據庫管理系統。
PHP是一種在服務器端執行的嵌入HTML文檔的腳本語言。
這四種軟件均為免費開源軟件,組合到一起,成為一個免費、高效、擴展性強的網站服務系統
本章,就帶大家一起來進行LNMP的手工編譯。
實驗步驟為四步:
安裝nginx服務
安裝mysql服務
安裝配置PHP解析環境
部署discuz社區論壇web應用
實驗環境:centos7.5 ? nginx-1.12 ?mysql-boot-5.7 ? ?php-7.1
實驗開始
【安裝nginx服務】
1、安裝環境依賴安裝包:
[root@localhost?~]#?yum?-y?install?pcre-devel?zlib-devel?gcc?gcc-c++
2、創建運行用戶、組
[root@localhost?~]#?useradd?-M?-s?/sbin/nologin?nginx
3、解壓安裝包
tar?zxvf?nginx-1.12.2.tar.gz?-C?/opt/
4、編譯安裝及配置優化
cd?nginx-1.12.2/ ./configure?\ --prefix=/usr/local/nginx?\ --user=nginx?\ --group=nginx?\ --with-http_stub_status_module?????????????????????????????? ?make?&&?make?install???????????????????????????????????????????????????//編譯安裝nginx ln?-s?/usr/local/nginx/sbin/nginx?/usr/local/sbin/?????????????????//創建命令的軟連接 systemctl?stop?firewalld.service????????????????????????????????????????????//關閉防火墻 setenforce?0??? nginx?-t?????????????????????????????????????????????????????????????????????//檢查配置文件是否有問題 方便管理nginx服務,編輯nginx服務腳本,將其添加到systemctl服務中 vim?/lib/systemd/system/nginx.service [Unit] Description=nginx After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/bin/kill?-s?HUP?$MAINPID ExecStop=/usr/bin/ki11?-s?QUIT?$MATNPID PrivateTmp=true [Install] WantedBy=multi-user.target chmod?754?nginx.service???????//賦予執行權限
【安裝mysql服務】
1、安裝編譯工具
yum?-y?install?\ ncurses?\ ncurses-devel?\ bison?\ cmake\ make
2、解壓縮包
tar?zxvf?mysql-boost-5.7.20.tar.gz?-C?/opt
3、定制配置
cd?/opt/my 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??????????????????????//5.7版本必須添加這個參數
4、編譯安裝
make?&&?make?install
5、添加程序用戶,及權限相關設置
useradd?-s?/sbin/nologin?mysql chown?-R?mysql:mysql?/usr/local/mysql/????????????????//設置屬主屬組
6、修改配置文件(刪除原內容,復制下列內容) ? ?
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
7、設置環境變量
echo?'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH'?>>?/etc/profile echo?'export?PATH'?>>?/etc/profile source?/etc/profile
8、初始化數據庫
cd?/usr/local/mysql/ bin/mysqld?\ --initialize-insecure?\ --user=mysql?\ --basedir=/usr/local/mysql?\ --datadir=/usr/local/mysql/data cp?usr/lib/systemd/system/mysqld.service?/usr/lib/systemd/system/
9、數據庫開啟自啟、關閉、狀態
systemctl?enable?mysqld systemctl?start?mysqld systemctl?stop?mysqld netstat?-natp?|?grep?3306
10、設置密碼
mysqladmin?-uroot?-p?password?????????????????? mysql?-u?root?-p???????????????????//進入數據庫
【安裝PHP服務】
1、安裝環境依賴包
yum?install?-y?\ libjpeg?\ libjpeg-devel?\ libpng?libpng-devel?\ freetype?freetype-devel?\ libxml2?\ libxml2-devel?\ zlib?zlib-devel?\ curl?curl-devel?\ openssl?openssl-devel
2、解壓安裝包
tar?jxvf?php-7.1.10.tar.bz?-C?/opt
3、定制配置
cd?/opt/php-7.1.10 ./configure?\ --prefix=/usr/local/php?\ --with-mysql-sock=/usr/local/mysql/mysql.sock?\ --with-mysqli?\ --with-zlib?\ --with-curl?\ --with-gd?\ --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
4、修改配置文件
//php有三個配置文件:
php.ini ? ? ? ? ? ? ? ? ? ? ?//核心配置文件
php-fpm.conf ? ? ? ? ? //進程服務配置文件
www.conf ? ? ? ? ? ? ? ?//擴展配置文件
cp?php.ini-development?/usr/local/php/lib/php.ini?????????????//配置核心模塊 vim?/usr/local/php/lib/php.ini mysqli.default_socket?=?/usr/local/mysql/mysql.sock date.timezone?=?Asia/Shanghai?????????????????????????????????//設置路徑,及時區 /usr/local/php/bin/php?-m????????????????//驗證安裝模塊
?
配置及優化fpm模塊
cd?/usr/local/php/etc/ cp?php-fpm.conf.default?php-fpm.conf vim?php-fpm.conf pid?=?run/php-fpm.pid??????????????//去掉;注釋??開啟pid cd?/usr/local/php/etc/php-fpm.d/ cp?www.conf.default?www.conf /usr/local/php/sbin/php-fpm?-c?/usr/local/php/lib/php.ini?????????//開啟php-fpm模塊 netstat?-natp?|?grep?9000 ln?-s?/usr/local/php/bin/*?/usr/local/bin/???????????????????????????//創建軟連接。系統識別命令 ln?-s?/usr/local/php/bin/*?/usr/local/bin/???????????????????????????//創建軟連接。系統識別命令
讓nginx支持php功能
vim?/usr/local/nginx/conf/nginx.conf???????????????//配置文件中有,只需要去掉注釋#修改路徑 ???????????location?~?\.php$?{ ????????????root???????????html; ????????????fastcgi_pass???127.0.0.1:9000; ????????????fastcgi_index??index.php; ????????????fastcgi_param??SCRIPT_FILENAME??/usr/local/nginx/html$fastcgi_script_name; ????????????include????????fastcgi_params; ????????}
5、配置服務首頁信息
killall?-1?nginx????????????????//重啟nginx服務? cd?/usr/local/nginx/html/ mv?index.html?index.php vim?index.php <?php phpinfo(); ?>?????????????????????????????????//原來的內容更改 192.168.109.137/index.php?????????????????????????????//訪問首頁
6、測試數據庫工作是否正常
mysql?-uroot?-p CREATE?DATABASE?bbs; GRANT?all?ON?bbs.*?TO?'bbsuser'?@'%'?IDENTIFIED?BY?'admin123'; GRANT?all?ON?bbs.*?TO?'bbsuser'?@'localhost'?IDENTIFIED?BY?'admin123'; flush?privileges; #回車?????//配置賬號文件 show?databases;????/查看數據庫
7、測試連通性
vi?/usr/local/nginx/html/index.?php ##原來的測試頁內容更改如下 <?php $link=mysqli_connect('192.168.109.137','?bbsadm'?,’admin123')?; if($link)?echo?"<h2>Success!!</h2>"; else?echo?"Fail!!"?; ?> systemctl?restart?nginx 在網頁測試“http://192.168.109.137/index.php"
?
【部署discuz 社區論壇web應用】
unzip?Discuz_X3.4_SC_UTF8.zip?-d?/opt???????????????????##解壓安裝包 cd?/tmp/dir_SC_UTF8/ cp?-r?upload/?/usr/local/nginx/html/bbs ##添加權限,使服務可以安裝 cd?/usr/local/nginx/html/bbs/ chown?-R?root:nginx?./config/ chown?-R?root:nginx?./data/ chown?-R?root:nginx?./uc_client/ chown?-R?root:nginx?./uc_server/ chmod?-R?777?./config/ chmod?-R?777?./data/ chmod?-R?777?./uc_client/ chmod?-R?777?./uc_server/ 192.168.109.137/bbs/install/index.php?????????????????????//權限設置完畢后,進行安裝 192.168.109.137/bbs/index.php???????????????????????????????//安裝完成,登錄使用
LNMP手工編譯全部完成。關于nginx的其他服務可以進我的主頁進行查看
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。