LNMP的搭建

 

1、下載安裝MySQL

1.1:下載地址:https://dev.mysql.com/downloads/mysql/

1.2:安裝後

  1.2.1:解壓:tar -xf mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz 

  1.2.2:重命名:mv mysql-8.0.15-linux-glibc2.12-x86_64 mysql-8.0.15

  1.2.3:建立軟鏈接:ln -n mysql-8.0.15 mysql

  1.2.4:建立mysql用戶和組

    groupadd mysql  # 建立組php

    useradd -r -g mysql mysql   # 建立用戶html

  1.2.5:更改MySQL文件的屬組合屬主

    chown -R mysql:mysql

  1.2.6:初始化數據庫

    /application/mysql/bin/mysqld –initialize –user=mysql –basedir=/application/mysql –datadir=/application/mysql/datamysql

  1.2.7:建立配置文件

    ①touch /application/mysql/super_file/my-default.cnf /etc/my.cnflinux

    ②修改配置文件nginx

[root@redhat ~]#vim /etc/my.cnf
[mysqld]
#skip-grant-tables
basedir = /application/mysql
datadir = /application/mysql/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

   1.2.8:/application/mysql/super)file/mysql.server 文件是MySQL的啓動腳本,將裏邊的文件路徑作下修改,該文件能夠直接啓動,能夠作如下配置

    cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld  # 複製啓動腳本程序員

    sed -i 's@/usr/local/mysql@/application/mysql@g' /etc/init.d/mysqld  # 修改配置文件裏邊的路徑,由於文件中默認配置的MySQL路徑爲/usr/local/mysql算法

     chmod +x /etc/init.d/mysqld  # 添加執行權限sql

    chkconfig --add mysqld  # 添加系統服務數據庫

    systemctl start mysqld  # 啓動MySQLvim

1.3:登陸MySQL,修改密碼

  1.3.1:修改密碼

    ①添加MySQL的環境變量:echo PATH=${PATH}:/application/mysql/bin/  >> /etc/profile

    ②進入數據庫:mysql -uroot -p,若是你記得初始化的時候生成的密碼,那麼你如今就能夠登陸了,若是你不知道,請修改配置文件/etc/my.cnf,將#skip-grant-tables前邊的井號去除便可

    ③修改密碼

use mysql;     //切換數據庫
update user set authentication_string='' where user='root'    //將密碼清空
ALTER user 'root'@'localhost' IDENTIFIED BY 'dongdaxuan';    //我修改的密碼是"dongdaxuan",請本身更改密碼

1.4:使用Navicat鏈接,請轉至:MySql 8.0 版本使用navicat連不上解決

2、安裝依賴包

2.1:使用yum安裝基本依賴包

 

  yum -y install zlib-devel libxml2-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd.devel libcurl-devel libxslt-devel libxslt-devel

  yum groupinstall "Development Tools" "Server Platform Development" -y

2.2:上述安裝中會提示沒有包libiconv-devel 、和gd.devel

  2.2.1:安裝libiconv-devel   

    ①下載地址:https://ftp.gnu.org/pub/gnu/libiconv/
     ②編譯安裝
tar xf libiconv-1.15.tar.gz 
cd libiconv-1.15/    
./configure --prefix=/usr/local/libiconv
make && make install 

 

  2.2.1:安裝gd.devel

    ①下載地址:https://www.lanzous.com/i3nz6he
    ②tar xf gd-devel.tar.gz
    ③yum install gd-devel-2.0.35-26.el7.x86_64.rpm

2.3:安裝libmcrypt庫

  2.3.1:這是一個使用動態的模塊化得libmcrypto。libmcrypto對於在程序運行時添加移除算法是有用的

  2.3.2:安裝

     ①下載:https://www.lanzous.com/i3nzbif

    ②:安裝

[root@redhat application]#tar -xf libmcrypt.tar.gz
yum install libmcrypt-devel-2.5.8-13.el7.x86_64.rpm libmcrypt-2.5.8-13.el7.x86_64.rpm

 

