Ubuntu-15. 04安装配置LNMP服务
一、操作系统版本信息
[email protected]:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.4 LTS
Release: 14.04
Codename: trusty
二、安装MYSQL
(1)开始安装:
apt-get install mysql-server libmysqld-dev
(2)提示设置MySQL root用户名密码(root/bdyun)
(3)确认root用户密码
(4)MySQL版本
[email protected]:~# mysql -V
mysqlVer 14.14 Distrib 5.5.50, for debian-linux-gnu (x86_64) using readline 6.3
三、安装Nginx
(1)安装:
apt-get install nginx
(2)启动服务
# service nginx start
或者
# /etc/init.d/nginx start
(3)Web测试是否成功安装,http://121.40.*.*/(主机地址)跳出Welcome to nginx!说明配置成功
四、安装PHP5
(1)开始安装
apt-get install php5-fpm php5-mysql
(2)配置nginx.conf
配置前作备份
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
配置/etc/nginx/nginx.conf
vi /etc/nginx/nginx.conf
搜索文字worker_processes找到worker_processes auto;改为worker_processes 4;
搜索文字keepalive_timeout找到keepalive_timeout 65;改为keepalive_timeout 2;
(3)配置Nginx让其使用php-fpm进程
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak
vi /etc/nginx/sites-available/default
这里修改如下
或者直接复制替换
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;
}
}
(4)重新加载nginx
service nginx reload
(5)配置PHP,修改php.ini文件
vi /etc/php5/fpm/php.ini
设置,取消分号;将1改为0
cgi.fix_pathinfo=0:
(6)重新加载 PHP-FPM:
service php5-fpm reload
五、测试运行
测试PHP
创建探针文件info.php到/usr/share/nginx/html目录下
vi /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
浏览器访问探针文件http://121.40.*.*/info.php
如果出现PHP版本信息说明配置成功
(2)测试mysql
创建测试文件sqltest.php到/usr/share/nginx/html目录下
vi /usr/share/nginx/html/sqltest.php
<?php
$link=mysql_connect("localhost","root","ubuntu");
if(!$link) echo "FAILD!";
else echo "OK!";
?>
访问http://121.40.*.*sqltest.php
如果出现OK字符说明mysql配置成功