1. 程式人生 > >ubuntu14.04 安裝LNMP

ubuntu14.04 安裝LNMP

data- http n) libcurl libmysql nbsp tar medium without

新書上市《深入解析Android 5.0系統》


通常我們使用centos來組建LNMP,可是我們開發時多使用ubuntu的桌面版本號來調試,以下將具體介紹怎樣在ubuntu上安裝一套LNMP。

一、下載並安裝最新的ubuntu14.04桌面版本號

二、安裝mysql

1. 下載mysql的最新版本號,比如:
wget http://dl.mysql.cn/mysql5/5.5/mysql-5.5.25.tar.gz

2. 解壓縮:
tar -xvf mysql-5.5.25.tar.gz

3. 進入mysql文件文件夾:
cd mysql-5.5.25

註意:文件INSTALL-SOURCE中有安裝指南,能夠參考。

4. mysql須要用cmake編譯,先安裝cmake:
sudo apt-get install cmake

5. 安裝g++編譯器
sudo apt-get install g++

6. 安裝依賴庫libncurses
sudo apt-get install libncurses5-dev

7. 使用以下的命令開始編譯並安裝,假設cmake失敗了,又一次調用cmake命令前。須要先刪除文件CMakeCache.txt
cmake .
make
sudo make install

8. 添加mysql組和用戶
sudo groupadd mysql
sudo useradd -r -g mysql mysql

9. 進入mysql的安裝文件夾
cd /usr/local/mysql

10. 改變owner和group
sudo chown -R mysql .
sudo chgrp -R mysql .

11. 創建數據庫
sudo scripts/mysql_install_db --user=mysql

12. 改變owner
sudo chown -R root .
sudo chown -R mysql data

13. 生成mysql的配置文件
sudo cp support-files/my-medium.cnf /etc/my.cnf

14. 啟動mysql
sudo bin/mysqld_safe --user=mysql &

15. 運行以下命令能夠啟動mysql的命令行工具。假設能正確啟動說明mysql成功安裝。


/usr/local/mysql/bin/mysql

三、安裝PHP

1. 下載PHP源代碼包:
wget http://cn2.php.net/distributions/php-5.5.12.tar.gz

2. 解壓縮:
tar -xvf php-5.5.12.tar.gz

3. 安裝依賴庫
sudo apt-get install libxml2-dev openssl libcurl3-openssl-dev libjpeg-dev libpng-dev libxpm-dev libfreetype6-dev libt1-dev libmcrypt-dev libxslt1-dev

4. 進入源代碼文件夾
cd php-5.5.12

5. 運行配置命令
./configure --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 --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-zlib --enable-pdo --with-pdo-mysql

6. 編譯前執行以下的命令
sudo ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/

7. 編譯並安裝
make
sudo make install

8. 生成php的配置文件php.ini
sudo cp ./php.ini-production /usr/local/php/etc/php.ini

9. 啟動php
/usr/local/php/bin/php-cgi -b 9000&

四、安裝Nginx

1. 下載Nginx源代碼包:
wget http://nginx.org/download/nginx-1.7.0.tar.gz

2. 解壓縮
tar -xvf nginx-1.7.0.tar.gz

3. 安裝依賴庫
sudo apt-get install libpcre3 libpcre3-dev

4. 進入源代碼文件夾
cd nginx-1.7.0

5. 執行配置命令
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module

6. 編譯並安裝
make
sudo make install

7. 打開nginx的配置文件:
sudo gedit /usr/local/nginx/conf/nginx.conf&

8. 在配置文件裏找到以下的內容,並將前面的#號去掉。
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
註意:上面的fastcgi_param參數要寫成"$document_root$fastcgi_script_name;"。



9. 啟動nginx
sudo /usr/local/nginx/sbin/nginx&


五、測試nginx。php和mysql的連接

1. 在瀏覽器裏輸入127.0.0.1看看是否出現nginx的提示。

2. 在/usr/local/nginx/html文件夾下新建一個index.php文件,增加以下一行:
<?

php phpinfo() ?

>

3. 改變index.php的屬性:
sudo chmod ugo+rwx -R /usr/local/nginx/html/index.php

4. 在瀏覽器裏輸入127.0.0.1/index.php看看是否出現php的信息。

5. 最後測試php和mysql的連接情況,把index.php中的內容換成下面內容:
<?php
$con = mysql_connect("127.0.0.1","root",null);
mysql_select_db("information_schema", $con);
$result = mysql_query("SELECT * FROM USER_PRIVILEGES");
$row = mysql_fetch_row($result);
echo $row[0];
mysql_close($con);
?

>

6. 在瀏覽器裏輸入127.0.0.1/index.php。出現以下的信息表示nginx。php和mysql間連接正常。
[email protected]

??

ubuntu14.04 安裝LNMP