2.4:安裝mhash加密擴展庫

  2.4.1:mhash是基於離散數學原理不可逆向的PHP加密方式擴展庫,其在默認狀況下不會開啓。能夠用於建立校驗值、信息摘要、消息認證碼、以及無需原文的關鍵信息保存等。它爲PHP提供了多種散列算法,如md五、sha一、gost等。能夠經過MHASH_hashname()查看其支持的算法有哪些。

  須要注意:

  • 該擴展不能提供最新的散列算法
  • 該擴展結果原則上運算不可逆

  2.4.2:安裝

    ①下載:https://www.lanzous.com/i3nzcha
    ②安裝:
tar -xf mhash.tar.gz 
yum install mhash-0.9.9.9-10.el7.x86_64.rpm

2.5:安裝mcrypt加密擴展庫

  2.5.1:mcrtpt介紹

  • PHP程序員在編寫代碼程序時,除了要保證代碼的高性能以外,還有一點是很是重要的,那就是程序的安全保障,PHP除了本身自帶的加密算法,還有功能更全面的php擴展庫mcrypt和mhash。其中,mcrypt能夠實現加密解密功能,就是將明文加密,也能夠將密文解密還願。

  • mycrpt是PHP重要的加密支持擴展庫,默認不開啓,支持20多種加密和8種加密模式,具體能夠經過algorithms()和mcrypt_list_modes()顯示

  2.5.2:安裝

    ①下載:https://www.lanzous.com/i3nzikj

    ②安裝,(切記安裝此文件的時候請確保上邊的libmcrypt和mhash已經安裝成功,由於本軟件須要依賴他們
tar -xf mcrypt.tar.gz
yum install mcrypt-2.6.8-11.el7.x86_64.rpm 

 

3、安裝php

3.1:下載php:https://www.php.net/downloads.php

3.2:安裝

  ①解壓縮:tar xf php-7.3.4.tar.xz 

  ②進入到目錄,而後開始預編譯[root@redhat application]#cd php-7.3.4/

[root@redhat php-7.3.4]#./configure --prefix=/application/php-7.3.4 --with-iconv-dir=/usr/local/libiconv --with-config-file-path=/application/php-7.3.4/etc --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir --enable-xml --enable-soap --enable-short-tags --enable-static --enable-calendar --with-curl --with-zlib --with-gd --with-pdo-sqlite --with-pdo-mysql --with-mysqli --with-mysql-sock --enable-mysqlnd --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --enable-shmop --with-mhash --enable-zip --with-pcre-regex --with-jpeg-dir --with-png-dir --with-openssl --enable-ftp --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-fpm --with-fpm-user=php --with-fpm-group=php --with-fpm-systemd --disable-fileinfo
[root@redhat php-7.3.4]#ln -s /application/mysql/lib/libmysqlclient.so.21 /usr/lib64/
[root@redhat php-7.3.4]#touch ext/phar/phar.phar
[root@redhat php-7.3.4]#make
[root@redhat php-7.3.4]#make install
[root@redhat php-7.3.4]#/usr/src/php-7.3.4/build/shtool install -c ext/phar/phar.phar /application/php-7.3.4/bin
[root@redhat php-7.3.4]#ln -s -f phar.phar /application/php-7.3.4/bin/phar
root@redhat php-7.3.4]#ln -s -f phar.phar /application/php-7.3.4/bin/phar
[root@redhat php-7.3.4]#ln -s /application/php-7.3.4/ /application/php

  ③報錯問題

報錯 Cannot find OpenSSL's <evp.h>

 執行 yum install openssl openssl-devel

 

報錯 Please reinstall the libcurl distribution

 執行 yum -y install curl-devel

 

錯誤 jpeglib.h not found

 執行 yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y

 和執行 yum install libjpeg-devel

 

錯誤:checking for BZip2 in default path... not found configure: error: Please reinstall the BZip2 distribution 這是bzip2軟件包沒有安裝

 執行 yum install bzip2-devel.x86_64 -y

 

錯誤:configure: error: xpm.h not found.

 執行 yum install libXpm-devel

 

錯誤: Unable to locate gmp.h

 執行 yum install gmp-devel

 

錯誤:Unable to detect ICU prefix or /usr//bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works

 執行 yum install -y icu libicu libicu-devel

 

錯誤:mcrypt.h not found. Please reinstall libmcrypt.

 執行 yum install php-mcrypt libmcrypt libmcrypt-devel


錯誤: configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

 執行 yum install postgresql-devel

 
錯誤: configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

 執行 yum install libxslt-devel

