当前位置: 首页 > 后端技术 > PHP

Ubuntu16安装配置LNMP(7.1)环境并安装v8js扩展

时间:2023-03-29 18:03:45 PHP

在服务器上安装Gitsudoapt-getinstallgit配置环境一:安装PHP7.1ppa安装php7.1:sudoapt-getinstallsoftware-properties-common添加php7ppasudoLC_ALL=en_US.UTF-8add-apt-repositoryppa:ondrej/php更新安装包sudoapt-getupdate查看是否安装成功,运行命令开始安装php7.1apt-cachesearchphp7.1php7.1installsudoapt-get-yinstallphp7.1apt-getinstallphp7.1-dev运行php-v查看版本,如果出现如下结果,则表示成功2:安装php7.1的各个模块sudoapt-get-yinstallphp7.1-mysqlsudoapt-getinstallphp7。1-fpmapt-获取安装php7.1-curlphp7.1-xmlphp7.1-mcryptphp7.1-jsonphp7.1-gdphp7.1-mbstringphp7.2-mcrypt安装apt-get安装php-peclapt-getinstalllibmcrypt-devlibreadline-devpeclinstallmcrypt-1.0.1安装成功后在php.ini中添加"extension=mcrypt.so"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重启:服务php7.1-fpmrestart3:安装mysql安装命令sudoapt-getinstallmysql-servermysql-clientps:安装过程中需要输入两次密码进行确认。安装完成后执行mysql-uroot-p登录测试。安装完成。出口;退出mysql,ubuntu16上安装的mysql版本为mysql-5.7,如果不需要升级,执行如下操作:cd~wgethttps://dev.mysql.com/get/mysql-apt-config_0.8.1-1_all.debsudodpkg-imysql-apt-config_0.8.1-1_all.deb选择mysql5.7按确定继续更新包索引sudoapt-getupdate安装MySQL-server:sudoapt-getinstallmysql-server升级数据库sudomysql_upgrade-uroot-p重启mysql:server:sudoservicemysqlrestart登录mysql查看是否升级完成4:安装Nginx查看服务器上是否存在apache2,如果有卸载则执行以下操作sudoserviceapache2stopupdate-rc.d-fapache2removesudoapt-getremoveapache2已卸载或不存在,执行以下操作更新包列表:sudoapt-getupdateinstallNginx:sudoapt-getinstallnginxrestartNginx:servicenginxrestarttest输入服务器地址可以访问内置welcome第5页:配置PHPsudovim/etc/php/7.1/fpm/php.ini在命令行模式下,进入/进入搜索模式搜索fix_pathinfo将cgi.fix_pathinfo=1改为cgi.fix_pathinfo=0六:配置nginx打开nginx配置文件sudovim/etc/nginx/sites-available/default编辑修改,例如server{listen80;服务器名称emycode.test.top;根“/家/代码”;indexindex.htmlindex.htmindex.php;字符集utf-8;location/{try_files$uri$uri//index.php?$query_string;}location=/favicon.ico{access_logoff;log_not_found关闭;}location=/robots.txt{access_logoff;log_not_found关闭;}access_log关闭;error_log/var/log/nginx/mycode.test.com-error.log错误;发送文件关闭;client_max_body_size100m;位置~\.php${fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;包括fastcgi_params;检查服务nginxconfigtest是否配置正确,如果出错运行nginx-t,尝试删除其他站点的ipv6only=on七:InstallComposerphp-r"copy('https://install.phpcomposer.com/installer','composer-setup.php');"phpcomposer-setup.phpphp-r"unlink('composer-setup.php');"sudomvcomposer.phar/usr/local/bin/composer八:配置v8js扩展这里使用v8js-2.1.0源码包:http://pecl.php.net/get/v8js解压源码包tarzxvfv8js-2.1.0.tgz进入解压目录cdv8js-2.1.0/添加libv8-dev包仓库sudoadd-apt-repository-yppa:pinepain/libv8更新包列表sudoapt-getupdateinstalllibv8-devapt-getinstalllibv8-6.6-devexecuteoperationphpize./configure--用-v8js=/opt/libv8-6.6makemaketestcpv8js.so/usr/lib/php/20160303/configurephp.ini填写:extension=v8js.so重启fpm和nginx并创建测试文件executeString($JS,'basic.js'));}catch(V8JsException$e){var_dump($e);}?>成功访问文件或访问phpinfo如果v8js存在,安装安装成功如果出现以下错误:configure:error:Pleasereinstallthev8distribution表示检查libv8_libplatfo的libv8*-dev包没有安装rm...checkingforlibv8_libplatform...configure:error:couldnotfindlibv8_libplatformlibrary表示安装的libv8-dev包版本太低