一、系統版本與所安裝軟體版本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<code>[root@www ~]# uname -a</code>
<code>Linux www.test.com.cn </code><code>2.6</code><code>.</code><code>32</code><code>-</code><code>358</code><code>.el6.x86_64 #</code><code>1</code> <code>SMP Fri Feb </code><code>22</code> <code>00</code><code>:</code><code>31</code><code>:</code><code>26</code> <code>UTC </code><code>2013</code> <code>x86_64 x86_64 x86_64 GNU/Linux</code>
<code>[root@www ~]# mkdir Downloads</code>
<code>[root@www ~]# mkdir nginx</code>
<code>[root@www Downloads]# cd nginx/</code>
<code>[root@www nginx]# pwd</code>
<code>/root/Downloads/nginx</code>
<code>[root@www nginx]# wget http:</code><code>//nginx.org/download/nginx-1.4.0.tar.gz</code>
<code>--</code><code>2013</code><code>-</code><code>09</code><code>-</code><code>03</code> <code>17</code><code>:</code><code>11</code><code>:</code><code>41</code><code>-- http:</code><code>//nginx.org/download/nginx-1.4.0.tar.gz</code>
<code>Resolving nginx.org... </code><code>206.251</code><code>.</code><code>255.63</code>
<code>Connecting to nginx.org|</code><code>206.251</code><code>.</code><code>255.63</code><code>|:</code><code>80</code><code>... connected.</code>
<code>HTTP request sent, awaiting response... </code><code>200</code> <code>OK</code>
<code>Length: </code><code>773451</code> <code>(755K) [application/octet-stream]</code>
<code>Saving to: ?.ginx-</code><code>1.4</code><code>.</code><code>0</code><code>.tar.gz?</code>
<code>[root@www php]# pwd</code>
<code>/root/Downloads/php</code>
<code>[root@www php]# wget http:</code><code>//cn2.php.net/get/php-5.4.14.tar.gz/from/this/mirror</code>
<code>--</code><code>2013</code><code>-</code><code>09</code><code>-</code><code>03</code> <code>17</code><code>:</code><code>18</code><code>:</code><code>22</code><code>-- http:</code><code>//cn2.php.net/get/php-5.4.14.tar.gz/from/this/mirror</code>
<code>Resolving cn2.php.net... </code><code>220.181</code><code>.</code><code>136.36</code><code>, </code><code>220.181</code><code>.</code><code>136.37</code>
<code>Connecting to cn2.php.net|</code><code>220.181</code><code>.</code><code>136.36</code><code>|:</code><code>80</code><code>... failed: Connection timed out.</code>
<code>Connecting to cn2.php.net|</code><code>220.181</code><code>.</code><code>136.37</code><code>|:</code><code>80</code><code>... connected.</code>
<code>HTTP request sent, awaiting response... </code><code>302</code> <code>Found</code>
<code>Location: http:</code><code>//cn2.php.net/distributions/php-5.4.14.tar.gz [following]</code>
<code>--</code><code>2013</code><code>-</code><code>09</code><code>-</code><code>03</code> <code>17</code><code>:</code><code>19</code><code>:</code><code>45</code><code>-- http:</code><code>//cn2.php.net/distributions/php-5.4.14.tar.gz</code>
<code>Length: </code><code>15773155</code> <code>(15M) [application/x-gzip]</code>
<code>Saving to: ?.hp-</code><code>5.4</code><code>.</code><code>14</code><code>.tar.gz?</code>
mysql
<code>[root@www mysql]# cd /root/Downloads/mysql/</code>
<code>[root@www mysql]# wget http:</code><code>//cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.13.tar.gz</code>
<code>--</code><code>2013</code><code>-</code><code>09</code><code>-</code><code>03</code> <code>17</code><code>:</code><code>55</code><code>:</code><code>30</code><code>-- http:</code><code>//cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.13.tar.gz</code>
<code>Resolving cdn.mysql.com... </code><code>216.156</code><code>.</code><code>211.64</code><code>, </code><code>216.156</code><code>.</code><code>211.17</code>
<code>Connecting to cdn.mysql.com|</code><code>216.156</code><code>.</code><code>211.64</code><code>|:</code><code>80</code><code>... connected.</code>
<code>Length: </code><code>35951160</code> <code>(34M) [application/x-tar-gz]</code>
<code>Saving to: ?.ysql-</code><code>5.6</code><code>.</code><code>13</code><code>.tar.gz?</code>
注:自從mysql 5.5.8之後,MySQL的源碼包編譯安裝都要用到cmake來進行編譯了,編譯的過程沒有本質的差別,但是要直覺很多.
二、安裝nginx
1、安裝前提:
<code>[root@www nginx]</code><code># yum remove httpd php*</code>
<code>#移除己安裝的httpd與php包</code>
<code>[root@www nginx]</code><code># yum groupinstall "Development Tools" -y</code>
<code>#安裝Development Tools</code>
2、解壓、編譯安裝nginx
<code>#到下載下傳nginx的目錄</code>
<code>[root@www nginx]# tar -zvxf nginx-</code><code>1.4</code><code>.</code><code>0</code><code>.tar.gz</code>
<code>[root@www nginx]# cd nginx-</code><code>1.4</code><code>.</code><code>0</code>
<code>[root@www nginx-</code><code>1.4</code><code>.</code><code>0</code><code>]# ./configure --prefix=/opt/nginx/</code>
3、如果在編譯過程有如下提示需要安裝:pcre pcre-devel包
<code>.</code><code>/configure</code><code>: error: the HTTP rewrite module requires the PCRE library.</code>
<code>You can either disable the module by using --without-http_rewrite_module</code>
<code>option, or </code><code>install</code> <code>the PCRE library into the system, or build the PCRE library</code>
<code>statically from the </code><code>source</code> <code>with nginx by using --with-pcre=<path> option.</code>
4、安裝pcre包
<code>[root@www nginx-1.4.0]</code><code># yum install pcre pcre-devel -y</code>
5、重新編譯安裝
<code>#編譯成功後</code>
<code>[root@www nginx-</code><code>1.4</code><code>.</code><code>0</code><code>]#make && make install</code>
6、啟動nginx
<code>[root@www nginx-</code><code>1.4</code><code>.</code><code>0</code><code>]# cd /opt/nginx/sbin</code>
<code>[root@www sbin]# ./nginx</code>
7、測試nginx
<code>[root@www sbin]# elinks http:</code><code>//127.0.0.1</code>
<code>#如果系統中沒有elinks需要安裝:</code>
<code>elinks-</code><code>0.12</code><code>-</code><code>0.21</code><code>.pre5.el6_3.x86_64.rpm</code>
<code>nss_compat_ossl-</code><code>0.9</code><code>.</code><code>6</code><code>-</code><code>1</code><code>.el6.x86_64.rpm</code>
<code>[root@www sbin]#yum install elink* -y</code>
===================================到此nginx安裝完畢=====================================
三、安裝msyql
1、安裝所需的庫檔案
<code>[root@www mysql]</code><code># pwd</code>
<code>/root/Downloads/mysql</code>
<code>[root@www mysql]</code><code># yum install -y gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*</code>
2、編譯步驟
<code>[root@www mysql]</code><code># mkdir -p /usr/local mysql</code>
<code>[root@www mysql]</code><code># mkdir -p /data/mysql</code>
<code>[root@www mysql]</code><code># groupadd mysql</code>
<code>[root@www mysql]</code><code># useradd -g mysql mysql</code>
<code>[root@www mysql]</code><code># chown -R mysql.mysql /data/mysql</code>
3、安裝cmake
<code>[root@www mysql]</code><code>#yum install -y cmake</code>
4、解壓、編譯mysql
<code>[root@www mysql-5.6.13]</code><code>#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306</code>
<code>[roo@www mysql-5.6.13]</code><code>#make &&make install</code>
參數說明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安裝目錄
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock //指定sock檔案所在的目錄
-DMYSQL_DATADIR=/data/mysql //資料庫存放目錄
-DWITH_MYISAM_STORAGE_ENGINE=1 //安裝myisam存儲引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 //安裝innodb存儲引擎
-DWITH_MEMORY_STORAGE_ENGINE=1 //安裝memory存儲引擎
-DWITH_READLINE=1 //快捷鍵功能
-DENABLED_LOCAL_INFILE=1 //允許從本地導入資料
-DDEFAULT_CHARSET=utf8 //使用utf8字元
-DDEFAULT_COLLATION=utf8_general_ci //校驗字元
-DEXTRA_CHARSETS=utf8,gbk //安裝utf8,gbk擴充字元集
-DMYSQL_TCP_PORT=3306 //MySQL監聽端口
-DMYSQL_USER=mysql //MySQL使用者名
<code>[root@www mysql]# pwd</code>
<code> </code><code>/usr/local/mysql</code>
<code>[root@www mysql]# cp support-files/my-</code><code>default</code><code>.cnf /etc/my.cnf</code>
<code>[root@www mysql]#chmod </code><code>755</code> <code>scripts/mysql_install_db</code>
<code>[root@www mysql]#scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/ #初始化資料庫</code>
<code>[root@www mysql]# cp support-files/mysql.server /etc/init.d/mysql #設定開機啟動mysql</code>
<code>[root@www mysql]#chmod </code><code>755</code> <code>/etc/init.d/mysql</code>
<code>[root@www mysql]#chkconfig mysql on #開機啟動</code>
<code>[root@www mysql]#echo </code><code>'export PATH=/usr/local/mysql/bin:$PATH'</code> <code>>> /etc/profile #将mysql的安裝路徑加入PATH中,友善啟動mysql(重新開機生效)</code>
<code>[root@www mysql]#/etc/init.d/mysql start #啟動mysql</code>
<code>#可以在程序中檢視mysql是否啟動</code>
<code>[root@www mysql]#ps aux|grep mysql</code>
<code>#完成。</code>
<code>#設定一個mysql的root密碼</code>
<code>[root@www mysql]#mysqlamdin -u root password </code><code>'mysql'</code>
在這裡我出現過一個問題:删除mysql 重新安裝後會有一些錯誤。在編譯完mysql後啟動時會提示
注:本人是重新編譯安裝就沒有出現此問題,有那一個大神知道具體是什麼原因,請指點!
附:
具體解決方法請參照:
<a href="http://blog.rekfan.com/articles/186.html">http://blog.rekfan.com/articles/186.html</a>
<code>#kill 掉mysql的程序</code>
<code>[root@www mysql]</code><code># ps aux |grep mysql</code>
<code>root 1694 0.0 0.1 108332 1508 ? S 17:21 0:00 </code><code>/bin/sh</code> <code>/usr/local/mysql/bin/mysqld_safe</code> <code>--datadir=</code><code>/data/mysql</code> <code>--pid-</code><code>file</code><code>=</code><code>/data/mysql/www</code><code>.centostest.com.cn.pid</code>
<code>mysql 1809 0.1 44.8 1071940 454008 ? Sl 17:21 0:03 </code><code>/usr/local/mysql/bin/mysqld</code> <code>--basedir=</code><code>/usr/local/mysql</code> <code>--datadir=</code><code>/data/mysql</code> <code>--plugin-</code><code>dir</code><code>=</code><code>/usr/local/mysql/lib/plugin</code> <code>--user=mysql --log-error=</code><code>/data/mysql/www</code><code>.centostest.com.cn.err --pid-</code><code>file</code><code>=</code><code>/data/mysql/www</code><code>.centostest.com.cn.pid</code>
<code>root 2299 0.0 0.0 103248 836 pts</code><code>/0</code> <code>S+ 18:07 0:00 </code><code>grep</code> <code>mysql</code>
<code>[root@www mysql]</code><code>#kill -9 1694</code>
<code>#重新啟動mysql即可</code>
<code>[root@www mysql]</code><code>#/etc/init.d/mysql start</code>
============================到此mysql安裝完畢=========================================
三、安裝php
1、解壓
<code>[root@www php]# tar -zxvf php-</code><code>5.4</code><code>.</code><code>14</code><code>.tar.gz</code>
2、安裝依賴包
<code>[root@www php]</code><code># yum install -y libxml2-devel libjpeg-devel libpng-devel freetype-devel openssl-devel libcurl-devel libmcrypt-devel</code>
3、編譯
<code>[root@www php]</code><code># ls</code>
<code>php-5.4.14 php-5.4.14.</code><code>tar</code><code>.gz</code>
<code>[root@www php-5.4.14]</code><code>#./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic</code>
在此遇到configure: error: mcrypt.h not found. Please reinstall libmcrypt.問題
解決方法:
<code>[root@www php-5.4.14]</code><code># wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download</code>
<code>[root@www php-5.4.14]</code><code>#tar -zxvf libmcrypt-2.5.8.tar.gz</code>
<code>[root@www php-5.4.14]</code><code>#cd libmcrypt-2.5.8</code>
<code>root@www libmcrypt-2.5.8]</code><code>#./configure</code>
<code>root@www libmcrypt-2.5.8]</code><code>#make && make install</code>
之後再重新編譯,完成
<code>[root@www libmcrypt-2.5.8]</code><code># cd ..</code>
<code>[root@www php-5.4.14]</code><code>#pwd</code>
<code>/root/Download/php/php-5</code><code>.4.14</code>
<code>[root@www php-5.4.14]</code><code># make && make install</code>
<code>#安裝時間有點長。</code>
編譯php出錯:
1、error while loading shared libraries: libmysqlclient.so.18: cannot open shared object 網上找到的解決辦法是
适用于32位系統
[root@www php-5.4.14]#ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/
64位系統應使用下面
[root@www php-5.4.14]#ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
2、 cp: cannot stat `ext/phar/phar.phar': No such file or directory
[root@www php-5.4.14]#cd ext/phar/
[root@www phar]# cp ./phar.php ./phar.phar
[root@www php-5.4.14]# make && make install
安裝成功後,php的位置就應該在/opt/php目錄下,接下去就是配置
<code>[root@www php-5.4.14]</code><code># cp /root/Downloads/php/php-5.4.14/php.ini-production /opt/php/etc/php.ini</code>
<code>[root@www php-5.4.14]</code><code># cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf</code>
<code>[root@www php-5.4.14]</code><code># cd /opt/php/etc</code>
<code>[root@www etc]</code><code># ls</code>
<code>php-fpm.conf php-fpm.conf.default php.ini</code>
<code>[root@www etc]</code><code># cd /opt/nginx/conf</code>
<code>#然後配置nginx的配置檔案,讓其可以運作php</code>
<code>[root@www conf]</code><code># ls</code>
<code>fastcgi.conf koi-utf nginx.conf uwsgi_params</code>
<code>fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default</code>
<code>fastcgi_params mime.types scgi_params win-utf</code>
<code>fastcgi_params.default mime.types.default scgi_params.default</code>
<code>[root@www conf]</code><code># vim nginx.conf</code>
<code>#1、去掉 #user nobody; 的#号, 變成 user nobody;</code>
<code>#2、去掉</code>
<code>#location ~ \.php$ {</code>
<code> </code><code># root html;</code>
<code> </code><code># fastcgi_pass 127.0.0.1:9000;</code>
<code> </code><code># fastcgi_index index.php;</code>
<code> </code><code># fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;</code>
<code> </code><code># include fastcgi_params;</code>
<code> </code><code>#}</code>
<code>#之前的#号,并修改fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;為fastcgi_param SCRIPT_FILENAME /opt/nginx/html$fastcgi_script_name;最終修改後的内容為:</code>
<code>location ~ \.php$ { </code>
<code> </code><code>root html;</code>
<code> </code><code>fastcgi_pass 127.0.0.1:9000;</code>
<code> </code><code>fastcgi_index index.php;</code>
<code> </code><code>fastcgi_param SCRIPT_FILENAME </code><code>/opt/nginx/html</code><code>$fastcgi_script_name;</code>
<code> </code><code>include fastcgi_params;</code>
<code> </code><code>}</code>
4、重新開機nginx服務,并開啟php-fpm
<code>[root@www conf]</code><code># /opt/nginx/sbin/nginx</code>
<code>[root@www conf]</code><code># /opt/php/sbin/php-fpm</code>
<code>[root@www conf]</code><code># vim /opt/nginx/html/phpinfo.php</code>
<code>#内容為</code>
<code> </code><code><?php</code>
<code> </code><code>phpinfo();</code>
<code>?></code>
<a target="_blank" href="http://blog.51cto.com/attachment/201309/113942166.png"></a>
======================到此LNMP安裝成功==========================================
本文轉自 jinlinger 51CTO部落格,原文連結:http://blog.51cto.com/essun/1288442,如需轉載請自行聯系原作者