一、操作步骤
1.安装Nginx
sudo apt-get update
sudo apt-get install nginx
2.测试Nginx,如果显示如下图则代表安装成功
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's//.*$//' #查看本机IP地址curl http://127.0.0.1 或者 curl http://本机ip
3.安装MySQL
sudo apt-get install mysql-server# 连续输入两次相同的密码
4.安装PHP
sudo apt-get install php5-fpm php5-mysql
5.配置PHP,修改php.ini文件
vim /etc/php5/fpm/php.ini
将cgi.fix_pathinfo=1 设置为 cgi.fix_pathinfo=0cgi.fix_pathinfo=0
启动php-fpmsudo service php5-fpm restart
6.配置Nginx让其使用php-fpm进程
备份/etc/nginx/sites-available/default文件
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.back
修改defalut文件内容如下
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name server_domain_name_or_IP;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
7.重启nginx服务器
sudo service nginx restart
8.在/usr/share/nginx/html/里面建立info.php写入如下内容
<?php phpinfo();?>浏览器输入: http://ip/info.php
显示如下,则代表成功安装lnmp环境
常用扩展安装
sudo apt-cache search php5
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
安装redis服务
安装Redis扩展
sudo apt-get install redis-server
sudo apt-get install php5-redis
安装mcrypt扩展
sudo apt-get install php5-mcrypt libmcrypt4 libmcrypt-dev
sudo apt-get install php5-mcrypt php5-dev
sudo ln -s /etc/php5/fpm/conf.d/20-mcrypt.ini /etc/php5/mods-available/