Nginx + php + mysql configuration in ubuntu

Source: Internet
Author: User

Nginx + php + mysql configuration in ubuntu 1. Update www.2cto.com 1 sudo apt-get update2 and install nginx 1 sudo apt-get intsall nginx after Ubuntu is installed. The file structure is roughly as follows: * All configuration files are under/etc/nginx, in addition, each VM has been arranged in the/etc/nginx/sites-available www.2cto.com * program file. the/usr/sbin/nginx * log is placed in/var/log/nginx * and already in/etc/init. d/, and then create the startup script nginx * the default virtual host directory is set to/var/www/nginx-default. You can start nginx to see the effect (make sure there are no other ports on port 80 ). service in use): 1 sudo/etc/init. d/nginx start # or simple 1 service nginx s Tart then open the browser and check http: // localhost/to see if "Welcome to nginx!" is displayed !" If yes, the installation is successful. of course, basically, there will be no problems with this part. if the operation fails, can first 1 sudo killall apache2 to kill apache process 3, install php 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 4. Why is spawn-fcgi installed, it is used to control php-cgi processes to prevent process crashes or the efficiency of a single process is too low. many people on the Internet say that spawn-fcgi must be used. Installing lighttpd is not necessary. You can directly install spawn-fcgi to run: 1 sudo apt-get install spawn-fcgi 5. The configuration is followed by the most troublesome configuration. configure Nginx and spawn-fcgi for running (1 ). add a line at the end of the/etc/nginx/fastcgi_params file. You can use 1 sudo vi/etc/nginx/fastcgi_params to add this line: 1fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name ). in addition, the configuration file in the PHP-CGI (Ubuntu on this configuration file is located in/etc/php5/cgi/php. ini), find cgi. fix_pathinfo option, changed to 1cgi. fix_pathinfo = 1; so that php-cgi can use SCRIPT_FILENAME normally This variable. (3 ). open the/etc/nginx/sites-available/default file and add the absolute address of the web root directory under 123 server {listen 80; server_name localhost, here we use the default nginx address 1 root/var/www/nginx-default, that is, the same level of root and server_name, which is equivalent to the default directory of apache, it is easy to prompt "No input file specified" when executing the php file ". I found the problem only when I went around a large circle here. then modify # location ~. Php $ {# fastcgi_pass 127.0.0.1: 9000; # fastcgi_index index. php; # fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name; # modify inclustcgi_params; #} to 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; # parameter file address containing fastcgi 6. Start fast_cgi process 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 to start fastcgi process and start 1 sudo vi/etc/rc. local Add the 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 if opening the PHP file appears: no input file specified check php. 1 CGI in ini configuration. fix_pathinfo = 1 1doc_root = also, each virtual machine must set different directories based on its own virtual machine. Ensure that the path is correct. check the configuration file in/etc/nginx/sites-available, start 1fast-cgisudo/usr/bin/spawn-fcgi-a 127.0.0.1-p 9000-C 5-u www-data-g www- the meaning of the data-f/usr/bin/php5-cgi-P/var/run/fastcgi-php.pid parameters is as follows *-f specifies the location of the execution program of the process that calls FastCGI, set *-a to bind to the address addr *-p to the port *-s to bind to the path *-C of the unix socket according to the PHP installed on the system. fastCGI process count, the default value is 5 (for PHP only) *-P, which specifies the PID file path of the generated process *-u and-g FastCGI (-u user-g user group, www-data can be used in Ubuntu. Other configurations are as follows, for example, nobody, apache, etc. Now you can place a probe or PHP file in the web Root directory to test it. 8. If you install mysql 1 sudo apt-get install mysql-server mysql-client, you will be prompted to enter Root. user Password, enter them in sequence. start MySQL 1 sudo/etc/init. d/mysql start test whether mysql service is normal: Run 1 mysql-uroot-p enter mysql password 1 show databases; if you see the following content | Database | information_schema | mysql |, mysql is correctly installed. so far, nginx + php + mysql installation in ubuntu is complete.

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.