1024programmer Nginx The installation and configuration process of Nginx+PHP+MySQL+Tomcat server environment

The installation and configuration process of Nginx+PHP+MySQL+Tomcat server environment

The installation steps are as follows:

1. Nginx

1.1 Add source and install

1.1.1 sudo add-apt-repository ppa:nginx/stable

1.1.2 sudo apt-get update

1.1.3 sudo apt-get install nginx

1.2 Testing

1.2.1 Start nginx: sudo /etc/init.d/nginx start

1.2.2 Access: http://localhost

appears “Welcome to
nginx!”, the installation is successful.

1.2.3 Close nginx: sudo /etc/init.d/nginx stop

2.PHP

2.1 Installation

2.1.1 sudo apt-get install php5-cli php5-cgi
php5-fpm php5-mcrypt php5-mysql

php5-fpm: One of the ways to cooperate with nginx, the other is: spawn-fcgi;

php5-mysql: access mysql;

2.2 Modify nginx configuration

2.2.1 sudo vim
/etc/nginx/sites-available/default

2.2.2 Change the line of index to: “index index.html index.htm
index.php;”

Uncomment the following to support php scripts:

location ~ \.php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

2.3 Testing

2.3.1 Create a new directory: sudo mkdir /var/www/

2.3.2 Modify nginx directory: sudo vim
/etc/nginx/sites-available/default

Change the root line to “root
/var/www;”

2.3.3 Create a new test file: sudo vim /var/www/test.php

Input: “”

2.3.4 Start nginx: sudo /etc/init.d/nginx start

2.3.5 Access: http://localhost/test.php

The php details appear and the configuration is successful.

2.3.6 Close nginx: sudo /etc/init.d/nginx stop

3. MySQL

3.1 Installation

3.1.1 sudo apt-get install mysql-server

During the installation process, you will be asked to set a root password.

3.2 Testing

3.2.1 Login to MySQL: mysql -u root -p

Enter password

3.2.2 The “mysql>” prompt appears, and the login is successful.

3.2.3 Exit MySQL: exit

Attachment: phpMyAdmin

For instructions, see: http://zh.wikipedia.org/wiki/PhpMyAdmin

Download phpMyAdmin-3.4.3.1-all-languages.tar.gz: http://www.phpmyadmin.net/home_page/downloads.php

Download and extract sudo tar zxvf
phpMyAdmin-3.4.3.1-all-languages.tar.gz

Copy to /var/www/: sudo cp
phpMyAdmin-3.4.3.1-all-languages ​​/var/www/

Modify the folder name to phpMyAdmin:sudo mv
/var/www/phpMyAdmin-3.4.3.1-all-languages ​​/var/www/phpMyAdmin

After starting nginx, visit: http://localhost/phpMyAdmin, you can manage MySQL.

4. Tomcat 7

4.1 Installation

4.1.1
Download and save to ~/download/directory: http://tomcat.apache.org/download-70.cgi#7.0.16

4.1.2 Decompression: sudo tar zxvf
~/Downloads/apache-tomcat-7.0.16.tar.gz

4.1.3 move: sudo mv ~/downloads/apache-tomcat-7.0.16
/opt/tomcat7

4.2 Configuration

4.2.1 Modify /opt/tomcat7/bin/catalina.sh

Add: JAVA_HOME=/opt/oracle/JRockit

4.3 Testing

4.3.1 Start tomcat7: sudo /opt/tomcat7/bin/startup.sh

4.3.2 Access: http://localhost:8080/

The cat icon appears and the configuration is successful.

4.3.3 Close tomcat7: sudo /opt/tomcat7/bin/shutdown.sh

4.4 Integration with nginx

4.4.1 Modify tomcat configuration /opt/tomcat7/conf/server.xml

Set Change to

4.4.2 Modify proxy_params under nginx: sudo vim
/etc/nginx/proxy_params

Add:

client_max_body_size 10m;

client_body_buffer_size 128k;

 
proxy_connect_timeout 90;

proxy_send_timeout 90;

proxy_read_timeout 90;

proxy_buffer_size 4k;

proxy_buffers
4
32k;

proxy_busy_buffers_size 64k;

proxy_temp_file_write_size 64k;

4.4.3 Modify ngingx configuration: sudo vim
/etc/nginx/sites-available/default

Modify index behavior: “index
index.html index.htm index.php index.jsp;”

at “location ~
Add after \.php${…}”php configuration section (see php configuration 2.2.2 above):

location ~
\.jsp${

index
index.jsp;

proxy_pass
http://localhost:8080;

include
proxy_params;

}

4.5 Test

4.5.1 Create a new directory: sudo mkdir /var/www/test

4.5.2 Create a new JSP file: sudo vim /var/www/test/test.jsp

Enter:

<%

out.println(“IP:”);

out.println(request.getHeader(“x-forwarded-for”));

%>

4.5.3 Start tomcat7: sudo /opt/tomcat7/bin/startup.sh
4.5.4 Start nginx: sudo /etc/init.d/nginx start
4.5.5 Access: http://localhost/test/test.jsp

“IP:192.168.11.22” appears and the configuration is successful.

Explain, because the nginx proxy function is used here, so you need to use request.getHeader(“x-forwarded-for”) to get the IP; request.getRemoteHost() will get the proxy IP, namely: 127.0.0.1.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/the-installation-and-configuration-process-of-nginxphpmysqltomcat-server-environment/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索