LNMP架構的搭建(linux+nginx+mysql+php源碼安裝 )+Discuz論壇的搭建

主機環境 redhat6.5 64位php

實驗環境 服務端 ip172.25.29.1  nginx+mysql+phphtml

安裝包   nginx-1.10.1.tar.gzmysql

        mysql-boost-5.7.11.tar.gznginx

      cmake-2.8.12.2-4.el6.x86_64.rpmc++

php-5.6.20.tar.bz2sql

        re2c-0.13.5-1.el6.x86_64.rpm數據庫

        libmcrypt-2.5.8-9.el6.x86_64.rpmvim

        libmcrypt-devel-2.5.8-9.el6.x86_64.rpmapi

        Discuz_X3.2_SC_UTF8.zip緩存


1. nginx源碼安裝及配置

  1.安裝

[root@server1 mnt]# yum install gcc -y      #安裝gcc

[root@server1 mnt]# tar zxf nginx-1.10.1.tar.gz   #解壓nginx壓縮包

[root@server1 mnt]# ls

nginx-1.10.1  nginx-1.10.1.tar.gz

[root@server1 mnt]# cd nginx-1.10.1

[root@server1 nginx-1.10.1]# vim auto/cc/gcc     #禁止debug調試

 178 # debug

 179#CFLAGS="$CFLAGS -g"

[root@server1 nginx-1.10.1]# vim src/core/nginx.h   #禁止出現nginx版本號,以保證安全性

 14 #defineNGINX_VER          "nginx/"

[root@server1 nginx-1.10.1]# ./configure--prefix=/usr/local/lnmp/nginx --with-http_ssl_module--with-http_stub_status_module

若是出現如下錯誤

wKiom1fg41DyHDBWAABeD17kGi8125.png

[root@server1 nginx-1.10.1]# yum install pcre-devel -y

從新配置

[root@server1 nginx-1.10.1]# ./configure --prefix=/usr/local/lnmp/nginx--with-http_ssl_module --with-http_stub_status_module

若是出現如下錯誤

wKioL1fg41CDDFmHAABXCWcE6pA291.png

[root@server1 nginx-1.10.1]# yum install openssl-devel -y

從新配置

[root@server1 nginx-1.10.1]# ./configure--prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module

[root@server1 nginx-1.10.1]# make

[root@server1 nginx-1.10.1]# make install


    2.將nginx做爲系統變量,開啓nginx

 [root@server1nginx-1.10.1]# cd /usr/local/lnmp/nginx/

[root@server1 nginx]# ls

conf  html  logs sbin

[root@server1 nginx]# ln -s /usr/local/lnmp/nginx/sbin/nginx/usr/local/sbin/  #做軟連接將nginx的啓動命令做爲系統命令

[root@server1 nginx]# nginx -t     #檢測

nginx: the configuration file/usr/local/lnmp/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conftest is successful

[root@server1 nginx]# nginx    #打開nginx

2. mysql的源碼安裝及配置

1.安裝

[root@server1 mnt]#tar zxf mysql-boost-5.7.11.tar.gz  #解壓gz包

[root@server1 mnt]#yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y #安裝cmake

[root@server1 mnt]#cd mysql-5.7.11/

2軟件配置

[root@server1mysql-5.7.11]# 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 \     #安裝全部擴展字符集

>-DWITH_BOOST=boost/boost_1_59_0/  #boost的指定路徑

若是出現以下錯誤

wKiom1fg41GgDmSsAAC_jcCX1JY138.png

[root@server1mysql-5.7.11]# rm -fr CMakeCache.txt   #清空緩存文件

[root@server1mysql-5.7.11]# yum install ncurses-devel gcc-c++ -y  #安裝上圖須要的軟件包

####注意:必定要清空緩存文件

從新配置

[root@server1mysql-5.7.11]# 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-DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all-DWITH_BOOST=boost/boost_1_59_0/

wKioL1fg41GTq2SLAACRyvJa6kY000.png

[root@server1mysql-5.7.11]# yum install bison -y  #系統能夠跳過warning錯誤,此步驟無關緊要

[root@server1 mysql-5.7.11]# make      #編譯,連接,生成可執行文件

[root@server1 mysql-5.7.11]# make install   #安裝

   

   2.mysql的簡單配置

[root@server1 mysql-5.7.11]# cd /usr/local/lnmp/mysql/

[root@server1 mysql]# useradd -u 27  -M -d /usr/local/lnmp/mysql/data -s/sbin/nologin mysql                                    #建立mysql用戶

 [root@server1 mysql]#groupmod -g 27 mysql

[root@server1 mysql]# id mysql

uid=27(mysql) gid=27(mysql) groups=27(mysql)

[root@server1 mysql]# chown mysql.mysql . -R         #修改mysql目錄下文件的權限

[root@server1 mysql]# cp /etc/my.cnf  /mnt/            #備份my.cnf

[root@server1 mysql]# cd support-files/   

[root@server1 support-files]# cp my-default.cnf  /etc/my.cnf  #服務器配置文件

