安装nginx
配置nginx源
vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
安装nginx
yum install nginx
启动nginx
systemctl start php-fpm.service
安装php环境
配置php源
yum install epel-release
yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
安装php
yum --enablerepo=remi-php73 install php php-cli php-common php-devel php-embedded php-gd php-mbstring php-pdo php-xml php-fpm php-mysqlnd php-opcache php-mcrypt php-pear php-pecl-memcached php-pecl-mongodb php-pecl-redis
修改php配置文件
修改user和group为nginx,与nginx服务用户相同
egrep -v ";|^$" /etc/php-fpm.d/www.conf
[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache
检查语法
php-fpm -t
启动php-fpm
systemctl start php-fpm.service
nginx整合php
nginx配置文件
vim /etc/nginx/conf.d/php.conf
server {listen 80;server_name localhost;location / {root /im;index index.php index.html index.htm;}location ~ \.php$ {root /im;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}
php测试页面
mkdir /im
vim index.php
<?php
phpinfo();
?>
访问php页面
composer安装
composer是PHP依赖管理工具,需要PHP 5.3.2或更高版本,运行php -v来检查已安装的PHP版本
安装composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/bin/composer
composer --version
配置国内镜像
composer config -g repo.packagist composer https://packagist.phpcomposer.com
更新Composer
composer self-update
安装MySQL
https://blog.csdn.net/wuxingge/article/details/100774308
安装redis
安装redis
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
tar xf redis-5.0.7.tar.gz -C /opt/
cd /opt
ln -s redis-5.0.7 redis
cd redis
make
make install
配置redis
cp redis.conf /etc/
修改配置文件 /etc/redis.conf
daemonize yes
bind 127.0.0.1 192.168.0.30 #本机IP
protected-mode no
dir /opt/redis
管理文件
vim /etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /etc/redis.conf
PrivateTmp=true[Install]
WantedBy=multi-user.target
启动
systemctl start redis.service
php后端服务部署
git clone https://gitee.com/raingad/im-instant-chat.git
#进入项目目录,执行:
composer install#启动
php start.php start #调试时使用
php start.php start -d
前端部署
node部署参考
https://blog.csdn.net/wuxingge/article/details/134859856
git clone https://gitee.com/raingad/im-chat-front.git
进入项目目录,执行
npm install
修改服务端域名
修改项目根目录下的 .env.development 文件,将VUE_APP_BASE_API的值改为自己的后端域名,构建后放服务端在运行时直接获取服务端的域名
构建
npm run build
将打包好的文件(dist目录)里面的所有文件覆盖到后端的public目录下即可
nginx配置文件
vim php.conf
server {listen 80;server_name localhost;location / {root /im/im-instant-chat/public;if (!-e $request_filename){rewrite ^(.*)$ /index.php?s=$1 last; break;}}location /wss {proxy_pass http://127.0.0.1:8282;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "Upgrade";proxy_set_header X-Real-IP $remote_addr;}}
最后访问页面有问题