debian系統安裝最新lnmp編譯最新php7.1.2及nginx1.10.3及mysql5.7及5.6

技術小牛人發表於2017-11-06

aptitude 安裝nginx/mysql,編譯安裝php7.1.2

Created 星期四 23 二月 2017

一、配置映象源,預設debian沒有Nginx最新版本,以及php7.0版本(編譯安裝),mysql5.7版本!
1.1 vim /etc/apt/sources.list   新增如下 
deb http://nginx.org/packages/debian/ jessie nginx

deb-src 
http://nginx.org/packages/debian/  jessie nginx

完成後匯入key

#wget http://nginx.org/packages/keys/nginx_signing.key

#apt-key add nginx_signing.key

1.2安裝mysql社群版本5.7  

wget https://repo.mysql.com//mysql-apt-config_0.8.2-1_all.deb 

dpkg -i mysql-apt-config_0.8.2-1_all.deb

選擇對應的版本,有5.6及5.7兩個版本,還有工具。


安裝Nginx1.10.3

  aptitude install nginx 

 檢視版本

 root@user:~# /usr/sbin/nginx -v

 nginx version: nginx/1.10.3

 安裝mysql

 aptitude install mysql-server-5.6

 版本資訊:

 Welcome to the MySQL monitor.  Commands end with ; or g.

 Your MySQL connection id is 3

 Server version: 5.6.35 MySQL Community Server (GPL)


編譯安裝php7.1.2

 make編譯安裝

 build-essential autoconf automake libtool bison re2c

 依賴包安裝(大部分依賴包都在此若是還缺少請查詢)

 libxml2-dev libssl-dev libbz2-dev libjpeg-dev libpng-dev  

 libxpm-dev libfreetype6-dev libgmp-dev libgmp3-dev  

 libmcrypt-dev libmysqlclient15-dev libpspell-dev librecode-dev

 libcurl4-gnutls-dev libgmp-dev libgmp3-dev librecode-dev  

 libpspell-dev  libmysqlclient15-dev  libmcrypt-dev  

 libreadline-dev libtidy-dev libxslt-dev  -y

 openssl報錯:
  ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/

  或者編譯安裝

  wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz

  tar zxf openssl-1.0.2k.tar.gz

  cd openssl-1.0.2k

  ./config

  make && make install 

下載php7.1.2

wget http://cn2.php.net/distributions/php-7.1.2.tar.gz
tar zxf php-7.1.2.tar.gz
cd php-7.1.2
  ./configure –prefix=/usr/local/php7 –sysconfdir=/etc/php7

–with-config-file-path=/etc/php7 –enable-fpm –with-mysqli=mysqlnd

–with-pdo-mysql=mysqlnd –with-mhash –with-openssl –with-zlib

–with-bz2 –with-curl –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir

–with-zlib –enable-mbstring –with-mcrypt –enable-sockets –with-iconv-dir

–with-xsl –enable-zip –with-pcre-dir –with-pear –enable-session  

–enable-gd-native-ttf –enable-xml –with-freetype-dir –enable-gd-jis-conv

–enable-inline-optimization –enable-shared –enable-bcmath

–enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-mbregex

–enable-pcntl –with-xmlrpc –with-gettext –enable-exif –with-readline

–with-recode –with-tidy

編譯安裝

make && make install



配置nginx php檔案
配置檔案都在/etc目錄下,先備份好
#cd /etc/nginx
#cp nginx.conf nginx.conf.bak

#vim nginx.conf

把user XXX;改成如下:
user  www-data;

退出在進入
cd conf.d/

cp default.conf default.conf.bak 

vim default.conf 

修改成如下:
server {

listen       80;

server_name  localhost;

location / {

root   /usr/share/nginx/html;

index index.php index.html index.htm;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   /usr/share/nginx/html;

}

location ~ .php$ {

        root                 /usr/share/nginx/html;

        fastcgi_pass   unix:/run/php/php7.0-fpm.sock;

        fastcgi_index  index.php;                    

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include           fastcgi_params;

}

}

配置php檔案
#cd /etc/php7

#cp php-fpm.conf.default  php-fpm.conf

# cd /etc/php7/php-fpm.d
# cp www.conf.default  www.conf.default.bak 
#  mv www.conf.default lnmp.conf
# vim lnmp.conf
 user = nobody   改成   user = www-data

 group = nobody  改成  group = www-data

 listen = 127.0.0.1:9000改成listen = 
/run/php/php7.0-fpm.sock 
 listen.owner = www-data    取消註釋改成如此

 listen.group = www-data    取消註釋改成如此

 listen.mode = 0660          取消註釋改成如此

然後在解壓的安裝包裡複製php.ini-production  在/etc/php7/目錄下。


啟動服務
/etc/init.d/nginx start /restart /stop
/usr/local/php7/sbin/php-fpm 
/etc/init.d/mysql start

或者

啟動服務

systemctl start mysql.service (stop)

systemctl start nginx.service  (stop)

檢視啟動狀態

systemctl status nginx.service

systemctl status mysql.service

注意若是啟動服務報錯,可以看下是否有/run/php,若無請建立目錄,然後賦予php7.0-fpm.sock 許可權

程式
root@user:~#  ps -ef | grep php-fpm

root      1070     1  0 10:33 ?        00:00:00 php-fpm: master process (/etc/php7/php-fpm.conf)

www-data  1071  1070  0 10:33 ?        00:00:00 php-fpm: pool www           

www-data  1072  1070  0 10:33 ?        00:00:00 php-fpm: pool www           

root      1106  1065  0 10:42 pts/0    00:00:00 grep php-fpm
root@user:~# ps -ef | grep nginx

root       512     1  0 10:29 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

www-data   513   512  0 10:29 ?        00:00:00 nginx: worker process                   

root      1108  1065  0 10:42 pts/0    00:00:00 grep nginx
root@user:~# ps -ef | grep mysql

mysql     1179     1  0 10:47 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe

mysql     1455  1179  1 10:47 ?        00:00:00 /usr/sbin/mysqld –basedir=/usr –datadir=/var/lib/mysql –plugin-dir=/usr/lib/mysql/plugin –log-error=/var/log/mysql/error.log –pid-file=/var/run/mysqld/mysqld.pid –socket=/var/run/mysqld/mysqld.sock –port=3306

root      1505  1065  0 10:47 pts/0    00:00:00 grep mysql

結束程式
killall php-fpm

大部分報錯都可以進入cat /var/log/nginx/error.log檢視,然後google!


!!!!附件

本文一鍵安裝lnmp指令碼,需要聯網,但資料庫為debian8預設mysql5.5!,取消TXT字尾。


本文轉自  一招拜師  51CTO部落格,原文連結:http://blog.51cto.com/sadoc/1900479


相關文章