- 在服务器上安装 Git
sudo apt-get install git
配置环境
一:安装 PHP 7.1
- ppa 方式安装 PHP7.1 :
sudo apt-get install software-properties-common
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/PHP
- 更新安装包
sudo apt-get update
- 检验是否安装成功,运行命令如若成功就能开始安装PHP7.1
apt-cache search PHP7.1
- PHP7.1安装
sudo apt-get -y install PHP7.1 apt-get install PHP7.1-dev
- 运行PHP -v查看版本,出现如下结果则为成功
二:安装PHP7.1的各个模块
sudo apt-get -y install PHP7.1-MysqL sudo apt-get install PHP7.1-fpm apt-get install PHP7.1-curl PHP7.1-xml PHP7.1-mcrypt PHP7.1-json PHP7.1-gd PHP7.1-mbstring PHP7.2-mcrypt 安装 apt-get install PHP-pecl apt-get install libmcrypt-dev libreadline-dev pecl install mcrypt-1.0.1 After the successful installation You should add "extension=mcrypt.so" to PHP.ini
PS:为了与我下方Nginx配置对应,这里要将PHP-fpm监听接口打开
vim /etc/PHP/7.1/fpm/PHP-fpm.conf 或者 /etc/PHP/7.1/fpm/pool.d/ 下配置文件 pm.max_children = 5 => pm.max_children = 20 最大子进程数 listen = /run/PHP/PHP7.1-fpm.sock => listen = 127.0.0.1:9000 重启:service PHP7.1-fpm restart
三:安装 MysqL
- 安装命令
sudo apt-get install MysqL-server MysqL-client
ps:安装过程中需要输入 2 次密码确认,安装完成后MysqL -u root -p登陆测试,能正常登陆即安装完成。exit;退出 MysqL,ubuntu16 安装的MysqL版本为MysqL-5.7,如若不是需要升级执行以下操作:
cd ~ wget https://dev.MysqL.com/get/MysqL-apt-config_0.8.1-1_all.deb sudo dpkg -i MysqL-apt-config_0.8.1-1_all.deb
选择MysqL5.7按OK继续
更新包索引
sudo apt-get update
安装
MysqL-server:sudo apt-get install MysqL-server
sudo MysqL_upgrade -u root -p
重启
MysqL:server:sudo service MysqL restart
四:安装 Nginx
- 检查服务器是有存在apache2,如若存在卸载,执行以下操作
sudo service apache2 stop update-rc.d -f apache2 remove sudo apt-get remove apache2
- 卸载完毕或原不存在执行以下操作
更新包列表: sudo apt-get update 安装Nginx: sudo apt-get install Nginx 重启Nginx: service Nginx restart
五:配置 PHP
sudo vim /etc/PHP/7.1/fpm/PHP.ini
命令行模式下输入/进入查找模式
搜索fix_pathinfo将cgi.fix_pathinfo=1改为cgi.fix_pathinfo=0
六:配置 Nginx
sudo vim /etc/Nginx/sites-available/default
- 编辑修改,例如
server { listen 80; server_name mycode.test.top; root "/home/Code"; index index.html index.htm index.PHP; charset utf-8; location / { try_files $uri $uri/ /index.PHP?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } access_log off; error_log /var/log/Nginx/mycode.test.com-error.log error; sendfile off; client_max_body_size 100m; location ~ \.PHP$ { 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; } }
- 配置成功后查看是否正确
service Nginx configtest
配置好之后,运行Nginx -t如果出现报错,尝试删除其他站点的ipv6only=on
七:安装 Composer
PHP -r "copy('https://install.PHPcomposer.com/installer','composer-setup.PHP');" PHP composer-setup.PHP PHP -r "unlink('composer-setup.PHP');" sudo mv composer.phar /usr/local/bin/composer
八:配置v8js拓展
- 这里用到的是v8js-2.1.0源码包:http://pecl.php.net/get/v8js
- 解压源码包
tar zxvf v8js-2.1.0.tgz
- 进入解压后目录
cd v8js-2.1.0/
- 添加libv8-dev包的仓库
sudo add-apt-repository -y ppa:pinepain/libv8
- 更新包列表
sudo apt-get update
- 安装libv8-dev
apt-get install libv8-6.6-dev
- 执行操作
PHPize ./configure --with-v8js=/opt/libv8-6.6 make make test cp v8js.so /usr/lib/PHP/20160303/
<?PHP $v8 = new V8Js(); /* basic.js */ $JS = <<< EOT len = print('Hello' + ' ' + 'World!' + "\\n"); len; EOT; try { var_dump($v8->executeString($JS,'basic.js')); } catch (V8JsException $e) { var_dump($e); } ?>
如果出现以下错误:
configure: error: Please reinstall the v8 distribution
表示没有安装libv8*-dev的包checking for libv8_libplatform... checking for libv8_libplatform... configure: error: could not find libv8_libplatform library表示安装libv8-dev包的版本太低了