咱們爲何採用LNMP這種架構?
採用Linux、PHP、MySQL的優勢咱們沒必要多說。php
Nginx是一個小巧而高效的Linux下的Web服務器軟件,是由 Igor Sysoev 爲俄羅斯訪問量第二的 Rambler.ru 站點開發的,已經在一些俄羅斯的大型網站上運行多年,目前不少國內外的門戶網站、行業網站也都在是使用Nginx,至關的穩定。html
Nginx至關的穩定、功能豐富、安裝配置簡單、低系統資源……
Linux採用的是centos,軟件包統一放在/usr/local/src目錄下.因爲 centos源比較老,並且更新起來也比較慢,此處建議你換成163源。提示:若是你真打算採用這種編譯安裝php的話,請至少安排半天時間來完成。若是是在虛擬機裏測試的話,建議調大內存以讓時間更短,我本機給了虛擬機2G內存。在安裝完成後能夠再設置小點內存跑.安裝的時候請按順序安裝。node
更改yum源mysql
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo mv CentOS-Base.repo CentOS-Base.repo.bak mv CentOS6-Base-163.repo CentOS-Base.repo
yum clean all
yum makecache
yum update(這步比較慢,建議先不要運行)
準備lnmp安裝環境linux
先採用yum包安裝一些依賴的東西nginx
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make cmake libtool* git tree
下載一些軟件都放在/usr/local/src下
使用wget命令下載便可
附上軟件包地址(軟件包都是我一個一個在網上找的,可能軟件包下載地址會失效,你能夠給我發郵件或者你百度搜一個)
所須要的軟件包:c++
mhash-0.9.9.9
http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gzgit
mcrypt-2.6.8
http://jaist.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gzweb
ncurses
http://down1.chinaunix.net/distfiles/ncurses-5.9.tar.gzredis
pcre-8.31.tar.bz2
http://exim.mirror.fr/pcre/pcre-8.31.tar.bz2
zlib-1.2.8.tar.gz
http://iweb.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz
freetype-2.3.5.tar.bz2
http://down1.chinaunix.net/distfiles/freetype-2.3.5.tar.bz2
openssl-1.0.1c.tar.gz
http://down1.chinaunix.net/distfiles/openssl-1.0.1c.tar.gz
php-5.5.29.tar.bz2
http://cn2.php.net/distributions/php-5.5.29.tar.bz2
安裝libiconv
cd /usr/local/src wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz tar zxvf libiconv-1.14.tar.gz cd libiconv-1.14/ ./configure --prefix=/usr/local make && make install
在我make && make install的時候出現錯誤了error: ‘gets’ undeclared here (not in a function)。若是你不要遇到遇到,若是遇到請作以下修改:(國外的這文章記錄了http://www.itkb.ro/kb/linux/patch-libiconv-pentru-glibc-216)
cd libiconv-1.14/srclib
編輯stdio.in.h文件,搜索這句話
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
把這句刪除換成以下幾句
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); #endif
而後
cd .. make && make install
下載並安裝libmcrypt
cd /usr/local/src wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz tar -zxvf libmcrypt-2.5.7.tar.gz cd libmcrypt-2.5.7 ./configure make make install cd libltdl/ ./configure --enable-ltdl-install make make install
安裝mbash
cd /usr/local/src tar -jxvf mhash-0.9.9.9.tar.bz2 cd mhash-0.9.9.9 ./configure make make install
下載並安裝mcript
cd /usr/local/src tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
./configure make make install ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
安裝mysql(mysql5.6.13)
先檢查一下mysql是否已經存在了,若是存在就刪除mysql
rpm -qa | grep mysql
mysql-libs-5.1.73-3.el6_5.i686
rpm -e mysql-libs-5.1.73-3.el6_5.i686 --nodeps
rpm -qa | grep mysql
添加一個mysql用戶(nologin用戶而且沒有家目錄)
useradd -M -s /sbin/nologin mysql
初次編譯mysql的時候時間比較長,請耐心等待吧
cd /usr/local/src tar -zxf mysql-5.6.13.tar.gz cd mysql-5.6.13
cmake . make && make install
cp support-files/my-default.cnf /etc/my.cnf
cd /usr/local/mysql scripts/mysql_install_db --user=mysql
cd /usr/local/mysql chown -R root:mysql . chown -R mysql:mysql data
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/usr/local/mysql/bin/mysqld_safe --user=mysql &
netstat -tunpl | grep 3306
/usr/local/mysql/bin/mysqladmin -u root password "xxxxx"
/usr/local/mysql/bin/mysql -u root -p select host,user,password from mysql.user; delete from mysql.user where password="" or user=""; flush privileges;
set password form 'root'@'localhost' = password('123456');
/usr/local/mysql/bin/mysqladmin -u root -p shutdown
vim /etc/rc.local
/usr/local/mysql/bin/mysqld_safe --user=mysql &
ln -s /usr/local/mysql/bin/mysql /usr/bin/
nginx安裝
nginx安裝前編譯安裝pcre zlib openssl[openssl安裝用./config]
pcre安裝
cd /usr/local/src tar -jxf pcre-8.31.tar.bz2 cd pcre-8.31 ./configure make && make install
zlib安裝
cd /usr/local/src tar -zxf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./configure make && make install
openssl安裝
cd /usr/local/src tar -zxf openssl-1.0.1c.tar.gz cd openssl-1.0.1c ./config make && make install
安裝Nginx
cd /usr/local/src useradd -M -s /sbin/nologin nginx
tar -zxf nginx-2.0.1.tar.gz cd tengine-2.0.1
./configure --with-pcre=/usr/local/src/pcre-8.31 --with-http_ssl_module --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.1c
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/bin/
vim /usr/local/nginx/conf/nginx.conf
把#user nobody 改爲 user nginx;
nginx -t
nginx
vim /etc/rc.local
/usr/local/nginx/sbin/nginx
netstat -tunpl | grep 80
pstree 看下有沒有nginx就好了
安裝php
cd /usr/local/src useradd -M -s /sbin/nologin php tar -jxf php-5.5.12.tar.bz2 cd php-5.5.12
./configure --enable-opcache --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring=all --with-pdo-mysql --enable-sockets --enable-mbstring --enable-fpm --with-curl --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --with-gd --with-mcrypt --with-libxml-dir=/usr --enable-xml --with-openssl --with-iconv=/usr/local/iconv
make ZEND_EXTRA_LIBS='-liconv' make install
cp php.ini-development /usr/local/php/etc/php.ini
cd /usr/local/php/etc cp php-fpm.conf.default php-fpm.conf vim php-fpm.conf
將
`user = nobody
group = nobody`
改成
`user = php
group = php`
/usr/local/php/sbin/php-fpm
vim /etc/rc.local
/usr/local/php/sbin/php-fpm
修改nginx配置文件使之支持php
vim /usr/local/nginx/conf/nginx.conf #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; #}
修改成
location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
gzip on前面的#去掉
修改完配置以後nginx -s reload
ok,如今來測試一下環境
cd /usr/local/nginx cd html vim test.php
寫上
<?php phpinfo();
而後訪問一下localhost/test.php,正常的話,就一切正常了
若是出問題的話,請看nginx有沒有啓動,php-fpm有沒有啓動
註明幾個問題若是修改php配置文件的時候,須要重啓php-fpm就能夠了
pkill php-fpm
/usr/local/php/sbin/php-fpm
pstree
爲了更方便的使用php和php-fpm,我作了兩個鏈連接
ln -s /usr/local/php/sbin/php-fpm /usr/bin/
ln -s /usr/local/php/bin/php /usr/bin/
nmp安裝就完全完成了,有什麼問題能夠聯繫我QQ1017109588 [這裏沒沒講到如何優化一些配置的問題,之後能夠會寫文章分析]
在些也特別說明一下nginx如何支持path_info這種形式。配置文件中能夠這樣寫。固然可能對你不須要
location ~ ^(.+\.php)(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; }
LNMP環境搭建完成 你還能夠裝一些擴展 例如memcache redisd等
總結:編譯安裝的過程當中 操做系統環境不一樣 軟件包依賴 可能會出現一些報錯
遇到報錯不要慌張 能夠去Google一下 大部分的問題均可以解決
還能夠在文章下面評論 貼上你的報錯信息 博主能夠幫你看看哦
原文地址https://wujunze.com/lnmp_compile_install.jsp轉載請保留原文連接
參考