搭建nginx
一般空的云服务器上,C、C++的编译器什么的都是没有的,需要我们去安装,不过也简单,就几条命令:
安装 gcc-c++ 编译器
yum install gcc-c++
安装一些依赖
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
如果报错:Error: Multilib version problems found,则使用
yum update (依赖名称)
yum update -y pcre pcre-devel
下载nginx安装包
wget -c https://nginx.org/download/nginx-1.19.10.tar.gz
安装
如果需要使用https访问的,需要把ssl模块编译进来,可使用 ./configure --with-http_stub_status_module --with-http_ssl_module
- 注:报 make leave xxx目录 一般可以不管的吧,在 /usr/local/nginx 目录下面已经有了nginx 直接启动就可以的,不知道会对后面运行有什么影响没有
tar -zxvf nginx-1.19.10.tar.gz
cd nginx-1.19.10
./configure ( 或 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module)
make
make install
cd /usr/local/nginx/sbin/
./nginx
执行到这里如果放开了80端口,那么直接使用你的 IP 访问就能出来nginx的欢迎页面
其他一些命令
./nginx -s stop
./nginx -s quit
./nginx -s reload
安装mysql
下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装刚刚下载下来的mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
修改enabled的值,确定安装的源 (大概看看,好像不用修改)
vim /etc/yum.repos.d/mysql-community.repo
安装mysql
yum install mysql-community-server
启动mysql
systemctl start mysqld
systemctl status mysqld
systemctl restart mysqld
修改密码,远程登录操作
这个说是mysql7是随机的密码,可以去看看怎么直接找密码,我一般直接跳过登录重新设置下密码
在 /etc/my.cnf 下的 [mysqld] 下面加上skip-grant-tables
然后mysql -hlocalhost -uroot -p 直接一直回车就能进数据库了
密码规则可以用 show variable like ‘validate_password%’; 命令查看
下面是修改密码的几种方式
mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
或者
mysql> set password for 'root'@'%'=password('你的密码');
如果碰上以上两个都不能解决,直接修改
use mysql
select * from user;
update user set password=password('你的密码') where host='localhost' and user='root';
如果是mysql7的话,密码的字段是authentication_string
建立远程登录用户(要远程连接的话必须放开3306端口,或者你自己设置的端口)
mysql> show variables like '%password%';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
安装PHP
centos7 运行
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装
yum install php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel
执行到这里php就算是安装完了
查看或者安装扩展
php -m
yum install php70w-xml
安装memcache、reids (需要缓存的可以安装下,具体用法百度)
yum install -y memcached redis
源码安装redis
# 下载源码
wget https://download.redis.io/releases/redis-5.0.13.tar.gz
# 解压文件
tar -zxvf redis-5.0.13.tar.gz
# 进入到源码目录
cd redis-5.0.13
make PREFIX=/usr/local/redis install
# 把配置文件copy到执行目录
cd /usr/local/redis/bin
cp /usr/local/src/redis-5.0.13/redis.conf ./
修改配置文件
# 后台启动
vi redis.conf daemonize no => yes
# 请求密码
requirepass
源码安装php & 扩展
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --with-openssl --with-mcrypt --enable-ftp --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --with-freetype-dir=/usr --with-libxml-dir=/usr --with-xmlrpc --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli --with-curl --enable-bcmath
需要复制php-fpm.conf
文件,以及www.conf
文件
目录 /usr/local/php/etc/...
;修改www.conf
的用户以及组
https://www.cnblogs.com/lxwphp/p/9777547.html
配置nginx
nginx.conf 结束的 } 前加上下面一行
include sites-enabled/*.conf;
一般习惯在conf中建两个目录,sites-available和sites-enabled,把sites-available这个目录下的软链接到sites-enabled这个目录中
不使用证书的配置:
server {
listen 80 default;
server_name www.yuanjy.com;
server_tokens off;
charset utf-8;
access_log /var/log/nginx/access-dev.yuanjy.com.log;
error_log /var/log/nginx/error-dev.yuanjy.com.log;
set $host_path "/Users/yuanjiayang/tmp/www";
set $yii_bootstrap "index.html";
root $host_path;
index $yii_bootstrap;
location / {
try_files $uri $uri/ /$yii_bootstrap?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index $yii_bootstrap;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/usr/local/var/run/php5-fpm.sock;
fastcgi_connect_timeout 300s;
fastcgi_read_timeout 300s;
fastcgi_send_timeout 600s;
fastcgi_ignore_client_abort on;
fastcgi_pass_header "X-Accel-Expires";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTP_REFERER $http_referer;
include fastcgi_params;
}
location ~* \.(js|css|less|png|jpg|jpeg|gif|ico|woff|ttf|svg|tpl)$ {
expires 24h;
}
location = /favicon.ico {
try_files $uri /static/img/favicon.ico;
}
}
使用SSL证书的配置:
server {
listen 80;
server_name api.yuanjy.com;
server_tokens off;
rewrite ^/(.*) https://api.yuanjy.com/$1 permanent;
}
server {
listen 443;
server_name api.yuanjy.com;
server_tokens off;
charset utf-8;
userid on;
userid_name analyse_id;
userid_expires 5y;
ssl on;
ssl_certificate cert/api.yuanjy.com_bundle.crt;
ssl_certificate_key cert/api.yuanjy.com.key;
access_log /data/logs/nginx/apiyuanjy/access-api.yuanjy.com.log;
error_log /data/logs/nginx/apiyuanjy/error-api.yuanjy.com.log;
set $host_path "/data/www/wwwroot/apiyuanjy/backend/web";
set $yii_bootstrap "index.php";
root $host_path;
index $yii_bootstrap;
allow 120.241.13.103; #局域网
allow 133.15.22.82; #内部监控服务器
#deny all;
location / {
try_files $uri $uri/ /$yii_bootstrap?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index $yii_bootstrap;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9001;
fastcgi_connect_timeout 120s;
fastcgi_read_timeout 120s;
fastcgi_send_timeout 120s;
fastcgi_ignore_client_abort on;
fastcgi_pass_header "X-Accel-Expires";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTP_REFERER $http_referer;
include fastcgi_params;
}
location ~* \.(js|css|less|png|jpg|jpeg|gif|ico|woff|ttf|svg|tpl)$ {
expires 24h;
}
location = /favicon.ico {
try_files $uri /static/img/favicon.ico;
}
}
安装java
下载一个java的.gz包,解压,设置好环境变量
yum install java-1.8.0-openjdk* -y
安装tomcat
下载tomcat包,解压,就可以启动
wget https://yuanjy.oss-cn-shanghai.aliyuncs.com/owner/apache-tomcat-8.5.43.tar.gz