Based on the ubuntu nginx+php+mysql installation configuration steps

  • 2020-06-01 08:38:19
  • OfStack

1, update,

1 sudo apt-get update

2. Install nginx

1 sudo apt-get intsall nginx

The file structure of Ubuntu after installation is roughly as follows:
* all configuration files are under /etc/nginx, and each virtual host is already under /etc/nginx/ sites-available
* the program files are in /usr/sbin/nginx * logs are in /var/log/nginx
* the startup script nginx has been created under /etc/ init.d /
* the default virtual host directory is set to /var/www/ nginx-default

Now you can launch nginx to see what happens (make sure no other services are in use on port 80):

1 sudo /etc/init.d/nginx start

# or something simple

1 service nginx start

Then open your browser and look at http://localhost/ to see if you see "Welcome to nginx!" If so, the installation was successful.
Of course, basically, this will not be a problem. If the operation is not successful, you can first

1 sudo killall apache2

Kill the apache process
3. Install 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. Install spawn-fcgi
Why install spawn-fcgi, which controls the php-cgi process to prevent process crashes or single process inefficiency?
Many people on the Internet say you have to install lighttpd to use spawn-fcgi, but actually you don't have to, you can just install spawn-fcgi

1 sudo apt-get install spawn-fcgi

5, configuration,
Next comes the most frustrating configuration.
Configure Nginx and spawn-fcgi to run together
(1). At the end of the /etc/nginx/fastcgi_params file, add 1 line

1 sudo vi /etc/nginx/fastcgi_params

Join this trip:

1 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

(2). Also need in PHP - CGI configuration file (Ubuntu on this configuration file located in/etc/php5 / cgi/php ini), find cgi. fix_pathinfo option, is amended as:

1 cgi.fix_pathinfo=1;

In this way, php-cgi can normally use the variable SCRIPT_FILENAME.
(3). Open /etc/nginx/ sites-available /default

1 2 3 server { listen 80; server_name localhost;

Next, add the absolute address of the web root directory, where the default address of nginx is used

1 root /var/www/nginx-default

So root and server_name are equivalent to the default directory for apache
Without this, it is easy to be prompted "No input file specified" when executing the php file.
I went all the way around here before I found the problem. Then I modified it

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

Modified into

1 2 3 4 location ~ .php$ { fastcgi_pass; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;

include/etc/nginx/fastcgi_params; # contains the parameter file address for fastcgi
6. Start the fast_cgi process

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

7. Set to boot the fastcgi process and start it

1 sudo vi /etc/rc.local

Add the next row

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

If you open the php file :No input file specified please check the configuration of php.ini

1 cgi.fix_pathinfo=1 1 doc_root=

Also, each virtual machine has a different directory for its own virtual machine, so make sure the path is correct.
Check that in the configuration file under /etc/nginx/ sites-available,server contains root and the address instead of root within location
Start the

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

The parameter has the following meaning
* -f specifies the execution location of the process that calls FastCGI, depending on the PHP installed on the system
* -a is bound to the address addr
* -p is bound to port port
* -s is bound to the path path of unix socket
* -C specifies the number of processes to generate FastCGI, with default of 5(for PHP only)
* -P specifies the PID file path of the generated process
* -u and -g FastCGI use what identity (-u user-g user group),Ubuntu can use www-data, other configuration, such as nobody, apache can now put a probe in the web root directory or php file test 1
8. Install mysql

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

You will be prompted to enter the Root user password in the middle.
Start the MySQL

1 sudo /etc/init.d/mysql start

Test whether mysql service is normal:

1 mysql -uroot -p

Enter the mysql password

1 show databases;

If you look at the following
| Database |
| information_schema |
| mysql |
Then mysql has been installed correctly.
At this point, the installation of nginx+php+mysql under ubuntu is complete.

Related articles: