Ubuntu下安装LNMP
2014-04-06 02:07
Ubuntu
LNMP
Nginx
MySQL
PHP
摘要:每次重装服务器都要装一遍 LNMP,干脆整理一份完整步骤,包括 Nginx 配置、PHP-FPM 和常用扩展。
- 安装MySQL
sudo apt-get install mysql-server mysql-client
安装过程中需要输入root用户的密码 2. 安装Nginx
sudo apt-get install nginx
安装完成后重启一下Nginx服务
sudo service nginx restart
重启后就可以访问loalhost或者127.0.0.1地址了,会看到Nginx的欢迎界面。 3. 安装php-fpm作为我们的php解析
sudo apt-get install php5-fpm
- 这时候可以修改一下Nginx的站点配置,Nginx的站点配置文件存放在/etc/nginx/sites-availble/default
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default ipv6only=on; ## listen for ipv6
root /usr/share/nginx/www;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
# Only for nginx-naxsi : process denied requests
#location /RequestDenied {
# For example, return an error code
#return 418;
#}
#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/www;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
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;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
主要将原本php解析被注释掉的一些代码去注释,其次你也可以更改你站点的目录。注:第48行和50行选择其中一个注释掉即可,但是要注意你的/var/run/下是否有php5-fpm.sock这个文件。 5. 安装php5相关的一些组建,通过下面的这条命令来查看都有哪些组件可以安装。
sudo apt-cache search php5
一般情况下,安装这些组件就足够了。
sudo apt-get install 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
- 重启服务
sudo service php5-fpm restart
sudo service nginx restart