天天看點

Ubuntu 14.04 配置php+nginx+mysql

資料庫:

sudo apt-get install mysql-server mysql-client      

然後設定資料庫ROOT使用者的秘密,兩次,确認。然後資料庫安裝成功

Nginx :

sudo add-apt-repository ppa:nginx/stable

sudo apt-get update

sudo apt-get install nginx      

這個指令可以從PPA軟體管理裡面安裝最新的穩定版本的Nginx

nginx -v
      

可以檢視到安裝的版本是nginx/1.6.0

安裝之後,要啟動nginx

sudo service nginx start      

然後在Firefox裡面輸入localhost 或者 http://serverip (你的ip),看到welcome的字樣,說明安裝成功。 

Ubuntu 14.04 配置php+nginx+mysql

PHP5

這裡是通過PHP-FPM來讓PHP5在nginx裡工作,當然如果喜歡FastCGI的朋友,可以自己去弄。

sudo apt-get install php5-fpm      

安裝完畢, 現在來修改nginx的配置吧

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

如果不懂得vi,可以查些資料,vi編輯文檔,需要文檔777權限 (chomd 777 /etc/...) 按i 為編輯模式,ESC退出編輯模式,進入指令模式,wq退出儲存,x删除某個字元,dd删除行。也可以使用gedit來編輯,注意gedit備份檔案的功能

以下是某個例子:

server {
	listen 80 default_server;
	listen [::]:80 default_server ipv6only=on;

	root /usr/share/nginx/html;
	index index.php index.html index.htm;

	# Make site accessible from http://localhost/
	server_name localhost;

	location / {

		try_files $uri $uri/ /index.php;

	}

	location /doc/ {
		alias /usr/share/doc/;
		autoindex on;
		allow 127.0.0.1;
		allow ::1;
		deny all;
	}

	#
	error_page 500 502 503 504 /50x.html;
	location = /50x.html {
		root /usr/share/nginx/html;
	}

	location ~ \.php$ {

		# With php5-fpm:
                try_files $uri =404;
		fastcgi_pass unix:/var/run/php5-fpm.sock;
		fastcgi_index index.php;
		include fastcgi_params;
	}

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	location ~ /\.ht {
		deny all;
	}
}      

然後,reload nginx:

sudo service nginx reload      

測試PHP是否安裝成功

sudo vi /usr/share/nginx/html/info.php      

内容:

<?php
phpinfo();
?>      

打開浏覽器,檢視

Ubuntu 14.04 配置php+nginx+mysql

參考檔案:http://ubuntuhandbook.org/index.php/2013/10/install-nginx-php5-mysql-lemp-ubuntu-1310/