1、拿到一个全新的Ubuntu 12.04服务器,首先要更新系统软件
apt-get update
apt-get upgrade
2、安装apt源管理工具
apt-get install python-software-properties
3、添加nginx和php的安装源
add-apt-repository ppa:nginx/stable
add-apt-repository ppa:ondrej/php5 这个是php5.5
add-apt-repository ppa:ondrej/php5-5.6 这个是php5.6 建议都安装此版本
apt-get update
//如果出现如下错误提示:
//W: GPG error: http://ppa.launchpad.net trusty InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4F4EA0AAE5267A6C
//运行如下命令即可:
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FAF69C646FF368B7 //注意修改keys的内容
4、安装mysql
apt-get install mysql-server
5、安装php(包含一些常用的扩展组件)
apt-get install php5 php-pear php5-mysql php5-fpm php5-dev curl libcurl3 libcurl3-dev php5-curl php5-mcrypt php5-gd
6、安装nginx
apt-get install nginx
修改配置文件vim /etc/nginx/site-enabled/default
root /www/ #网站根目录到/www
location ~ \.php$ {
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;
}
#打开nginx的php5-fpm支持
重启相关服务
service php5-fpm start
service nginx start
7、测试
vim /www/index.php
<?php
echo phpinfo();
浏览器http://url_to_host/即可
8、后续安装gd库支持,由于很久没更新apt-get源信息了,导致安装失败
apt-get update
apt-get install php5-gd