ubuntu 搭建lnmp

1,ubuntu - 14.04.1
2,ubuntu 自帶php版本爲5.5.9(建議安裝php5.6+)
3,nginx 安裝默認
4,mysql 安裝默認

ubuntu 安裝php5.6
- sudo add-apt-repository ppa:ondrej/php
- sudo apt-get update
- sudo apt-get -y install php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl php5.6-zip php5.6-fpm php5.6-dev php5.6-json

安裝完成後可以執行php -m 查看安裝的module
ps aux | grep php-fpm

安裝nginx:(安裝默認)
- sudo apt-get install nginx
安裝完成後可以執行nginx -v 查看版本
ps aux | grep nginx 

安裝mysql:(安裝默認)
- sudo apt-get install mysql-server mysql-client
會提示你輸入root用戶的密碼:
輸入設置的密碼後,選中確定,安裝完成
安裝完成後可以執行:mysql -u root -p 密碼
進入成功後顯示mysql信息

配置nginx配置文件:(/etc/nginx/conf)
新建配置文件 default.conf 內容如下:
  server {
  listen 80;
  server_name www.test.com;
  root /home/yangshudong/xiaomi/test;
  index index.php index.html index.htm;

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

  location / {
  try_files $uri $uri/ /index.php$is_args$args;
  }

  location ~ \.php($|/) {
  include fastcgi_params;
  fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
  }

  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
  access_log off;
  expires 340d;
  }

  location ~ .*\.(js|css)?$ {
  access_log off;
  expires 2d;
  }

  access_log /home/work/logs/nginx/default.log;
  }

或者修改nginx 配置文件:(/etc/nginx/sites-enabled)
server {
  listen 80;
  server_name www.test.com;
  root /home/yangshudong/xiaomi/test;
  index index.php index.html index.htm;

  location / {
      try_files $uri $uri/ =404;
  }

  location ~ \.php($|/) {
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
  fastcgi_index index.php;
  include fastcgi_params;
  }

  }

操作命令:(service啓動)
sudo service nginx start/stop/restart
sudo nginx -t      測試nginx
sudo nginx -s reload     平滑啓動nginx

sudo service php5.6-fpm start/stop/restart
sudo service mysqld start/stop/restart

可執行文件:(腳本啓動)
sudo /etc/init.d/php5.6-fpm start     (啓動php)
sudo /etc/init.d/nginx start     (啓動nginx)
sudo /etc/init.d/mysql start     (啓動mysql)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章