錯誤:checking for libzip... not found
configure: error: Please reinstall the libzip distribution

    執行 (1)移除舊的libzip:

  yum remove libzip

(2)安裝新版本:

  curl-O https://libzip.org/download/libzip-1.5.1.tar.gz

  tar -zxvf libzip-1.5.1.tar.gz

  cd libzip-1.5.1

  mkdir build

  cd build

  cmake ..

  make && make install
  cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

 

4、配置PHP引擎配置文件php.ini

4.1:複製php.ini文件,和建立php.fpm.conf

[root@redhat php-7.3.4]#cp php.ini-production /application/php/lib/php.ini
[root@redhat php-7.3.4]#cd /application/php/etc/
[root@redhat etc]#cp php-fpm.conf.default php-fpm.conf
[root@redhat ~]#cd /application/php/etc/php-fpm.d/
[root@redhat ~]#chown nginx: /application/php -R
[root@redhat ~]# vim /application/php/etc/php-fpm.d/www.conf
user = nginx  # 修改user
group = nginx  # 修改組

 

4.2:[root@redhat ~]#/application/php/sbin/php-fpm 啓動

  [root@redhat ~]#ss -tunl  # 查看是否啓動

  tcp LISTEN 0 128 127.0.0.1:9000 *:*  # 已經啓動了9000端口

5、Nginx經過fastcgi鏈接php、數據庫

5.1:fastcgi

 

5.2:鏈接php

  5.2.1:配置

[root@redhat ~]#vim /usr/local/nginx/conf/extra/N1.conf         //編輯虛擬主機文件
location ~ .*\.(php|php5)?$ {        //匹配全部php結尾的訪問
                fastcgi_pass 127.0.0.1:9000; 
                fastcgi_index index.php;
                include fastcgi.conf;
        }

[root@redhat ~]#/usr/local/nginx/sbin/nginx -t    //檢查語法
nginx: the configuration file /usr/local/nginx-1.10.1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.10.1/conf/nginx.conf test is successful
[root@redhat ~]#/usr/local/nginx/sbin/nginx -s reload  //從新啓動

[root@redhat ~]#echo -e "<?php\nphpinfo();\n?> /var/www/html/www/index.php  //php函數,用於查看php

   5.2.2:驗證是php是否鏈接成功,如圖所示,就是成功鏈接

 

5.3:鏈接數據庫,本測試方式適用於7.0以上版本

[root@redhat ~]#vim /var/www/html/www/index.php
<?php
$link_id=mysqli_connect('localhost:3306','root','dongdaxuan') or mysql_error();
if($link_id) {
        echo "mysql succesful by QQ:920506213";
} else {
        echo mysql_error();
}                                                                                          
?>

 

 瀏覽器進行訪問,出現如下信息就是鏈接成功

 

 

 5.4:部署一個blog程序服務

  5.4.1:Wordpress下載:https://www.lanzous.com/i3oqwlg

  5.4.2:配置Wordpress步驟

    ①切換目錄:[root@redhat ~]#cd /var/www/html/blog/

    ②解壓:[root@redhat blog]#tar -xf latest-zh_CN.tar.gz 

    ③將解壓的文件中的全部文件移至blog目錄下:[root@redhat blog]#mv wordpress/* ./

  5.4.3:配置blog虛擬主機文件

    

[root@redhat blog]#vim /usr/local/nginx/conf/extra/blog.conf 
server {
        listen 80;
        server_name blog.p-pp.cn;
        root /var/www/html/blog;
        location / {
                index index.html index.php;                                                            
        }
 location ~ .*\.(php|php5) {        //添加了這個location
                fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; }
}
[root@redhat ~]#/usr/local/nginx/sbin/nginx -t    //檢查語法
nginx: the configuration file /usr/local/nginx-1.10.1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.10.1/conf/nginx.conf test is successful
[root@redhat ~]#/usr/local/nginx/sbin/nginx -s reload  //從新啓動

 

  5.4.4:在數據庫中建立Wordpress的專用數據庫

[root@redhat blog]#mysql -uroot -p
mysql> create database wordpress;

  5.4.5:瀏覽器訪問而後一步一步配置便可(/var/www/html/blog這個文件夾須要有nginx用戶的寫入權限)!!!!!!

相關文章
相關標籤/搜索