官方推荐的首选需要安装docker环境
但是官方的docker没有nginx而且我们公司的服务器,是没有使用docker的。同时部署子站点和主站点,而且还需手动配置。现在记录一下自己的手动安装过程
安装方式有两种:
1.docker安装方式
推荐mac和win10的用户使用
首先下载安装 docker http://get.daocloud.io/#install-docker-for-mac-windows (国内镜像)
然后去github下载swoft框架
git clone https://github.com/swoft-cloud/swoft
cd swoft
docker-compose up
只需几步,docker下的swoft就运行起来了。详细的docker使用方式,请参考docker官网
2. vagrant+virtualbox安装
已经封装好的box 百度网盘下载地址:
https://pan.baidu.com/s/1wFtIhai_TFPn6174cLh1hQ
用vagrant导入box即可。
3.在centos7虚拟机原始安装
安装过程如下:
首先安装一些系统需要的组件
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libXpm-devel autoconf
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libmcrypt-2.5.8-13.el7.x86_64.rpm
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libmcrypt-devel-2.5.8-13.el7.x86_64.rpm
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/m/mhash-0.9.9.9-10.el7.x86_64.rpm
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/m/mcrypt-2.6.8-11.el7.x86_64.rpm
yum localinstall -y libmcrypt-2.5.8-13.el7.x86_64.rpm libmcrypt-devel-2.5.8-13.el7.x86_64.rpm mhash-0.9.9.9-10.el7.x86_64.rpm mcrypt-2.6.8-11.el7.x86_64.rpm
rm -rf libmcrypt-2.5.8-13.el7.x86_64.rpm libmcrypt-devel-2.5.8-13.el7.x86_64.rpm mhash-0.9.9.9-10.el7.x86_64.rpm mcrypt-2.6.8-11.el7.x86_64.rpm
安装nginx
在nginx官方找到最新稳定版本的nginx: http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar -zxvf nginx-1.12.2.tar.gz
rm -rf nginx-1.12.2.tar.gz
cd nginx-1.12.2/
./configure --prefix=/usr/local/nginxmake && make install
cd /usr/local/nginx/sbin
./nginx
vim /etc/rc.d/init.d/nginx
写入以下脚本参考:https://www.cnblogs.com/KenChung/p/8079313.html
#设置脚本权限
#设置脚本开机启动
#启动nginx
chmod 775 /etc/rc.d/init.d/nginx
chkconfig nginx on
/etc/rc.d/init.d/nginx start
#把nginx加入系统变量
echo 'export PATH=$PATH:/usr/local/nginx/sbin'>>/etc/profile && source /etc/profile
安装php7
我们这里选择的是php7.1.15版本
wget http://cn2.php.net/distributions/php-7.1.15.tar.gz
tar zxvf php-7.1.15.tar.gz&& rm -rf php-7.1.15.tar.gz
cd php-7.1.15/
./configure --prefix=/usr/local/php7 --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --enable-pcntl --with-openssl --enable-soap --with-pear --with-png-dir --with-pcre-regex --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf --with-gettext --with-curl --enable-sockets --enable-bcmath --enable-xml --with-bz2 --enable-zip --with-freetype-dir=/usr/include/freetype
make&& make install
cp php.ini-production /usr/local/php7/lib/php.ini
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
echo -e'\nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n' >> /etc/profile && source /etc/profile
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
service php-fpm start
安装redis、hiredis 和 nghttp2
nghttp2和hiredis,基于c的http和redis通信
①:安装redis和hiredis
hiredis
wget https://github.com/redis/hiredis/archive/v0.13.3.tar.gz -O hiredis.tar.gz
mkdir -p hiredis&& tar -xf hiredis.tar.gz -C hiredis --strip-components=1
rm -rf hiredis.tar.gz&& cd hiredis&& make -j&& make install&& ldconfig
redis
wget http://download.redis.io/releases/redis-4.0.9.tar.gz
tar xzf redis-4.0.9.tar.gz&& rm -rf redis-4.0.9.tar.gz&& cd redis-4.0.9&& make MALLOC=libc
cd src&& make install
cd ../
sed -i's/daemonize no/daemonize yes/g' ./redis.conf
sed -i's/protected-mode yes/protected-mode no/g' ./redis.conf
sed -i's/bind 127.0.0.1/#bind 127.0.0.1/g' ./redis.conf
mkdir /etc/redis
cp ./redis.conf /etc/redis/6379.conf&& cp ./utils/redis_init_script /etc/init.d/redis
cd /etc/init.d
sed -i'1a #chkconfig: 2345 90 10' ./redis
sed -i'2a #description: Redis is a persistent key-value database' ./redis
chkconfig redis on
service redis start
②:安装nghttp2
wget https://github.com/nghttp2/nghttp2/releases/download/v1.30.0/nghttp2-1.30.0.tar.bz2 && tar -jxvf nghttp2-1.30.0.tar.bz2 && cd nghttp2-1.30.0 && ./configure && make -j && make install
编译安装swoole 2.2.0版本
sed -i'$a export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib' ~/.bash_profile
source ~/.bash_profile
wget https://github.com/swoole/swoole-src/archive/v2.2.0.tar.gz -O swoole.tar.gz&& mkdir -p swoole&& tar -xf swoole.tar.gz -C swoole --strip-components=1 && rm -rf swoole.tar.gz
cd swoole/&& /usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config --enable-async-redis --enable-mysqlnd --enable-coroutine --enable-openssl --enable-http2&& make -j&& make install
sed -i'$a extension=swoole.so' /usr/local/php7/lib/php.ini
service php-fpm restart
安装mysql数据库
#安装mysql 5.6
wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-server-5.6.21-1.rhel5.x86_64.rpm&& wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-devel-5.6.21-1.rhel5.x86_64.rpm&& wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-client-5.6.21-1.rhel5.x86_64.rpm
rpm -ivh MySQL-server-5.6.21-1.rhel5.x86_64.rpm&& rpm -ivh MySQL-client-5.6.21-1.rhel5.x86_64.rpm&& rpm -ivh MySQL-devel-5.6.21-1.rhel5.x86_64.rpm
cp /usr/share/mysql/my-default.cnf /etc/my.cnf
/usr/bin/mysql_install_db
查看初始密码
more /root/.mysql_secret
用获取到的密码登录
mysql -uroot -pj3R5qTNxrKsxnQTj # 命令登录Mysql:(j3R5qTNxrKsxnQTj 即为笔者查到的初始密码)
修改密码
set password = password('123456');
登录数据库修改数据库root访问权限
use mysql
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;
开启外网防火墙
firewall-cmd --zone=public --add-port=3306/tcp --permanent
配置nginx
代理到本地的10000端口
server {
listen 80;
server_name dev.jianshu.com;
root /home/www/jianshu;
location / {
proxy_pass http://127.0.0.1:10000;
}
}
创建目录
/home/www/jianshu
配置swoft代码里swoole监听的端口
将swoft的开发代码上传到服务器目录
/home/www/jianshu
php bin/swoft start
配置本地域名或者dns解析,用 dev.jianshu.com 即可访问。