In practice, configuring Nginx + PHP + MySQL on Ubuntu is a high-performance HTTP and reverse proxy server that has become increasingly popular in recent years. It is also an IMAP/POP3/SMTP proxy server, the pronunciation is "Engine X"
(No wonder I think the previous reading is so awkward. the original reading is wrong ..)
Today, I just got another ec2 quota and tried to deploy this environment on ubuntu.
Tips on ec2 configuration if you need to perform web services on ec2, remember to allow port 80 communication in the security group's inbound settings
1. install FastCGI
FastCGI is a module responsible for Nginx parsing php. For more information about FastCGI, see the following section. The following describes how to install and configure Nginx in the blog-Ubuntu
Nginx is completely lightweight and can be parsed using a third-party FastCGI processor. Therefore, Nginx is flexible, it can be connected to any third-party parsing processor to achieve PHP parsing (in nginx. conf ). Nginx can use spwan-fcgi. Lighttpd needs to be installed in earlier versions, but spawn-fcgi can be directly installed after version 9.10.
Install spwan-fcgi using apt-get of ubuntu.
sudo apt-get install spawn-fcgi
2. install and start nginx
Similarly, you can use apt-get to install nginx.
sudo apt-get install nginx
After installation, the location of each nginx file is roughly as follows:
Configuration file directory:/etc/nginx
Directory of the configuration file for each VM:/etc/nginx/sites-available
Startup Program File:/usr/sbin/nginx
Log File (access. log and error. log):/var/log/nginx
Startup script:/etc/init. d/nginx
Default virtual host Directory:/usr/share/nginx/www
After installation, start the script to control the nginx switch.
Start: sudo/etc/init. d/nginx start
Stop: sudo/etc/init. d/nginx stop
Restart: sudo/etc/init. d/nginx restart
3. install PHP and MySQL and configure PHP to run properly.
Continue to use apt-get to install php, mysql, middleware, and other components
sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql
Go to the nginx virtual host configuration Directory, edit the default file (remember to enable sudo), and find the following code:
location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: # fastcgi_pass unix:/var/run/php5-fpm.sock; # fastcgi_index index.php; # include fastcgi_params; }
Please note that if the configuration in this step is incorrect or the php script is not configured, the browser will pop up the download problem when accessing the php script. Therefore, we do not recommend deploying the code to the server before the configuration is successful, this may cause risks due to misconfiguration. Remove the comments of the three lines of code below the # With php5-fpm and save them, then restart nginx
sudo /etc/init.d/nginx restart
Locate the default directory of your VM host and write a simple php script to save it, for example
Then access the script in the browser. if everything is normal, it will be successful.