欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Centos 6.8編譯安裝LNMP環(huán)境(Nginx+MySQL+PHP)教程

 更新時間:2017年03月04日 14:19:18   作者:鍋子博客  
這篇文章主要介紹了關(guān)于CentOS 6.8中編譯安裝LNMP環(huán)境的相關(guān)資料,LNMP即Linux,Nginx,MySQL,PHP,文中通過一步步的步驟介紹的非常詳細,需要的朋友可以參考借鑒,下面來一起看看吧。

前言

對于新手的一點建議:

  • 最好熟悉一下linux 的基本命令,vim的常用命令
  • 千萬不要無腦復(fù)制,先看一下命令,特別是路徑要注意
  • 學(xué)會排查錯誤

本篇安裝的軟件版本為:

  • Linux:Centos6.8
  • Nginx:1.10.3
  • MySQL:5.7.17
  • PHP:7.0.16

最近研究了Linux系統(tǒng)下的PHP環(huán)境搭建,個人感覺最好最好不要用yum默認的程序包安裝,因為版本都比較低,下載最新的穩(wěn)定版自行安裝比較好。現(xiàn)在網(wǎng)上教程很多,之所以還記這篇,原因有一點,當你重復(fù)網(wǎng)上的教程自行安裝時,90%還是會出現(xiàn)各種各樣的問題,因為你可能linux的系統(tǒng)版本不同,你想裝的軟件版本不同,安裝的方法不同,你下錯了安裝包的版本,還有其它亂七八糟的。舉個例,比如你看著5.6的mysql安裝教程,裝5.7的,你感覺沒問題,但是事實就是,5.7的不一樣了!而且網(wǎng)上還沒有新的這方面內(nèi)容,不好找,這就需要你去摸索了,親身經(jīng)歷啊。這里面,Niginx感覺最好配,MySQL最坑。

一 準備工作

1. 關(guān)閉SELINUX

修改配置文件,重啟服務(wù)后永久生效。

# sed -i ‘s/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

命令行設(shè)置立即生效。

# setenforce 0

2. 如果是阿里云ECS用戶,安全組設(shè)置中開啟80端口方便調(diào)試。 

二 安裝Nginx

1. 下載源碼包

上Nginx官網(wǎng),復(fù)制最新穩(wěn)定版的下載地址過來,然后用wget下載(接下來需要下載安裝包的都可以用wget):

# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.10.3.tar.gz

下載完成的狀態(tài)基本都是以下這樣的:

2. 進行解壓編譯

# tar xvf nginx-1.10.3.tar.gz
# yum groupinstall “Development tools”
# yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel

執(zhí)行完成。

進入解壓后的nginx-1.10.3文件夾:

cd /usr/local/src/nginx-1.10.3

執(zhí)行以下語句:

./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module

完成后執(zhí)行編譯:

# make && make install
# mkdir -pv /var/tmp/nginx/client

3. 添加SysV啟動腳本。

用vim編輯腳本:

# vim /etc/init.d/nginx

寫入以下內(nèi)容:

#!/bin/sh 
# 
# nginx - this script starts and stops the nginx daemon 
# 
# chkconfig: - 85 15 
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \ 
#  proxy and IMAP/POP3 proxy server 
# processname: nginx 
# config: /etc/nginx/nginx.conf 
# config: /etc/sysconfig/nginx 
# pidfile: /var/run/nginx.pid 
# Source function library. 
. /etc/rc.d/init.d/functions
# Source networking configuration. 
. /etc/sysconfig/network
# Check that networking is up. 
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
 [ -x $nginx ] || exit 5
 [ -f $NGINX_CONF_FILE ] || exit 6
 echo -n $"Starting $prog: " 
 daemon $nginx -c $NGINX_CONF_FILE
 retval=$?
 echo 
 [ $retval -eq 0 ] && touch $lockfile
 return $retval
}
stop() {
 echo -n $"Stopping $prog: " 
 killproc $prog -QUIT
 retval=$?
 echo 
 [ $retval -eq 0 ] && rm -f $lockfile
 return $retval
killall -9 nginx
}
restart() {
 configtest || return $?
 stop
 sleep 1
 start
}
reload() {
 configtest || return $?
 echo -n $"Reloading $prog: " 
 killproc $nginx -HUP
RETVAL=$?
 echo 
}
force_reload() {
 restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
 status $prog
}
rh_status_q() {
 rh_status >/dev/null 2>&1
}
case "$1" in
 start)
 rh_status_q && exit 0
 $1
 ;;
 stop)
 rh_status_q || exit 0
 $1
 ;;
 restart|configtest)
 $1
 ;;
 reload)
 rh_status_q || exit 7
 $1
 ;;
 force-reload)
 force_reload
 ;;
 status)
 rh_status
 ;;
 condrestart|try-restart)
 rh_status_q || exit 0
  ;;
 *)
 echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
 exit 2
