Procedure for installing and configuring nginx + php + mysql in ubuntu _ PHP Tutorial

Source: Internet
Author: User
Install and configure nginx, php, and mysql on ubuntu. 1. update 1sudoapt-getupdate2, the file structure after installing the nginx1sudoapt-getintsallnginxUbuntu is roughly: * all the configuration files are under etcng.pdf, and each virtual 1 , Update

1 Sudo apt-get update

2, InstallationNginx

1 Sudo apt-get intsall nginx

UbuntuAfter installation, the file structure is roughly:
*All the configuration files are in/Etc/nginxLower,And each virtual host is already in/Etc/nginx/sites-availableLower
*Program file in/Usr/sbin/nginx *Logs are stored in/Var/log/nginxMedium
*And already/Etc/init. d/The startup script is created underNginx
*The default virtual host directory is/Var/www/nginx-default

You can startNginxTo see the effect(Make sure that80No other services on the port):

1 Sudo/etc/init. d/nginx start

#Or simply

1 Service nginx start

Then open the browser,ViewHttp: // localhost/See if you see"Welcome to nginx!"If you see,The installation is successful..
Of course,Basically,This one won't go wrong..If the operation fails,Yes

1 Sudo killall apache2

KillApacheProcess
3, InstallationPhp

Sudo apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode

4, InstallationSpawn-fcgi
Why installSpawn-fcgiWhat about,It is used to controlPhp-cgiProcess,To prevent process crashes or the efficiency of a single process is too low.
Many people on the Internet say they want to use it.Spawn-fcgiInstallation requiredLighttpd,Actually not necessary,Can be directly installedSpawn-fcgi
Run:

1 Sudo apt-get install spawn-fcgi

5, Configuration
Next is the most annoying configuration..
ConfigurationNginxAndSpawn-fcgiCombined operation
(1 ).In/Etc/nginx/fastcgi_paramsLast file,Add a row,Available

1 Sudo vi/etc/nginx/fastcgi_params

Join this row:

1 Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;

(2 ).In additionPHP-CGIConfiguration file(UbuntuThe configuration file is located in/Etc/php5/cgi/php. ini)Medium,FindCgi. fix_pathinfoOption,Change:

1 Cgi. fix_pathinfo = 1;

This wayPhp-cgiCan be used normallySCRIPT_FILENAMEThis variable.
(3 ).Open/Etc/nginx/sites-available/defaultFILE In

123 Server {listen 80; server_name localhost;

AddWebAbsolute root directory address,Here we useNginxDefault address

1 Root/var/www/nginx-default

That isRootAndServer_nameThe same level is equivalentApacheDefault directory
If not,Easy to executePhpFile,Will prompt"No input file specified".
I used to go around a large circle to find out the problem..Then modify

123456 # Location ~ . Php $ {# fastcgi_pass 127.0.0.1: 9000; # fastcgi_index index. php; # fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name; # inclustcgi_params ;#}

Modify

1234 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 ;#IncludeFastcgiParameter file address
6StartFast_cgiProcess

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, Set boot startFastcgiProcess and start

1 Sudo vi/etc/rc. local

Add next line

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

IfPhpFile appears: No input file specifiedPlease checkPhp. iniIs being configured

1 Cgi. fix_pathinfo = 1
1 Doc_root =

And,Set different directories for each virtual machine based on its own virtual machine,Make sure the path is correct..
Check/Etc/nginx/sites-availableIn the configuration file, ServerContainsRootAnd address insteadLocationInternalRoot
Start

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 parameter description is as follows:
*-FCallFastCGIThe execution program location of the process.,Based onPHPSpecific settings
*-Bind to addressAddr
*-PBind to portPort
*-SBindUnix socketPathPath
*-CSpecifiedFastCGINumber of processes,Default value:5 (Used onlyPHP)
*-PSpecifies the processPIDFile path
*-UAnd-G FastCGIIdentity used(-UUser-GUser Group)Run, UbuntuYou can useWww-data,Other configurations as needed,For exampleNobody,ApacheNow you canWebA probe orPhpFile tested
8, InstallationMysql

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

Input will be prompted in the middleRootUser password,Enter them in sequence..
StartMySQL

1 Sudo/etc/init. d/mysql start

TestMysqlIs the service normal?:
Run

1 Mysql-uroot-p

InputMysqlPassword

1 Show databases;

If you see the following content
| Database |
| Information_schema |
| Mysql |
ThenMysqlInstalled correctly.
So Far, UbuntuUnderNginx + php + mysqlThe installation is complete..

Http://www.bkjia.com/PHPjc/326928.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326928.htmlTechArticle1, update 1 sudoapt-getupdate 2, install nginx 1 sudoapt-getintsallnginx after Ubuntu installation file structure is roughly: * all the configuration files are under/etc/nginx, and each virtual...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.