日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Ubuntu >内容正文

Ubuntu

在ubuntu上搭建LNMP服务器

發布時間:2023/12/10 Ubuntu 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在ubuntu上搭建LNMP服务器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

LNMP = Linux + Nginx + MySQL + PHP
安裝Nginx

執行以下命令即可:

apt-get install nginx

不過源里的版本是0.7.65,不喜歡老舊的玩意,可以嘗試編譯安裝。

編譯安裝nginx.
1.準備編譯環境

apt-get install libpcre3-dev build-essential libssl-dev

在這里 http://nginx.org/en/download.html 能找到nginx的tar球,最新的官方穩定版是
1.2.0.
執行:

cd /opt/
wget http://nginx.org/download/nginx-1.2.0.tar.gz
tar -zxvf nginx-1.2.0.tar.gz
cd /opt/nginx-1.2.0/

configure:

./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module

configure完成后會輸出nginx的一些相關信息,

nginx path prefix: “/opt/nginx”
nginx binary file: “/opt/nginx/sbin/nginx”
nginx configuration prefix: “/opt/nginx/conf”
nginx configuration file: “/opt/nginx/conf/nginx.conf”
nginx pid file: “/opt/nginx/logs/nginx.pid”
nginx error log file: “/opt/nginx/logs/error.log”
nginx http access log file: “/opt/nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”

make,安裝,執行:

make
make install

給nginx進程添加用戶nginx:

adduser --system --no-create-home --disabled-login --disabled-password --group nginx

下載并安裝啟動腳本:

wget -O init-deb.sh http://library.linode.com/assets/552-init-deb.sh
mv init-deb.sh /etc/init.d/nginx
chmod +x /etc/init.d/nginx
/usr/sbin/update-rc.d -f nginx defaults

啟動一下試試:

/etc/init.d/nginx start

如果輸出正常,那nginx就安裝成功了。
配置虛擬主機:

如果從源里安裝的nginx,那nginx配置文件位于/etc/nginx/sites-enabled
下面是一個虛擬主機的配置實例:

server {
? ? listen ? 80;
? ? server_name www.example.com example.com;
? ? access_log /srv/www/example.com/logs/access.log;
? ? error_log /srv/www/example.com/logs/error.log;

? ? location / {
? ? ? ? root ? /srv/www/example.com/public_html;
? ? ? ? index ?index.html index.htm;
? ? }
}

注意,配置文件中出現的目錄必須存在,nginx并不會自動創建他們,所以,還需要執行:

mkdir -p /srv/www/example.com/public_html
mkdir -p /srv/www/example.com/logs

如果是編譯安裝的版本,相關路徑見上文configure部分,配置文件位于/opt/nginx/conf,可以直接在nginx.conf添加 server段,為了便于管理,還是把虛擬主機獨立出來好,修改nginx.conf, 如下在http段添加include部分。

http {
# [...]

include /opt/etc/nginx/sites-enabled/*;

# [...]
}

添加完虛擬主機后,別忘了重啟以下nginx服務。

/etc/init.d/nginx restart

刪除虛擬主機只需要刪除對應的配置文件并重新啟動一下下nginx就好。

安裝php with fastcgi

執行:

apt-get install php5-cli php5-cgi psmisc spawn-fcgi

執行下面的命令會下載并安裝fastcgi的控制腳本:

cd /opt/
wget -O php-fastcgi-deb.sh http://library.linode.com/assets/554-php-fastcgi-deb.sh
mv /opt/php-fastcgi-deb.sh /usr/bin/php-fastcgi
chmod +x /usr/bin/php-fastcgi
wget -O init-php-fastcgi-deb.sh http://library.linode.com/assets/553-init-php-fastcgi-deb.sh
mv /opt/init-php-fastcgi-deb.sh /etc/init.d/php-fastcgi
chmod +x /etc/init.d/php-fastcgi
/etc/init.d/php-fastcgi start
update-rc.d php-fastcgi defaults

然后在虛擬主機的配置文件里面添加php支持,示例如下:

server {
? ? server_name www.example.com example.com;
? ? access_log /srv/www/example.com/logs/access.log;
? ? error_log /srv/www/example.com/logs/error.log;
? ? root /srv/www/example.com/public_html;

? ? location / {
? ? ? ? index index.html index.htm index.php;
? ? }

? ? location ~ \.php$ {
? ? ? ? include /etc/nginx/fastcgi_params;
? ? ? ? fastcgi_pass ?127.0.0.1:9000;
? ? ? ? fastcgi_index index.php;
? ? ? ? fastcgi_param SCRIPT_FILENAME /srv/www/example.com/public_html$fastcgi_script_name;
? ? }
}

最后重啟一下nginx服務:

/etc/init.d/nginx restart

安裝MySQL:

執行:

apt-get install mysql-server php5-mysql

安裝過程中會要求輸入數據庫的初始密碼,

還可以執行一下:

mysql_secure_installation

禁用root的遠程登錄即可。

如果需要重新設置MySQL的密碼,執行:

dpkg-reconfigure mysql-server-5.0

最后重啟一下fastcgi:

/etc/init.d/php-fastcgi restart

至此LNMP安裝完成。
本文翻譯自Linode的Library文章:http://library.linode.com/lemp-guides/ubuntu-10.04-lucid#sph_id7
文中的操作系統是Ubuntu 10.04,你可以訪問上面的連接獲取更多信息。個人更推薦一鍵傻瓜安裝包:

總結

以上是生活随笔為你收集整理的在ubuntu上搭建LNMP服务器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。