cp: overwrite `/etc/my.cnf'? y

[root@server1 support-files]# cp mysql.server/etc/init.d/mysqld   #添加mysql啓動命令

[root@server1 support-files]# cd ..

[root@server1 mysql]# cd bin/

[root@server1 bin]# pwd

/usr/local/lnmp/mysql/bin

[root@server1 bin]# vim /root/.bash_profile     #將mysql添加到系統的環境變量裏

  10PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin

[root@server1 bin]# source /root/.bash_profile  #刷新環境變量文件

[root@server1 bin]# echo $PATH                  #查看mysql添加到環境變量

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/usr/local/lnmp/mysql/bin

[root@server1 bin]# which mysql        #測試

/usr/local/lnmp/mysql/bin/mysql

[root@server1 ~]# mysqld --initialize --user=mysql    #初始化mysql

wKiom1fg41KwheTGAAHaN19DM00926.png

[root@server1 bin]# cd /usr/local/lnmp/mysql/

[root@server1 ~]# chown root . -R                #改回權限

[root@server1 mysql]# chown mysql data/ -R

[root@server1 ~]# /etc/init.d/mysqld start       #啓動mysql

Starting MySQL. SUCCESS!

 [root@server1 ~]# mysql-p          #登錄mysql

Enter password:        #密碼是上一個截圖裏最後的QV>6!r4LCyjw

wKioL1fg41KxgEflAAFqC5ehiwE727.png

 

3. php的源碼安裝及配置

1.安裝

[root@server1 mnt# tar jxf php-5.6.20.tar.bz2    #解壓

[root@server1 php-5.6.20]# rpm -vih libmcrypt-*   #安裝libmcrypt庫

[root@server1 php-5.6.20]# yum installre2c-0.13.5-1.el6.x86_64.rpm –y   #安裝re2c

[root@server1 php-5.6.20]# ./configure--prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc--with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir--with-png-dir --with-jpeg-dir --with-freetype-dir --with-gettext--without-pear --with-gmp --enable-inline-optimization --enable-soap--enable-ftp --enable-sockets --enable-mbstring --with-mysqli --with-mysql--with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx--with-mcrypt --with-mhash

若是出現以下錯誤wKiom1fg52HxlHWwAAAXa_t5IDE094.png[root@server1 php-5.6.20]# yum install libxml2-devel -y

[root@server1 php-5.6.20]# ./configure--prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc--with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir--with-png-dir --with-jpeg-dir --with-freetype-dir --with-gettext--without-pear --with-gmp --enable-inline-optimization --enable-soap--enable-ftp --enable-sockets --enable-mbstring --with-mysqli --with-mysql--with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx--with-mcrypt --with-mhash

 #####注意:php在加載配置過程當中,如上面會報不少錯誤。有經驗的能夠根據報錯本身去裝所須要的包;新手能夠參考前幾篇博文,安裝所須要的包

[root@server1 php-5.6.20]# make #編譯

[root@server1 php-5.6.20]# make install   #安裝

 

 2.php的配置

[root@server1 php-5.6.20]# cd /usr/local/lnmp/php/etc/

[root@server1 etc]# ls

php-fpm.conf.default

[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf   #備份php的文件

[root@server1 etc]# ls

php-fpm.conf php-fpm.conf.default

[root@server1 etc]# cp /mnt/php-5.6.20/php.ini-productionphp.ini   #php的配置文件

[root@server1 etc]# ls

php-fpm.conf php-fpm.conf.default  php.ini

[root@server1 etc]# vim php.ini

925 date.timezone = Asia/Shanghai          #修改時區

1001 pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock   #指定鏈接數據庫的sock文件的路徑

1150 mysql.default_socket =/usr/local/lnmp/mysql/data/mysql.sock   #同上

1209 mysqli.default_socket =/usr/local/lnmp/mysql/data/mysql.sock   #同上

[root@server1 etc]# vim php-fpm.conf

25 pid = run/php-fpm.pid          #將pid的標記去掉

 

[root@server1 etc]# cd /mnt/php-5.6.20/sapi/fpm/

[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm   #添加啓動命令

[root@server1 fpm]# chmod +x /etc/init.d/php-fpm       #添加可執行權限

[root@server1 fpm]# ll /etc/init.d/php-fpm

-rwxr-xr-x 1 root root 2359 Sep 18 00:18 /etc/init.d/php-fpm

[root@server1 fpm]# /etc/init.d/php-fpm start        #開啓php服務

Starting php-fpm  done

 

[root@server1 fpm]# cd /usr/local/lnmp/nginx/conf/

[root@server1 conf]# vim nginx.conf         

 51             root   html;

 52             index  index.php index.html index.htm;     #在nginx裏添加默認訪問目錄爲php優先

 50         location / {

 

 53         }

 

 75         location ~ \.php$ {

 76             root           html;

 77             fastcgi_pass   127.0.0.1:9000;

 78             fastcgi_index  index.php;

 79             fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

 80             include        fastcgi.conf;         #設置成已存在的文件

 81         }

 

[root@server1 conf]# nginx –t       #檢測

[root@server1 conf]# nginx           #開啓

 

4.搭建bbs論壇

[root@server1 html]# unzip /mnt/Discuz_X3.2_SC_UTF8.zip -d/usr/local/lnmp/nginx/html/              #解壓Discuz包

[root@server1 html]# ls

50x.html  index.html  index.php readme  upload  utility

[root@server1 html]# mv upload/ bbs/       #給upload文件重命名

[root@server1 html]# ls

50x.html  bbs  index.html index.php  readme  utility

[root@server1 html]# chmod 777 -R bbs/     #修改權限

[root@server1 html]# mysql –p           

Enter password:

mysql> grant all on discuz.* to Discuz@localhost identifiedby 'Red+hat888';  #建立能從論壇操做數據庫的數據庫用戶

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit

Bye

[root@server1 html]# cd /usr/local/lnmp/mysql/

[root@server1 mysql]# chmod 755 data/

wKioL1fg41OCYjKBAAHifFbkWIo790.png

wKiom1fg41Tj4wpvAAFScHeXFas589.png

wKioL1fg41SDpfymAADmzmfBUhU595.png              wKiom1fg41XRPG0yAAFW4UmbMcY240.png

     wKioL1fg41aiXTMwAADhmhekTyg130.png

wKiom1fg41bRSnqeAAEctmlRpXg749.png

相關文章
相關標籤/搜索