Home  >  Article  >  Backend Development  >  Specific steps for installation and configuration of nginx+php+mysql based on ubuntu_PHP tutorial

Specific steps for installation and configuration of nginx+php+mysql based on ubuntu_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:11:07892browse

1、更新

1
sudo apt-get update

2、安装nginx

1
sudo apt-get intsall nginx 

Ubuntu安装之后的文件结构大致为:
所有的配置文件都在/etc/nginx,并且每个虚拟主机已经安排在了/etc/nginx/sites-available
*程序文件在/usr/sbin/nginx * 日志放在了/var/log/nginx
*并已经在/etc/init.d/下创建了启动脚本nginx
默认的虚拟主机的目录设置在了/var/www/nginx-default

下面可以启动nginx来看看效果(请确保80端口没有其他服务在使用):

1
sudo /etc/init.d/nginx start 

#或者简单的

1
service nginx start 

然后打开浏览器,查看http://localhost/ 看看是否看到了Welcome to nginx!” 如果看到了,说明安装成功.
当然,基本上,这块儿都不会出问题如果运行不成功,可以先

1
sudo killall apache2 

杀掉apache进程
3、安装php

sudo apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-sqlite php5-xsl

 

4、安装spawn-fcgi
为什么要安装spawn-fcgi,它用来控制php-cgi进程,以防止进程崩溃或是单进程的效率太低.
网上很多人都说要使用spawn-fcgi必须得安装lighttpd,实际上不必要,可以直接安装spawn-fcgi
运行:

1
sudo apt-get install spawn-fcgi 

5、配置
接下来就是最让人头疼的配置.
配置Nginxspawn-fcgi配合运行
(1)./etc/nginx/fastcgi_params 文件最后,加入一行,可以用

1
sudo vi /etc/nginx/fastcgi_params 

加入此行:

1
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

(2).另外需要在PHP-CGI的配置文件(Ubuntu 上此配置文件位于/etc/php5/cgi/php.ini),找到cgi.fix_pathinfo选项,修改为:

1
cgi.fix_pathinfo=1;

这样php-cgi方能正常使用SCRIPT_FILENAME这个变量.
(3).打开/etc/nginx/sites-available/default文件在

1
2
3
server {
listen 80;
server_name localhost;

下面添加web根目录的绝对地址,这里是使用的是nginx的默认地址

1
root /var/www/nginx-default

rootserver_name同级这段即相当于apache的默认目录
如果没有这个的话,容易在执行php 文件的时候,会提示No input file specified.
我就曾在此绕了好大个圈子才发现问题.然后修改

1
2
3
4
5
6
#location ~ .php$ {
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#includefastcgi_params;
#}

修改成

1
2
3
4
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; #包含fastcgi的参数文件地址
6、开始fast_cgi进程

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

7、设置开机启动fastcgi进程并启动

1
sudo vi /etc/rc.local

添加下一行

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

如果打开php文件出现:No input file specified请检查php.ini的配置中

1
cgi.fix_pathinfo=1 
1
doc_root=

还有,每个虚机要根据自己不同的虚机设置不同的目录,要保证这个路径正确.
检查/etc/nginx/sites-available下的配置文件中,server内包含 root 及地址 而非location内的root
启动

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

The meaning of the parameters is as follows
* -f Specify the execution program location of the process that calls FastCGI,according to Specific settings for PHP installed on the system
* -a is bound to the address addr
* -p bind to portport
* -s bind to path of unix socketpath
* -C Specifies the number of processes generated by FastCGI, Defaults to 5 ( only for PHP)
* -PSpecifies the of the spawned process PIDFile path
* -u and -g FastCGIWhat identity to use(-u User -g User Group)Run, Ubuntu You can use www-data, and other configurations according to the situation , such as nobody, apache, etc. Now you can put a probe in the root directory of web or phpTested the file
8, installedmysql

1
sudo apt-get install mysql-server mysql-client
1

sudo apt-get install mysql-server mysql-client

You will be prompted to enter the Rootuser password ,
in order to start .
1
sudo /etc/init.d/mysql start
MySQL

1 sudo /etc/init.d/mysql start

Test
1
mysql -uroot -p
mysql
whether the service is normal

:Run

1
1
 show databases;
mysql -uroot -p





Entermysqlpassword
1 show databases;
If you see the following content | Database | >.At this point

, the installation of

under ubuntu is completed.
http://www.bkjia.com/PHPjc/326928.html
www.bkjia.com
truehttp: //www.bkjia.com/PHPjc/326928.htmlTechArticle1. Update 1 sudoapt-getupdate 2. Install nginx 1 sudoapt-getintsallnginx The file structure of Ubuntu after installation is roughly as follows: * All configuration files are under /etc/nginx, and each virtual...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn