Heim > php教程 > php手册 > 小黑小波比.Ubuntu14.04下配置Nginx+php5+Mariadb开发环境

小黑小波比.Ubuntu14.04下配置Nginx+php5+Mariadb开发环境

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-06 19:40:12
Original
1002 Leute haben es durchsucht

我的Ubuntu14.04版本 Nginx是一个免费、开源、高性能的HTTP服务器。Nginx以其稳定的性能、丰富的功能、简单的 配置 、低资源消耗而闻名。下面介绍你在Ubuntu下安装支持PHP和MySQL的nginx服务器。 1、安装前注意事项 首先Ubuntu的软件安装要用root权限,所以

我的Ubuntu14.04版本


Nginx是一个免费、开源、高性能的HTTP服务器。Nginx以其稳定的性能、丰富的功能、简单的配置、低资源消耗而闻名。下面介绍你在Ubuntu下安装支持PHP和MySQL的nginx服务器。

1、安装前注意事项

首先Ubuntu的软件安装要用root权限,所以命令前要全部加Sudo,然后输入密码。否则会显示权限不够。

其次安装前最好先运行apt-get update更新本地软件。以免安装过程中出现错误。

如果可以的话,用su root 然后输入root密码

2、安装Mariadb


MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。在存储引擎方面,使用XtraDB(英语:XtraDB)来代替MySQL的InnoDB。 MariaDB由MySQL的创始人Michael Widenius(英语:Michael Widenius)主导开发,他早前曾以10亿美元的价格,将自己创建的公司MySQL AB卖给了SUN,此后,随着SUN被甲骨文收购,MySQL的所有权也落入Oracle的手中。MariaDB名称来自Michael Widenius的女儿Maria的名字。

运行语句

shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql & (在这里增加sudo )

http://blog.csdn.net/xuechongyang/article/details/69728773、安装nginx

运行

apt-get install nginx

启动nginx

/etc/init.d/nginxstart

访问你服务器的IP地址http://localhost会看到nginx欢迎界面





 

将nginx加入开机启动

update-rc.d nginxdefaults

4、安装PHP5

PHP5通过FastCGI在nginx下运行。乌班图提供一个FastCGI-enabled PHP5安装包,可以这样安装。

apt-get install php5-cgi php5-mysqlphp5-curl php5-gd php5-idn php-pear php5-imagick php5-imapphp5-mcrypt php5-memcache php5-mhash php5-ming php5-pspellphp5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpcphp5-xsl

打开 /etc/php5/cgi/php.ini配置文件,在最后一行添加cgi.fix_pathinfo = 1

vi/etc/php5/cgi/php.ini

 

[...]

cgi.fix_pathinfo = 1

 

Ubuntu没有独立的FastCGI安装包,所以用lighttpd里面的spawn-fcgi,运行下面命令:

apt-get installlighttpd

安装完成时会出现lighttpd无法启动的错误,因为nginx占用了80端口。运行

update-rc.d -f lighttpdremove

使lighttpd开机不启动。

我们安装lighttpd只需要其中的/usr/bin/spawn-fcgi,来运行FastCGI进程。运行

spawn-fcgi --help

查看它的命令帮助。

以用户www-data在本机localhost的9000端口下运行一个PHP FastCGI进程,输入以下命令

/usr/bin/spawn-fcgi -a 127.0.0.1 -p9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P/var/run/fastcgi-php.pid

加入开机运行,以免每次开机运行此命令。

vi /etc/rc.local

在最后一行加入下面语句(在exit前面)。

[...]

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000-u www-data -g www-data -f /usr/bin/php5-cgi -P/var/run/fastcgi-php.pid

[...]

 

5、nginx配置

编辑配置文件

vi/etc/nginx/nginx.conf

首先(可选) 增加worker processes 的数量,设置keepalive_timeout到适当的值:

 

[...]

worker_processes 5;

[...]

   keepalive_timeout  2;

[...]

 

接着配置虚拟主机,默认虚拟主机路径是/etc/nginx/sites-available/default

vi/etc/nginx/sites-available/default

 

[...]

server {

       listen   80;

       server_name  _;

 

       access_log /var/log/nginx/localhost.access.log;

 

       location / {

               root  /var/www/nginx-default;

               index  index.php index.html index.htm;

       }

 

       location /doc {

               root   /usr/share;

               autoindex on;

               allow 127.0.0.1;

               deny all;

       }

 

       location /images {

               root   /usr/share;

               autoindex on;

       }

 

       #error_page  404 /404.html;

 

       # redirect server error pages to the static page/50x.html

       #

       error_page   500 502 503504  /50x.html;

       location = /50x.html {

               root  /var/www/nginx-default;

       }

 

       # proxy the PHP scripts to Apache listening on127.0.0.1:80

       #

       #location ~ \.php$ {

               #proxy_pass  http://127.0.0.1;

       #}

 

       # pass the PHP scripts to FastCGI server listening on127.0.0.1:9000

       #

       location ~ \.php$ {

               fastcgi_pass  127.0.0.1:9000;

               fastcgi_index  index.php;

               fastcgi_param  SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;

               include       /etc/nginx/fastcgi_params;

       }

 

       # deny access to .htaccess files, if Apache's documentroot

       # concurs with nginx's one

       #

       location ~ /\.ht {

               deny  all;

       }

}

[...]

 

可以直接复制过去,以免修改过程中出现错误。

修改好了,重启nginx

/etc/init.d/nginxrestart

在默认目录/var/www/nginx-default建立PHP文件info.php

 

vi/var/www/nginx-default/info.php

 

phpinfo();

?>

 

在浏览器访问http://localhost/info.php



Server API 行里会看到PHP通过FastCGI运行。支持MySQL

 

好了,安装到此结束。



Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage