alibaba cloud linux+JDK+TOMCAT+NGINX+PHP+MYSQL配置实践
以下是一个基于阿里云服务器配置Linux环境下的JDK、Tomcat、NGINX和PHP的示例配置实践:
- 安装JDK
# 更新软件包
sudo yum update -y
# 安装Java开发工具包
sudo yum install java-1.8.0-openjdk-devel -y
# 设置JAVA_HOME环境变量
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
# 验证安装
java -version
- 安装Tomcat
# 下载Tomcat
wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.62/bin/apache-tomcat-9.0.62.tar.gz
# 解压Tomcat
tar -xvzf apache-tomcat-9.0.62.tar.gz
# 移动Tomcat到指定目录
sudo mv apache-tomcat-9.0.62 /opt/tomcat
# 设置环境变量
export CATALINA_HOME=/opt/tomcat
# 启动Tomcat
/opt/tomcat/bin/startup.sh
- 安装NGINX
# 添加NGINX仓库
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# 安装NGINX
sudo yum install nginx -y
# 启动NGINX
sudo systemctl start nginx
# 设置开机自启动
sudo systemctl enable nginx
- 安装PHP
# 安装PHP和PHP FPM
sudo yum install php php-fpm -y
# 启动PHP FPM
sudo systemctl start php-fpm
# 设置开机自启动
sudo systemctl enable php-fpm
- 配置NGINX与Tomcat
# 编辑NGINX配置文件
sudo vi /etc/nginx/conf.d/default.conf
# 在server块中添加以下内容
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
# 重启NGINX
sudo systemctl restart nginx
- 配置Tomcat与PHP集成
# 编辑Tomcat server.xml文件,添加web应用和AJP连接器
sudo vi /opt/tomcat/conf/server.xml
# 在<Host>标签内添加以下内容
<Context path="" docBase="/usr/share/nginx/html" />
# 下载PHP解压工具和PHP源码
cd /opt
wget http://php.net/get/php-7.tar.gz/from/this/mirror.tar.gz
tar -xvzf mirror.tar.gz
cd php-7*
# 配置PHP(可以根据需要添加或修改配置)
./configure --prefix=/usr/bin/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pear --with-pdo-mysql --with-
评论已关闭