esac

保存退出(按:wq!);可能你得稍微查一下vim的一些命令,不然操作時可能會出現(xiàn)一點小問題。

賦予腳本執(zhí)行權(quán)限:

# chmod +x /etc/init.d/nginx

添加至服務(wù)管理列表,設(shè)置開機自啟:

# chkconfig –add nginx
# chkconfig nginx on

4. 啟動服務(wù)。

# service nginx start

出現(xiàn)這玩意說明成功了!

注:如果報錯 [emerg]: getpwnam(“nginx”) failed ;

解決方法:

# useradd -s /sbin/nologin -M nginx
# id nginx

三 安裝mysql

1. 版本選擇

在安裝之前必須明白一件事情,mysql有很多種安裝方式,每種不一樣,不要弄混了。

比如源碼編譯安裝(mysql-5.7.17.tar.gz),二進制安裝(mysql-5.7.17-linux-glibc2.5-i686.tar),nmp安裝(最簡單的)。這里我們用源碼自己編譯安裝。

2. 準備編譯環(huán)境

# yum groupinstall “Server Platform Development” “Development tools” -y
# yum install cmake -y

cmake在現(xiàn)在的版本是必須要安裝的,你可以下載camke之后編譯,也可以直接yum安裝。接下來的編譯過程如果報錯缺少什么就補什么。

3. 準備mysql數(shù)據(jù)庫存放目錄

# mkdir /mnt/data
# groupadd -r mysql
# useradd -r -g mysql -s /sbin/nologin mysql
# id mysql

4. 更改數(shù)據(jù)目錄權(quán)限。

# chown -R mysql:mysql /mnt/data

5. 下載并解壓編譯官網(wǎng)下載的穩(wěn)定版的源碼包。

在下載的時候注意一下版本,下載對應(yīng)的版本。我們源碼編譯,要下載長這樣的安裝包:mysql-5.7.17.tar.gz,同時在安裝的時候我們需要boost庫,5.7需要1.59版本的庫;你可以下載boost庫然后編譯boost庫,或者像我一樣,下載帶有boost庫的mysql版本。

開始解壓編譯:

# tar xvf mysql-boost-5.7.17.tar.gz -C /usr/local/src
# cd /usr/local/src/mysql-5.7.17
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mnt/data \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/mysql/boost/boost_1_59_0 \
# make && make install

6. 修改安裝目錄的權(quán)限屬組

# chown -R mysql:mysql /usr/local/mysql/

7. 初始化數(shù)據(jù)庫。

# /usr/local/mysql/bin/mysqld –initialize –user=mysql –basedir=/usr/local/mysql –datadir=/mnt/data/

需要注意這里是mysql5.7的初始化命令,而5.7以下的都是用:

# /usr/local/mysql/scripts/mysql_install_db –user=mysql –datadir=/mnt/data/

在初始化成功之后,5.7的initial命令會產(chǎn)生一個隨機的root登錄密碼,你要用這個密碼登錄,然后修改(必須修改生成的隨機密碼不然無法后續(xù)操作)。在最后有一個類似這樣的密碼:

8. 復(fù)制配置文件

# cp support-files/my-default.cnf /etc/my.cnf

