您好,登錄后才能下訂單哦!
------------- LNMP + Discuz -------------
系統環境: RHEL6 x32 selinux and iptables disabled
主機角色: 172.25.46.1 nginx+mysql+php+Discuz
Mysql安裝
軟件包依賴性:
yum install -y gcc gcc-c++make ncurses-devel bison openssl-devel zlib-devel cmake
解壓:
tar zxf mysql-5.5.12.tar.gz
cd mysql-5.5.12
編譯:
cmake-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql\ #安裝目錄
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data\ #數據庫存放目錄
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock\ #Unix socket文件路徑
-DWITH_MYISAM_STORAGE_ENGINE=1\ #安裝Myisam存儲引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1\ #安裝Innodb存儲引擎
-DDEFAULT_CHARSET=utf8\ #使用Utf8字符
-DDEFAULT_COLLATION=utf8_general_ci\ #校驗字符
-DEXTRA_CHARSETS=all #安裝所有擴展字符集
安裝:
make && makeinstall
注意:這一步若有報錯,清除舊的對象文件和緩存信息,重新編譯(先make clean,再rm -f CmakeCache.txt,之后再開始編譯)
進入到/root/,添加環境變量:
vi .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
使更改生效:
source .bash_profile
查看剛剛添加的環境變量:
which mysql
/usr/local/lnmp/mysql/bin/mysql
創建mysql用戶:
groupadd -g 27 mysql
useradd -u 27 -g 27 -s/sbin/nologin -d /usr/local/lnmp/mysql/ -M mysql
初始化數據庫:
cd /usr/local/lnmp/mysql/
scripts/mysql_install_db--user=mysql --basedir=/usr/local/lnmp/mysql
--datadir=/usr/local/lnmp/mysql/data
顯示2個ok表示安裝成功
更改權限:
chown root . -R
chgrp mysql . -R
chown mysql data/ -R
復制配置文件及啟動腳本到指定位置:
cpsupport-files/my-medium.cnf /etc/my.cnf
cpsupport-files/mysql.server /etc/init.d/mysqld
啟動mysql服務:
/etc/init.d/mysqld start
安裝mysql:
mysql_secure_installation
Enter current password for root (enter for none):
Change the root password? [Y/n] n #若當前root有數據庫的密碼則輸入,沒有按回車
... skipping.
Remove anonymous users? [Y/n] y #移除匿名用戶
... Success!
Disallow root login remotely? [Y/n] y #不允許root遠程登錄
... Success!
Remove test database and access to it? [Y/n] y #移除test數據庫
Reload privilege tables now? [Y/n] y #重新加載數據庫權限
... Success!
登錄mysql驗證:
mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
..........
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.04 sec)
Nginx安裝
安裝開發包:
yum install -y pcre-devel openssl-devel
解壓源碼包并編輯文件隱藏nginx版本:
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
vim auto/cc/gcc
#CFLAGS=”$CFLAGS -g” #注釋掉這行,去掉debug模式編譯,編譯以后程序只有幾百k
vim src/core/nginx.h
#define NGINX_VERSION "1.8.0”
#defineNGINX_VER "nginx" #修改此行,去掉后面的“NGINX_VERSION”,為了安全,這樣編譯后外界無法獲取nginx的版本號
編譯并安裝:
./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module
make && makeinstall
鏈接方便調用和修改:
cd/usr/local/lnmp/nginx/sbin
ln -s/usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin
檢測語法,開啟nginx服務,加載配置文件:
nginx -t
nginx
nginx -s reload
查看80端口是否打開并檢測(此時要確保httpd服務是關閉的):
netstat -antlp
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7060/nginx
curl -I localhost
HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Wed, 13 Jan 2016 08:42:21 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 13 Jan 2016 08:31:20 GMT
Connection: keep-alive
ETag: "56960b58-264"
Accept-Ranges: bytes
此時可以使用瀏覽器訪問,我在實驗中訪問的是:172.25.46.1,顯示頁面如下:
更改用戶及進程數:
cd /usr/local/lnmp/nginx/conf/
vi nginx.conf
#user nginx; #更改用戶為nginx
worker_processes 2; #進程數改為2
重載文件并查看端口:
nginx -s reload
netstat -antlp
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7060/nginx
開啟了2個進程:
ps -ax
7104 ? S 0:00 nginx: worker process
7105 ? S 0:00 nginx: worker process
生成key:
cd /etc/pki/tls/certs/
make nginx.pem
Country Name (2 letter code) [XX]:CN #國家,大寫
State or Province Name (full name) []:Shanxi #省
Locality Name (eg, city) [Default City]:xi'an #市
Organization Name (eg, company) [Default CompanyLtd]:westos #組織名
Organizational Unit Name (eg, section) []:Linux #組織單元
Common Name (eg, your name or your server's hostname)[]:server1.example.com #主機名
Email Address []:742019722@qq.com #郵箱
將key加入配置文件:
mv nginx.pem/usr/local/lnmp/nginx/conf/
cd/usr/local/lnmp/nginx/conf/
vim nginx.conf
http{
.......
# HTTPS server
#
server {
listen 443 ssl;
server_name localhost;
ssl_certificate nginx.pem; #更改此處
ssl_certificate_key nginx.pem; #更改此處
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location/ {
root html;
index index.html index.htm;
}
}
}
重載文件查看端口:
nginx -s reload
netstat -antlp
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 7060/nginx
此時可使用瀏覽器訪問,實驗中我訪問的是:https://172.25.46.1,顯示頁面如下
選擇I Understand the Risks,進入如下頁面:
Php安裝
安裝軟件包依賴:
yum install -y pcre-devel openssl-devel libxml2-devel curl-devel libjpeg-turbo-devel.x86_64 libpng-devel gpm.h mcrypt.hnet-snmp-devel freetype-devel gmp-devel-* libjpeg-*
解壓源碼包并編譯安裝:
tar jxf php-5.4.36.tar.bz2
cd php-5.4.36
./configure --prefix=/usr/local/lnmp/php--with-config-file-path=/usr/local/lnmp/php/etc--with-mysql=/usr/local/lnmp/mysql/--with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config --with-openssl --with-snmp --with-gd--with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --without-pear--with-gettext --with-gmp --enable-inline-optimization --enable-soap--enable-ftp --enable-sockets --enable-mbstring --enable-fpm -- --with-fpm-user=nginx--with-fpm-group=nginx --with-mhash
make && make install
復制配置文件及啟動腳本到指定位置:
cpphp.ini-production /usr/local/lnmp/php/etc/php.ini
cd sapi/fpm
cp init.d.php-fpm /etc/init.d/fpm
chmod +x /etc/init.d/fpm
編輯php-fpm.conf文件打開php運行pid
cd /usr/local/lnmp/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
...........
[global]
; Pid file
; Note: the default prefix is/usr/local/lnmp/php/var
; Default Value: none
pid = run/php-fpm.pid #打開php運行pid
..........
更改時區為亞洲上海:
vim php.ini
..........
[Date]
; Defines the default timezone used by thedate functions
; http://php.net/date.timezone
;date.timezone=Asia/Shanghai
此時開啟php服務時可能會有報錯:
/etc/init.d/fpm start
Starting php-fpm [14-Jan-2016 15:52:53]ERROR: [pool www] cannot get uid for user 'nginx'
[14-Jan-2016 15:52:53] ERROR: FPMinitialization failed
刪除id為48的用戶和組(因為apache默認id也為48,這樣會有沖突),新建nginx用戶:
groupadd -g 48 nginx
useradd -u 48-g 48 -s /sbin/nologin -d /usr/local/lnmp/nginx/ -M nginx
id nginx
uid=48(nginx) gid=48(nginx) groups=48(nginx)
再次開啟php服務便可以成功:
/etc/init.d/fpm start
Starting php-fpm done
/etc/init.d/fpmreload
Reload service php-fpm done
編寫php測試頁:
cd /usr/local/lnmp/nginx/html
vim index.php
<?php
phpinfo()
?>
檢測語法并重載:
nginx -t
nginx -s reload
添加cgi支持php:
vim /usr/local/lnmp/nginx/conf/nginx.conf #行號大致如下,不一定與你的完全一樣
48 location / {
49 root html;
50 index index.php index.htmlindex.htm; #添加index.php為首頁
51 }
..........
70 location ~ \.php$ {
71 root html;
72 fastcgi_pass 127.0.0.1:9000;
73 fastcgi_index index.php;
74 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; #注釋此行
75 include fastcgi.conf; #更改文件后綴為.conf
76 }
檢測語法查看端口:
nginx -t
nginx -s reload
netstat -antlp
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1354/nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1354/nginx
此時可使用瀏覽器訪問,我在實驗中訪問的是:172.25.46.1,頁面顯示如下:
基于lnmp的Discuz論壇
將壓縮包解壓至nginx的發布目錄下:
yum install -y unzip
unzip Discuz_X2.5_SC_UTF8.zip -d /usr/local/lnmp/nginx/html/
重命名upload目錄為bbs,便于訪問:
mv /usr/local/lnmp/nginx/html/upload /usr/local/lnmp/nginx/html/bbs
此時可使用瀏覽器訪問,實驗中我訪問的是:172.25.46.1/bbs,顯示頁面如下:
選擇我同意進入下一步,設置運行環境:
看到目錄文件的當前狀態顯示為不可寫,需更改目錄及文件權限:
cd /usr/local/lnmp/nginx/html/bbs
chmod 777 config/ -R
chmod 777 data/ -R
chmod 777 data/ uc_server/ -R
chmod 777 data/ uc_client/ -R
此時更新一次顯示為可寫,可進入下一步,創建數據庫:
在填寫信息之前要設置root用戶密碼及創建數據庫discuz
mysql_secure_installation
Enter current password for root (enter fornone): #回車,因為剛開始我沒有設置root密碼
OK, successfully used password, movingon...
Set root password? [Y/n] y
New password: #輸入密碼
Re-enter new password: #確認密碼
Password updated successfully!
Remove anonymous users? [Y/n] y
...Success!
Disallow root login remotely? [Y/n] y
...Success!
Remove test database and access to it?[Y/n] y
-Dropping test database...
Reload privilege tables now? [Y/n] y
...Success!
mysql –p+密碼
mysql> create database discuz;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| discuz |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
設置好以上信息之后可進行創建數據庫,頁面如下:
填寫完信息后進入下一步,顯示論壇界面如下:
至此完成了基于lnmp的Discuz論壇的搭建!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。