本篇內(nèi)容主要講解“Centos6.8編譯安裝LNMP環(huán)境的方法”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“Centos6.8編譯安裝LNMP環(huán)境的方法”吧!
一 準(zhǔn)備工作
1. 關(guān)閉selinux
修改配置文件,重啟服務(wù)后永久生效。
# sed -i ‘s/selinux=.*/selinux=disabled/g' /etc/selinux/config
命令行設(shè)置立即生效。
# setenforce 0
2. 如果是阿里云ecs用戶,安全組設(shè)置中開(kāi)啟80端口方便調(diào)試。
二 安裝nginx
1. 下載源碼包
上nginx官網(wǎng),復(fù)制新穩(wěn)定版的下載地址過(guò)來(lái),然后用wget下載(接下來(lái)需要下載安裝包的都可以用wget):
# cd /usr/local/src # wget http://nginx.org/download/nginx-1.10.3.tar.gz
2. 進(jìn)行解壓編譯
# 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í)行完成。
進(jìn)入解壓后的nginx-1.10.3文件夾:
cd /usr/local/src/nginx-1.10.3
執(zhí)行以下語(yǔ)句:
./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啟動(dòng)腳本。
用vim編輯腳本:
# vim /etc/init.d/nginx
寫(xiě)入以下內(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的一些命令,不然操作時(shí)可能會(huì)出現(xiàn)一點(diǎn)小問(wèn)題。
賦予腳本執(zhí)行權(quán)限:
# chmod +x /etc/init.d/nginx
添加至服務(wù)管理列表,設(shè)置開(kāi)機(jī)自啟:
# chkconfig –add nginx # chkconfig nginx on
4. 啟動(dòng)服務(wù)。
# service nginx start
注:如果報(bào)錯(cuò) [emerg]: getpwnam(“nginx”) failed ;
解決方法:
# useradd -s /sbin/nologin -m nginx # id nginx
三 安裝mysql
1. 版本選擇
在安裝之前必須明白一件事情,mysql有很多種安裝方式,每種不一樣,不要弄混了。
比如源碼編譯安裝(mysql-5.7.17.tar.gz),二進(jìn)制安裝(mysql-5.7.17-linux-glibc2.5-i686.tar),nmp安裝(最簡(jiǎn)單的)。這里我們用源碼自己編譯安裝。
2. 準(zhǔn)備編譯環(huán)境
# yum groupinstall “server platform development” “development tools” -y # yum install cmake -y
cmake在現(xiàn)在的版本是必須要安裝的,你可以下載camke之后編譯,也可以直接yum安裝。接下來(lái)的編譯過(guò)程如果報(bào)錯(cuò)缺少什么就補(bǔ)什么。
3. 準(zhǔn)備mysql數(shù)據(jù)庫(kù)存放目錄
# 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)定版的源碼包。
在下載的時(shí)候注意一下版本,下載對(duì)應(yīng)的版本。我們?cè)创a編譯,要下載長(zhǎng)這樣的安裝包:mysql-5.7.17.tar.gz,同時(shí)在安裝的時(shí)候我們需要boost庫(kù),5.7需要1.59版本的庫(kù);你可以下載boost庫(kù)然后編譯boost庫(kù),或者像我一樣,下載帶有boost庫(kù)的mysql版本。
開(kāi)始解壓編譯:
# 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ù)庫(kù)。
# /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命令會(huì)產(chǎn)生一個(gè)隨機(jī)的root登錄密碼,你要用這個(gè)密碼登錄,然后修改(必須修改生成的隨機(jī)密碼不然無(wú)法后續(xù)操作)。
8. 復(fù)制配置文件
# cp support-files/my-default.cnf /etc/my.cnf
這里又有一點(diǎn)要注意:mysql5.7配置文件需要修改my.cnf關(guān)鍵配置, mysql5.7之前默認(rèn)配置文件中是有配置項(xiàng)的,不用手動(dòng)修改。以下為配置,根據(jù)實(shí)際情況修改:
</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]下。
如果報(bào)錯(cuò)tmp目錄不錯(cuò)在,到對(duì)應(yīng)的地方去創(chuàng)建目錄,然后創(chuàng)建后要賦予mysql權(quán)限,chown -r mysql:mysql tmp。
9. 設(shè)置開(kāi)機(jī)啟動(dòng)
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld # chmod +x /etc/init.d/mysql
注冊(cè)為開(kāi)機(jī)啟動(dòng)服務(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. 啟動(dòng)服務(wù)
# service mysqld start
這樣基本上,這個(gè)mysql就裝好了。
12. 登錄mysql并修改密碼
mysql -uroot -p生成的密碼
執(zhí)行修改密碼:
alter user ‘root'@'localhost' identified by ‘newpassword';
四 安裝php-fpm
1. 安裝依賴(lài)包:
yum install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel
這里還漏了幾個(gè),如果報(bào)錯(cuò)了提示缺少了什么就yum補(bǔ)上。
2. 到官網(wǎng)下載源碼包后,開(kāi)始編譯安裝:
# 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,才是正確的,才可以開(kāi)始編譯,如果出問(wèn)題,就解決,一般是少了什么庫(kù)。
執(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啟動(dòng)腳本。
# 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è)置開(kāi)機(jī)自啟。
# chkconfig –add php-fpm # chkconfig –list php-fpm # chkconfig php-fpm on
6. 啟動(dòng)服務(wù)。
# service php-fpm start
注:啟動(dòng)時(shí)如出現(xiàn)錯(cuò)誤:
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對(duì)fastcgi的支持,
首先備份默認(rèn)的配置文件。
# cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak # cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
編輯/etc/nginx/nginx.conf,在所支持的主頁(yè)面格式中添加php格式的主頁(yè),類(lèi)似如下:
</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)容前面的注釋?zhuān)?/p>
</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. 測(cè)試是否成功
在/usr/local/nginx/html/新建index.php的測(cè)試頁(yè)面,內(nèi)容如下:
<?php phpinfo(); ?>
到此,相信大家對(duì)“Centos6.8編譯安裝LNMP環(huán)境的方法”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)建站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
本文題目:Centos6.8編譯安裝LNMP環(huán)境的方法-創(chuàng)新互聯(lián)
標(biāo)題路徑:http://www.rwnh.cn/article22/jogjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、用戶體驗(yàn)、搜索引擎優(yōu)化、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、定制開(kāi)發(fā)、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容