這里又有一點要注意:mysql5.7配置文件需要修改my.cnf關(guān)鍵配置, mysql5.7之前默認配置文件中是有配置項的,不用手動修改。以下為配置,根據(jù)實際情況修改:

</div>
<div>[mysqld]</div>
<div>basedir = /usr/local/mysql</div>
<div>datadir = /mnt/data</div>
<div>port = 3306</div>
<div>socket = /Ultrapower/test/mysql/tmp/mysql.sock</div>
<div></div>
<div>sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES</div>
<div>[client]</div>
<div>socket = /Ultrapower/test/mysql/tmp/mysql.sock</div>
<div>

如果添加[client]下 的內(nèi)容,注意sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES要放在[mysqld]下。
如果報錯tmp目錄不錯在,到對應(yīng)的地方去創(chuàng)建目錄,然后創(chuàng)建后要賦予mysql權(quán)限,chown -R mysql:mysql tmp。

9. 設(shè)置開機啟動

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysql

注冊為開機啟動服務(wù):

# chkconfig mysqld on
# chkconfig –add mysqld

查看是否設(shè)置成功:

# chkconfig –list mysql

10. 設(shè)置PATH環(huán)境變量。

# echo “export PATH=$PATH:/usr/local/mysql/bin” > /etc/profile.d/mysql.sh
# source /etc/profile.d/mysql.sh

11. 啟動服務(wù)

# service mysqld start

這樣基本上,這個mysql就裝好了。

12. 登錄mysql并修改密碼

mysql -uroot -p生成的密碼

執(zhí)行修改密碼:

alter user ‘root'@'localhost' identified by ‘newpassword';

四 安裝php-fpm

1. 安裝依賴包:

yum install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel

這里還漏了幾個,如果報錯了提示缺少了什么就yum補上。

2. 到官網(wǎng)下載源碼包后,開始編譯安裝:

# tar xvf php-7.0.16.tar.bz2 -C /usr/local/src
# cd /usr/local/src/php-7.0.16
執(zhí)行下面的配置文件:
# ./configure --prefix=/usr/local/php \
--with-config-file-scan-dir=/etc/php.d \
--with-config-file-path=/etc \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-fpm \
--enable-opcache \
--disable-fileinfo \
--with-jpeg-dir \
--with-iconv-dir=/usr/local \
--with-freetype-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-exif \
--with-curl \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-inline-optimization \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-ftp \
--with-gettext \
--enable-zip \
--enable-soap \
--with-bz2

執(zhí)行以上的配置,如果出現(xiàn)下面這樣的license,才是正確的,才可以開始編譯,如果出問題,就解決,一般是少了什么庫。


執(zhí)行編譯:

# make && make install

3. 添加php和php-fpm配置文件。

# cp /usr/local/src/php-7.0.16/php.ini-production /etc/php.ini
# cd /usr/local/php/etc/
# cp php-fpm.conf.default php-fpm.conf
# sed -i ‘s@;pid = run/php-fpm.pid@pid = /usr/local/php/var/run/php-fpm.pid@' php-fpm.conf

4. 添加php-fpm啟動腳本。

# cp /usr/local/src/php-7.0.16/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm

5. 添加php-fpm至服務(wù)列表并設(shè)置開機自啟。

# chkconfig –add php-fpm
# chkconfig –list php-fpm
# chkconfig php-fpm on

6. 啟動服務(wù)。

# service php-fpm start

注:啟動時如出現(xiàn)錯誤:

WARNING: Nothing matches the include pattern ‘/usr/local/etc/php-fpm.d/*.conf' from /usr/local/etc/php-fpm.conf at line 125.
ERROR:. No pool defined at least one pool section must be specified in config file
ERROR: failed to post process the configuration
ERROR: FPM initialization failed

解決:到指定目錄執(zhí)行cp www.conf.default www.conf

7. 添加nginx對fastcgi的支持,

首先備份默認的配置文件。

# cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak

# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf

編輯/etc/nginx/nginx.conf,在所支持的主頁面格式中添加php格式的主頁,類似如下:

</div>
<div>location / {</div>
<div>root /usr/local/nginx/html;</div>
<div>index index.php index.html index.htm;</div>
<div>}</div>
<div>

取消以下內(nèi)容前面的注釋:

</div>
<div>location ~ \.php$ {</div>
<div>root /usr/local/nginx/html;</div>
<div>fastcgi_pass 127.0.0.1:9000;</div>
<div>fastcgi_index index.php;</div>
<div>fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;</div>
<div>include fastcgi_params;</div>
<div>}</div>
<div>

8. 重啟nginx

# service nginx reload

9. 測試是否成功

在/usr/local/nginx/html/新建index.php的測試頁面,內(nèi)容如下:

<?php
phpinfo();
?>

如果出現(xiàn)這個熟悉的界面,說明就大功告成了!Linux下一個基本的LNMP就搭建完畢了。

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

  • 確保Linux服務(wù)器安全 防范四種級別攻擊

    確保Linux服務(wù)器安全 防范四種級別攻擊

    以下的文章主要描述的是防范四種級別攻擊確保Linux服務(wù)器安全,如果你對防范四種級別攻擊確保Linux服務(wù)器安全心存好奇的話,以下的文章將會揭開它的神秘面紗。
    2011-03-03
  • Linux中接收和處理數(shù)據(jù)包方式

    Linux中接收和處理數(shù)據(jù)包方式

    這篇文章主要介紹了Linux中接收和處理數(shù)據(jù)包方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • 詳解在Linux下搭建Git服務(wù)器

    詳解在Linux下搭建Git服務(wù)器

    本篇文章主要介紹了詳解在Linux下搭建Git服務(wù)器,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • Linux中sudo、su和su -命令的區(qū)別小結(jié)

    Linux中sudo、su和su -命令的區(qū)別小結(jié)

    我們知道,在Linux下對很多文件進行修改都需要有root(管理員)權(quán)限,比如對/ect/profile等文件的修改。下面這篇文章主要給大家總結(jié)介紹了關(guān)于Linux中sudo、su和su -命令的區(qū)別的相關(guān)資料,需要的朋友可以參考下
    2018-09-09
  • Linux自動化構(gòu)建工具make和Makefile詳解

    Linux自動化構(gòu)建工具make和Makefile詳解

    這篇文章主要介紹了Linux如何自動化構(gòu)建工具make和makefile,文章中有詳細的圖片示例,對學(xué)習(xí)有一定的參考價值,感興趣的小伙伴可以參考一下
    2023-04-04
  • LAMP架構(gòu)系統(tǒng)服務(wù)搭建過程詳解

    LAMP架構(gòu)系統(tǒng)服務(wù)搭建過程詳解

    這篇文章主要為大家詳細介紹了LAMP架構(gòu)系統(tǒng)服務(wù)搭建過程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • 重啟Linux服務(wù)器后數(shù)據(jù)消失問題的解決方法(重新掛載)

    重啟Linux服務(wù)器后數(shù)據(jù)消失問題的解決方法(重新掛載)

    在使用 reboot 命令重啟服務(wù)器后,服務(wù)器內(nèi)掛載的文件全部丟失,那應(yīng)該如何重新掛載呢?所以本文小編給大家介紹了重啟Linux服務(wù)器后數(shù)據(jù)消失問題的解決方法,并通過圖文講解的非常詳細,需要的朋友可以參考下
    2024-09-09
  • linux環(huán)境安裝openssh-server及使用密碼登錄方式

    linux環(huán)境安裝openssh-server及使用密碼登錄方式

    這篇文章主要介紹了linux環(huán)境安裝openssh-server及使用密碼登錄方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • linux平臺的office文檔轉(zhuǎn)pdf的實例(程序員的菜)

    linux平臺的office文檔轉(zhuǎn)pdf的實例(程序員的菜)

    下面小編就為大家?guī)硪黄猯inux平臺的office文檔轉(zhuǎn)pdf的實例(程序員的菜)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • 在CentOS搭建Git服務(wù)器的詳細步驟

    在CentOS搭建Git服務(wù)器的詳細步驟

    本篇文章主要介紹了在CentOS搭建Git服務(wù)器的詳細步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11

最新評論