Ubuntu 9.10 nginx PHP mysql-applicable to later use

Source: Internet
Author: User

1. Install nginx
Run:
Sudo apt-Get intsall nginx
After Ubuntu is installed, the file structure is roughly as follows:
* All configuration files are under/etc/nginx, and each virtual host is already under/etc/nginx/sites-available.
* The program file is stored in/usr/sbin/nginx.
* Logs are stored in/var/log/nginx.
* The Startup Script nginx has been created under/etc/init. d /.

 

* If the default virtual host directory is set to/var/www/nginx-default, you can start nginx to see the effect (ensure that no other service is in use on port 80 ):
Run Ubuntu:
Sudo/etc/init. d/nginx start
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 is no problem with this part.
If the operation fails, sudo killall apache2 can first kill the Apache process.
2. install PHP:
Of course, now we use PhP5. Run:
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

3. Install spawn-fcgi
Run sudo apt-Get install spawn-fcgi
Why is spawn-fcgi installed? It is used to control the PHP-CGI process to prevent process crashes or the efficiency of a single process is too low.
Many people on the Internet say that to use spawn-fcgi, Lighttpd must be installed. In fact, it is not necessary to install spawn-fcgi directly.

The next step is the most frustrating configuration.
Configure nginx and spawn-fcgi to run together
(1) Add a line to the end of the/etc/nginx/fastcgi_params file. You can use sudo gedit/etc/nginx/fastcgi_params to open the file.
Add this row: fastcgi_param script_filename $ document_root $ fastcgi_script_name;

(2). In addition, you need to find the CGI. fix_pathinfo option in the configuration file of the PHP-CGI (which is located in/etc/PhP5/cgi/PHP. ini on Ubuntu) and change it:
CGI. fix_pathinfo = 1;
In this way, the script_filename variable can be used normally in PHP-CGI.

(3) Open the/etc/nginx/sites-available/default file.
In
Server {
Listen 80;
SERVER_NAME localhost;

Add
Root/var/www/nginx-Default
That is, root and SERVER_NAME are at the same level.
This section is equivalent to the default directory of Apache. If this is not available, the system prompts "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;
# Define defastcgi_params;
#}

Modify

Location ~ \. Php $ {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
# Fastcgi_param script_filename/var/www/nginx-default $ fastcgi_script_name; this section is useless. Stay here for a reminder.
Include/etc/nginx/fastcgi_params; # FastCGI parameter file address
}

Then run
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
To start the fast-CGI process, and then we can add this line of code to the bottom of the/etc/rc. Local file, so that the system can start the FastCGI process of PHP at the same time.

Run sudo/etc/init. d/nginx restart to restart nginx
Now, you can test your php file under/var/www/nginx-default.

If the PHP file is opened, the following error occurs: no input file specified.
Please check
Configuring PHP. ini
CGI. fix_pathinfo = 1
Doc_root =
In addition, each virtual machine must set an inaccessible directory based on its own virtual machine. Ensure that the path is correct.
Check the configuration file in/etc/nginx/sites-available. The server contains the root and root address, not the root address in the location.

Command for restarting nginx and PHP-CGI

Nginx: sudo/etc/init. d/nginx restart can also have parameters such as start and stop.
Php-CGI: First kill the process
Sudo killall-hup php5-cgi
Restart
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

The parameter description is as follows:

*-F specifies the location of the execution program of the process that calls FastCGI, Which is set according to the PHP installed on the system
*-A is bound to the ADDR address.
*-P bind to the port
*-S is the path to bind to the UNIX socket
*-C indicates the number of FastCGI processes generated. The default value is 5 (for PHP only)
*-P
PID file path of the Generated Process
* What identity does-U and-G FastCGI use (-u user-G user group) to run? www-data can be used in Ubuntu, and other configuration based on situation, such as nobody and Apache
------------
If you want to install zendoptimizer
Go to Zend official website download, address http://www.zend.com/en/products/guard/downloads
Find the zendoptimizer corresponding to your operating system. If you have not registered the zendoptimizer during the download process, do not register it once. Once and for all.
Decompress the package, open the data folder, and find the so file corresponding to your PHP version. Basically, php5.2 is used now, so in 5_2_x_comp/zendoptimizer. So
You can place this file anywhere, as long as you specify an absolute position in PHP. ini.
For example, we put it under/usr/local.
Sudo mkdir/usr/local/Zend // enter the password as prompted
In the folder you decompress, execute
Sudo CP zendoptimizer. So/usr/local/Zend
Copy the file.
Edit PHP. ini and enter
Sudo gedit/etc/PhP5/cgi/PHP. ini
Add at the end of the file
[Zend optimizer]
Zend_optimizer.optimization_level = 1
Zend_extension = "/usr/local/Zend/zendoptimizer. So"

Restart FastCGI.
Sudo killall-hup php5-cgi
Restart
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
OK. Use the PHP probe.
4. install PHP and MySQL
Sudo apt-Get install mysql-server mysql-Client
In the middle, you will be prompted to enter the root user password and enter it in sequence.

Start MySQL
Sudo/etc/init. d/MySQL start

Mysql-uroot-P
Enter the MySQL password
Mysql> show databases;
+ ------- +
| Database |
+ ------- +
| Information_schema |
| MySQL |
+ ------- +
MySQL has been correctly installed.

Related Article

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.