配置 Vagrant 上 Ubuntu 的 Web 开发环境

Vagrant安装及设置可看《使用 Vagrant 构建现代化 Web 开发环境》

使用 SSH 连接管理虚拟机中的 Ubuntu

IP:127.0.0.1
端口:2222
账户及密码:vagrant

一、添加源及更新软件

为了使系统的更新、下载时速度提升,可以使用国内的源服务器,如网易的

编辑源
su -//切换至root,密码vagrant
sudo vi /etc/apt/sources.list

软件源信息

网易源
deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse

将以上源信息添加到上述源文件的最前端

刷新源及更新软件
sudo apt-get update && sudo apt-get upgrade

二、MariaDB

MariaDB 比起 MySQL 在性能、效率上都有所提升,十分推荐使用。

更新源及安装 MariaDB
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://mirrors.hustunique.com/mariadb/repo/10.0/ubuntu trusty main'
sudo apt-get update
sudo apt-get install mariadb-server

安装过程会要求设置数据库的 root 账户密码。

三、PHP

安装 PHP
sudo apt-get install php5-fpm php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
编辑 php.ini
vi /etc/php5/fpm/php.ini
配置PHP
cgi.fix_pathinfo=0//去掉前面的#并把1改成0
重启 PHP
service php5-fpm restart

四、Nginx

安装 Nginx
sudo apt-get install nginx

配置 Web 目录到共享目录,上一篇的 Vagrant 配置,我设置了共享目录在虚拟机的 /Vagrant 下,所以我要把 Web 目录也设置到 /Vagrant 下,就可以实现同步开发

配置 Nginx
su -
vi /etc/nginx/sites-available/default

找到并修改成

修改 Nginx 配置文件
server {
	listen 80 default_server;
	listen [::]:80 default_server ipv6only=on;

	root /vagrant;//改成/vagrant,因为上一篇我们把同步目录设置在/vagrant
	index index.php index.html index.htm;//增加index.php

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

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
		# Uncomment to enable naxsi on this location
		# include /etc/nginx/naxsi.rules
	}

	# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
	#location /RequestDenied {
	#	proxy_pass http://127.0.0.1:8080;    
	#}

	#error_page 404 /404.html;

	# redirect server error pages to the static page /50x.html
	#
	#error_page 500 502 503 504 /50x.html;
	#location = /50x.html {
	#	root /usr/share/nginx/html;
	#}

	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
	#
	location ~ \.php$ {//去掉#
		try_files $uri =404;//增加这行
	   	fastcgi_split_path_info ^(.+\.php)(/.+)$;//去掉#
	#	# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
	#
	#	# With php5-cgi alone:
	#	fastcgi_pass 127.0.0.1:9000;
	#	# With php5-fpm:
		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;//去掉#
	}//去掉#
}
重启 Nginx
service nginx restart

 

Conners Hua

欢迎入群讨论:Telegram >QQ群 42302626 >(不交流不和谐话题)

您可能还喜欢…

发表评论

电子邮件地址不会被公开。