首頁 >後端開發 >php教程 >lnmp搭建(Nginx1.12.1;mysql5.7.20;php7.2.0)

lnmp搭建(Nginx1.12.1;mysql5.7.20;php7.2.0)

不言
不言原創
2018-04-21 16:29:391652瀏覽

這篇文章介紹的內容是關於lnmp搭建(Nginx1.12.1;mysql5.7.20;php7.2.0),有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

安裝依賴套件:

#yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel libpng-devel libjpeg-devel freetype freetype-devel
  • 1

#建立www使用者:

#groupadd www#useradd -g www -s /sbin/nologin -M www
  • 1

  • 2

一、安裝Nginx1.12.1:

centos6.8的鏡像帶的Nginx版本是1.12.1

#yum install -y nginx #/etc/init.d/nginx start
  • 1

  • 2

#二、安裝mysql5.7.20:

#
#wget  
#rpm -Uvh mysql57-community-release-el6-9.noarch.rpm 
#yum install mysql-community-server
#service mysqld start
#grep 'temporary password' /var/log/mysqld.log  | awk '{print $NF}' 
#mysql -uroot -p
mysql>set global validate_password_policy=0;
mysql>set global validate_password_length=6; 
mysql>SET PASSWORD FOR 'root'@'localhost' =PASSWORD('******');

三、安裝PHP7.2.0 
3.1原始碼編譯安裝

#wget rm -php-7.2.0.tar.xz
#tar xvJf php-7.2.0.tar -C /usr/local/
#cd /usr/local/php-7.2.0
#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp  --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts --with-libdir=lib64
# make 
# make install

上面configure步驟,可能會因為缺少依賴套件而報錯,我這台機器安裝過其他一些其他的套件,不同的機器情況可能不一樣,在編譯的時候根據報錯資訊 
用yum search 查找依賴包並安裝,編譯完成之後是沒有error的! ! ! 
make install 完成後也是沒有error的才可以進行後面的步驟。

3.2 設定PHP

#cp /usr/local/php-7.2.0/php.ini-development /usr/local/php/etc/php.ini
  • 1

#
<p style="margin-bottom: 7px;">#cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf<br/></p>
  • 1

  • ##
    #cp /usr/local/php-7.2.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  • 1

  • #chmod +x /etc/init.d/php-fpm

#1
  • #cp /usr/local/php/etc/php-fpm.d/www.conf.default/usr/local/php/etc/php-fpm.d/www.conf


### ##1############3.3啟動php-fpm###
# /etc/init.d/php-fpm startStarting php-fpm  done
#########1###########2### #########3.4新增PHP 指令到環境變數###
vim ~/.bash_profile
cat ~/.bash_profile# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then
    . ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/bin:/usr/local/php/binexport PATH
###使之生效:###
#. ~/.bash_profile
#########1######### ###3.5查看PHP版本:###
# php -vPHP 7.2.0 (cli) (built: Dec 17 2017 19:58:31) ( ZTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
###3.6測試結果:###
vim /usr/share/nginx/html/a.php<?php
        phpinfo();    ?>
#########
vim /etc/nginx/conf.d/default.confcat /etc/nginx/conf.d/default.confserver {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index index.php index.html index.htm;
    }
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
    }    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache&#39;s document root
    # concurs with nginx&#39;s one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}}

Nginx配置文件修改的地方(在server里面添加 index.php格式的文件。增加一个location模块) 
重新加载Nginx,重启php-fpm

# /etc/init.d/nginx restartStopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
# /etc/init.d/php-fpm restartGracefully shutting down php-fpm . doneStarting php-fpm  done


测试:

# curl 192.168.1.185/a.php
  • 1

或者直接到网页上访问。 
lnmp搭建(Nginx1.12.1;mysql5.7.20;php7.2.0)

至此,lnmp环境搭建成功

相关推荐:

使用docker创建集成服务lnmp环境

在lnmp环境下thinkphp5的一些必要配置

LNMP源码编译安装php-5.5.32实例

以上是lnmp搭建(Nginx1.12.1;mysql5.7.20;php7.2.0)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn