Ubuntu使用apt-get安装Nginx,MySql,PHP5

一、Nginx安装

安装key

# cd /tmp
# wget http://nginx.org/keys/nginx_signing.key
# sudo apt-key add nginx_signing.key
# rm -rf nginx_signing.key

修改/etc/apt/sources.list文件增加如下内容:

deb http://nginx.org/packages/mainline/ubuntu/ codename nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ codename nginx

Ubuntu各版本对应Codename如下:

Version Codename
10.04 lucid
11.10 oneiric
12.04 precise
12.10 quantal
13.04 raring

使用apt-get安装并启动

# sudo apt-get update
# sudo apt-get install nginx
# sudo service nginx start

站点配置文件样本 :

server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.php;

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_ADMIN_VALUE open_basedir=$document_root/;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 12h;
}
#access_log /var/log/nginx/log/host.access.log main;
}

默认安装目录: /etc/nginx/
默认SSL和虚拟主机配置目录: /etc/nginx/conf.d/
默认日志保存目录: /var/log/nginx/
默认网站文件目录: /usr/share/nginx/html
默认配置文件: /etc/nginx/nginx.conf
默认访问日志文件: /var/log/nginx/access.log
默认错误日志文件: /var/log/nginx/error.log

二、MYSQL安装

# sudo apt-get install mysql mysql-server
# sudo service mysqld start
# sudo mysqladmin -u root password 'your-password'

配置文件路径:/etc/my.cnf
数据库路径:/var/lib/mysql

三、PHP5安装

# sudo apt-get install php5-common php5-fpm php5-cli php5-mysql php5-mcrypt php5-gd php5-tidy php5-xmlrpc
# sudo chown www-data:www-data /etc/php5/fpm/php-fpm.conf
# sudo service php5-fpm start

配置文件路径:/etc/php5/fpm/php.ini
SESSION保存路径:/var/lib/php5