在Ubuntu 12.4 下安裝 nginx, MySQL, PHP

來源:互聯網
上載者:User

標籤:

 

LNMP是時下很流行的網站配置,我在配置蟬大師伺服器的時候順帶把經驗做個分享,蟬大師的網址是:http://www.ddashi.com/

 

1、第一步, 跟新apt-get

輸入:

sudo apt-get update

 

2、第二步,安裝Mysql

輸入:

sudo apt-get install mysql-server php5-mysql

安裝過程中mysql會要求你給資料庫設定密碼,輸入兩次後繼續……

輸入:

sudo mysql_install_db

繼續輸入:

sudo /usr/bin/mysql_secure_installation

會提示你輸入剛剛設定的mysql密碼,輸入即可

問你是否要更改密碼,輸入N即可

 

接下來Mysql會提示幾個問題,填入下邊對應的y或n即可

By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y                                             ... Success!Normally, root should only be allowed to connect from ‘localhost‘.  Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] y... Success!By default, MySQL comes with a database named ‘test‘ that anyone canaccess.  This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] y ... Success!Cleaning up...

 

3、第三步、安裝Nginx

依次輸入:

echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/nginx-stable.listsudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8Csudo apt-get updatesudo apt-get install nginx

啟動nginx:

sudo service nginx start

這時候你可以訪問你的網域名稱或IP地址來看看Nginx是否工作了

輸入如下命令可以知道你的IP:

ifconfig eth0 | grep inet | awk ‘{ print $2 }‘

 

4、第四步,安裝PHP

sudo apt-get install php5-fpm

配置PHP:

sudo nano /etc/php5/fpm/php.ini

找到, cgi.fix_pathinfo=1, 把1改為0即可,如下:

cgi.fix_pathinfo=0

接著:

sudo nano /etc/php5/fpm/pool.d/www.conf

找到, listen = 127.0.0.1:9000, 把 127.0.0.1:9000 改成 /var/run/php5-fpm.sock.

listen = /var/run/php5-fpm.sock

儲存退出,啟動PHP

sudo service php5-fpm restart

配置Nginx

sudo nano /etc/nginx/sites-available/default

啟用PHP,綁定目錄和index檔案

[...]server {        listen   80;             root /var/www;        index index.php index.html index.htm;        server_name example.com;        location / {                try_files $uri $uri/ /index.html;        }        error_page 404 /404.html;        error_page 500 502 503 504 /50x.html;        location = /50x.html {              root /usr/share/nginx/www;        }        # pass the PHP scripts to FastCGI server listening on the php-fpm socket        location ~ \.php$ {                try_files $uri =404;                fastcgi_pass unix:/var/run/php5-fpm.sock;                fastcgi_index index.php;                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;                include fastcgi_params;                        }}[...]

 

可以了,建個檔案試試吧:

sudo nano /var/www/info.php

 

如果覺得有價值,歡迎加我(keerol)或關注我微博(weibo/yanghongjin)

 

在Ubuntu 12.4 下安裝 nginx, MySQL, PHP

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.