Environment: ubuntu12.0.4ltsngloud (pronounced "enginex") is a free, open-source, and high-performance HTTPserver. Nginx is famous for its stability, rich feature sets, simple configuration, and low resource consumption. This article will show you how to install Nginx, php5 (and php-fpm), and mysql on ubuntu12.0.4LTS. I. Before installation, make a simple description that the domain name I use is example.com and the IP address is 21.
Environment: Ubuntu 12.0.4 LTS
Nginx (pronounced "engine x") is a free, open-source, and high-performance HTTP server. Nginx is famous for its stability, rich feature sets, simple configuration, and low resource consumption. This article will show you how to install Nginx, php5 (and php-fpm), and mysql on ubuntu 12.0.4 LTS.
I. A brief description before installation
My domain name is example.com and the IP address is 218.198.177.252. You can change these settings as needed. In the following sections, I will use the root permission to install the required software. Therefore, switch to the root user: sudo su first.
Ii. Install MySQL
Apt-get install mysql-server mysql-client
The installation process will prompt you to provide a password for the MySQL root User-this password is available for root @ localhost, but also for the root@example.com, so you need to manually specify a password for the MySQL root User:
New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword
Iii. Install Nginx
Apt-get install nginx
1. Start nginx
/Etc/init. d/nginx start
2. Open the browser and enter http: // 127.0.0.1. If you see Welcome to nginx !, The installation is successful. The default website root directory of nginx on ubuntu 12.0.4 LTS is/usr/share/nginx/www.
4. Install PHP5
PHP5 can work on nginx via PHP-FPM (FastCGI Process Manager) is an optional FastCGI that adds some useful features, especially for busy sites.
Note: Nginx does not support direct calling or parsing of external programs. All external programs (including PHP) must be called through the FastCGI interface.
Apt-get install php5-fpm
The PHP-FPM is a daemon (init script file in/etc/init. d/php5-fpm) that runs a FastCGI server with port 9000.
5. Configure nginx. The following is my local configuration file.
1. The nginx configuration file is in/etc/nginx. conf, and vim/etc/nginx. conf is as follows:
User www-data; // specifies the Nginx Worker process running user and user group
Worker_processes 4; // specify the number of processes enabled by Nginx. Each Nginx process consumes an average of 10-20 mb of memory.
Pid/var/run/nginx. pid; // specifies the location of the stored file for the process id
Events {// used to specify the Nginx working mode and the maximum number of connections
Use epoll;
Worker_connections 768;
# Multi_accept on;
}
Http {
##
# Basic Settings // Basic Settings
##
Sendfile on;
Tcp_nopush on;
Tcp_nodelay on;
Keepalive_timeout 65;
Types_hash_max_size 2048;
# Server_tokens off;
# Server_names_hash_bucket_size 64;
# Server_name_in_redirect off;
Include/etc/nginx/mime. types;
Default_type application/octet-stream;
##
# Logging Settings // specify the log storage path
##
Access_log/var/log/nginx/access. log;
Error_log/var/log/nginx/error. log;
##
# Gzip Settings // enable Gzip Compression
##
Gzip on;
Gzip_disable "msie6 ";
Gzip_vary on;
Gzip_proxied any;
Gzip_comp_level 6;
Gzip_buffers 16 8 k;
Gzip_http_version 1.1;
Gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml + rss text/javascript;
##
# Nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
# Include/etc/nginx/naxsi_core.rules;
##
# Nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
# Passenger_root/usr;
# Passenger_ruby/usr/bin/ruby;
##
# Virtual Host Configs // Virtual Host Configuration
##
Include/etc/nginx/conf. d/*. conf;
Include/etc/nginx/sites-enabled /*;
}
# Mail {
# See sample authentication script:
# Http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# Auth_http localhost/auth. php;
# Pop3_capabilities "TOP" "USER ";
# Imap_capabilities "IMAP4rev1" "UIDPLUS ";
#
# Server {
# Listen localhost: 110;
# Protocol pop3;
# Proxy on;
#}
#
# Server {
# Listen localhost: 143;
# Protocol imap;
# Proxy on;
#}
#}
2. the VM is defined in server {}. The default file is/etc/nginx/sites-available/default, vim/etc/nginx/sites-available/default.
Server {
Listen 80; # listen for ipv4; this line is default and implied
Listen [:]: 80 default ipv6only = on; # listen for ipv6
Root/usr/share/nginx/www;
Index. php index.html index.htm;
# Make site accessible from http: // localhost/
Server_name _;
Location /{
# First attempt to serve request as file, then
# As directory, then fall back to index.html
Try_files $ uri // index.html;
}
Location/doc {
Root/usr/share;
Autoindex on;
Allow 127.0.0.1;
Deny all;
}
Location/images {
Root/usr/share;
Autoindex off;
}
# Error_page 404/404 .html;
# Redirect server error pages to the static page/50x.html
#
Error_page 500 502 503 x.html;
Location =/50x.html {
Root/usr/share/nginx/www;
}
# Proxy the PHP scripts to Apache listening on 127.0.0.1: 80
#
# Location ~ \. Php $ {
# Proxy_pass http: // 127.0.0.1;
#}
# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ \. Php $ {
Try_files $ uri = 404;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Include fastcgi_params;
}
# Deny access to. htaccess files, if Apache's document root
# Concurs with nginx's one
#
Location ~ /\. Ht {
Deny all;
}
}
3. Save the file to make the configuration take effect./etc/init. d/nginx reload
4. Create a PHP test file vim/usr/share/Nginx/www/info. php In the default website root directory of nginx.
Phpinfo ();
?>
5. Open the browser and enter http: // 127.0.0.1/info. php.
You can see that PHP5 has been working through FPM/FastCGI. For more information, see the Server API line. Scroll down to see that all modules are available in PHP5. MySQL is not listed yet, meaning MySQL does not support PHP5.