Ubuntu14.04 lnmp安装搭建
1.#首先更新源
[email protected]:~$ sudo apt-get update
2.#安装nginx
[email protected]:~$ sudo apt-get install nginx
#测试nginx 输入curl http://127.0.0.1 或curl http://本机ip地址
[email protected]:~$ curl http://127.0.0.1
#出现如下代表安装nginx成功
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
3.安装mysql
[email protected]:~$ sudo apt-get install mysql-server
#输入两次相同的密码,密码为mysql管理账户所使用
┌──────────────────────┤ 正在设定 mysql-server-5.5
│ While not mandatory, it is highly recommended that you set a password │
│ for the MySQL administrative "root" user. │
│ │
│ If this field is left blank, the password will not be changed. │
│ │
│ New password for the MySQL "root" user: │
│ │
│ _______________________________________________________________________ │
│ │
│ <确定> │
│ │
└──────────────────────────────────── ┘
┌────────┤ 正在设定 mysql-server-5.5 ┐
│ │
│ │
│ Repeat password for the MySQL "root" user: │
│ │
│ ___________________________________ │
│ │
│ <确定> │
│ │
└────────────────────── ┘
4.#安装PHP:
[email protected]:~$ sudo apt-get install php5-fpm php5-mysql
5.配置php
#备份配置文件
[email protected]:~$ sudo cp /etc/php5/fpm/php.ini /etc/php5/fpm/php_backup.ini
#修改php.ini文件 取消有安全隐患的pathinfo模式
[email protected]:~$ sudo vim /etc/php5/fpm/php.ini
#找到cgi.fix_pathinfo=1,把1改成0,并去掉;号
#启动php-fpm
[email protected]:~$ sudo service php5-fpm restart
php5-fpm stop/waiting
6.配置nginx,让其使用php5-fpm进程
php5-fpm start/running, process 14175
#备份配置文件
[email protected]:~$ sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default_backup
#修改配置文件
[email protected]:~$ sudo vim /etc/nginx/sites-enabled/default
#查看修改后的配置文件
[email protected]:~$ cat /etc/nginx/sites-available/default |grep -v '^#'
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index 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;
# 在浏览器中访问的.php文件,实际读取的是 $document_root(网站根目录)下的.php文件 -- 也就是说当访问127.0.0.1/index.php的时候,需要读取网站根目录下面的index.php文件,如果没有配置这一配置项时,nginx不回去网站根目录下访问.php文件,所以返回空白
include fastcgi_params;
}
}
[email protected]:~$ sudo service nginx restart
* Restarting nginx nginx
...fail!
[email protected]:~$ man nginx
OPTIONS
-t Tests nginx configuration and exit.
[email protected]:~$ sudo nginx -t
nginx: [emerg] directive "server_name" is not terminated by ";" in /etc/nginx/sites-enabled/default:29
nginx: configuration file /etc/nginx/nginx.conf test failed
#修改/etc/nginx/sites-enabled/default第29行
[email protected]:~$ sudo vim /etc/nginx/sites-enabled/default
[email protected]:~$ cat /etc/nginx/sites-enabled/default |grep -v '^#'
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index 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;
}
}
[email protected]:~$ sudo service nginx restart
* Restarting nginx nginx
...done.
#测试
#.在/usr/share/nginx/html/里面建立info.php写入如下内容<?php phpinfo();?>
[email protected]:~$ sudo vim /usr/share/nginx/html/info.php
<?php phpinfo();?>
在浏览器输入http://ip/info.php显示如下
将制作的php网页页面原文件上传至/usr/share/nginx/html/目录下即可
[email protected]:~$ sudo vim /usr/share/nginx/html/test.html
[sudo] password for wyj:
<html>
<title>Test!</title>
<body> Hello world.</body>
</html>
[email protected]:~$ cd /usr/share/nginx/html/
[email protected]:/usr/share/nginx/html$ ls
50x.html index.html info.php test.html
参考博客:https://www.jianshu.com/p/9412e90b33f2