劍閣網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)建站!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)建站公司2013年成立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)建站。
------------- LNMP + Discuz -------------
系統(tǒng)環(huán)境: RHEL6 x32 selinux and iptables disabled
主機(jī)角色: 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\ #數(shù)據(jù)庫存放目錄
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock\ #Unix socket文件路徑
-DWITH_MYISAM_STORAGE_ENGINE=1\ #安裝Myisam存儲(chǔ)引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1\ #安裝Innodb存儲(chǔ)引擎
-DDEFAULT_CHARSET=utf8\ #使用Utf8字符
-DDEFAULT_COLLATION=utf8_general_ci\ #校驗(yàn)字符
-DEXTRA_CHARSETS=all #安裝所有擴(kuò)展字符集
安裝:
make && makeinstall
注意:這一步若有報(bào)錯(cuò),清除舊的對象文件和緩存信息,重新編譯(先make clean,再rm -f CmakeCache.txt,之后再開始編譯)
進(jìn)入到/root/,添加環(huán)境變量:
vi .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
使更改生效:
source .bash_profile
查看剛剛添加的環(huán)境變量:
which mysql
/usr/local/lnmp/mysql/bin/mysql
創(chuàng)建mysql用戶:
groupadd -g 27 mysql
useradd -u 27 -g 27 -s/sbin/nologin -d /usr/local/lnmp/mysql/ -M mysql
初始化數(shù)據(jù)庫:
cd /usr/local/lnmp/mysql/
scripts/mysql_install_db--user=mysql --basedir=/usr/local/lnmp/mysql
--datadir=/usr/local/lnmp/mysql/data
顯示2個(gè)ok表示安裝成功
更改權(quán)限:
chown root . -R
chgrp mysql . -R
chown mysql data/ -R
復(fù)制配置文件及啟動(dòng)腳本到指定位置:
cpsupport-files/my-medium.cnf /etc/my.cnf
cpsupport-files/mysql.server /etc/init.d/mysqld
啟動(dòng)mysql服務(wù):
/etc/init.d/mysqld start
安裝mysql:
mysql_secure_installation
Enter current password for root (enter for none):
Change the root password? [Y/n] n #若當(dāng)前root有數(shù)據(jù)庫的密碼則輸入,沒有按回車
... skipping.
Remove anonymous users? [Y/n] y #移除匿名用戶
... Success!
Disallow root login remotely? [Y/n] y #不允許root遠(yuǎn)程登錄
... Success!
Remove test database and access to it? [Y/n] y #移除test數(shù)據(jù)庫
Reload privilege tables now? [Y/n] y #重新加載數(shù)據(jù)庫權(quán)限
... Success!
登錄mysql驗(yàn)證:
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安裝
安裝開發(fā)包:
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
鏈接方便調(diào)用和修改:
cd/usr/local/lnmp/nginx/sbin
ln -s/usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin
檢測語法,開啟nginx服務(wù),加載配置文件:
nginx -t
nginx
nginx -s reload
查看80端口是否打開并檢測(此時(shí)要確保httpd服務(wù)是關(guān)閉的):
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
此時(shí)可以使用瀏覽器訪問,我在實(shí)驗(yàn)中訪問的是:172.25.46.1,顯示頁面如下:
更改用戶及進(jìn)程數(shù):
cd /usr/local/lnmp/nginx/conf/
vi nginx.conf
#user nginx; #更改用戶為nginx
worker_processes 2; #進(jìn)程數(shù)改為2
重載文件并查看端口:
nginx -s reload
netstat -antlp
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7060/nginx
開啟了2個(gè)進(jìn)程:
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 #主機(jī)名
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
此時(shí)可使用瀏覽器訪問,實(shí)驗(yàn)中我訪問的是:https://172.25.46.1,顯示頁面如下
選擇I Understand the Risks,進(jìn)入如下頁面:
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
復(fù)制配置文件及啟動(dòng)腳本到指定位置:
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運(yùn)行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運(yùn)行pid
..........
更改時(shí)區(qū)為亞洲上海:
vim php.ini
..........
[Date]
; Defines the default timezone used by thedate functions
; http://php.net/date.timezone
;date.timezone=Asia/Shanghai
此時(shí)開啟php服務(wù)時(shí)可能會(huì)有報(bào)錯(cuò):
/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的用戶和組(因?yàn)閍pache默認(rèn)id也為48,這樣會(huì)有沖突),新建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服務(wù)便可以成功:
/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
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
此時(shí)可使用瀏覽器訪問,我在實(shí)驗(yàn)中訪問的是:172.25.46.1,頁面顯示如下:
基于lnmp的Discuz論壇
將壓縮包解壓至nginx的發(fā)布目錄下:
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
此時(shí)可使用瀏覽器訪問,實(shí)驗(yàn)中我訪問的是:172.25.46.1/bbs,顯示頁面如下:
選擇我同意進(jìn)入下一步,設(shè)置運(yùn)行環(huán)境:
看到目錄文件的當(dāng)前狀態(tài)顯示為不可寫,需更改目錄及文件權(quán)限:
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
此時(shí)更新一次顯示為可寫,可進(jìn)入下一步,創(chuàng)建數(shù)據(jù)庫:
在填寫信息之前要設(shè)置root用戶密碼及創(chuàng)建數(shù)據(jù)庫discuz
mysql_secure_installation
Enter current password for root (enter fornone): #回車,因?yàn)閯傞_始我沒有設(shè)置root密碼
OK, successfully used password, movingon...
Set root password? [Y/n] y
New password: #輸入密碼
Re-enter new password: #確認(rèn)密碼
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)
設(shè)置好以上信息之后可進(jìn)行創(chuàng)建數(shù)據(jù)庫,頁面如下:
填寫完信息后進(jìn)入下一步,顯示論壇界面如下:
至此完成了基于lnmp的Discuz論壇的搭建!