开篇
本操作是在VirtualBox里面进行的,所以开篇先说下,本地如何操作VB里面的Linux
1.secureCRT登陆虚拟机ubuntu
直接连接虚拟机的ip (ifconfig)会提示拒绝访问,是因为未安装ssh,ssh是telnet的升级,telnet的密码和信息是不加密的,而ssh是加密。
安装ssh
sudo apt-get install openssh-server openssh-client
启动ssh-server
ssh restart
查看ssh-server是否启动
netstat -tlp
显示一下表示成功启动
tcp 0 0 *:ssh *:* LISTEN 821/sshd tcp6 0 0 [::]:ssh [::]:* LISTEN 821/sshd
2.删除软件
因为之前安装过测试的php 所以先卸载掉
sudo apt autoremove php7.0
3. 获取root权限
这个是一个谨慎的操作,因为任何管理员都可以使用 sudo root 来获取root的权限,但有写入权限或-p 创建目录,启动服务等会出问题。
获取root权限:
sudo passwd
[sudo] currentUser 的密码: 输入新的 UNIX 密码: 重新输入新的 UNIX 密码: passwd:已成功更新密码
然后:
su root
下载测试安装环境
方便期间,我们使用lnmp快速安装,(先安装php5.4)
下载地址:http://soft.vpser.net/lnmp/lnmp1.3-full.tar.gz
tar xzvf lnmp1.3-full.tar.gz cd lnmp1.3-full ./install.sh
下一步……
完成!
访问ip查看lnmp环境是否安装ok
升级php至php7
下载最新版php7 (2017-03-16)
下载地址:http://cn2.php.net/distributions/php-7.0.17.tar.gz
别急!
上一步我们查看那了phpinfo,首先先复制Configure Command 等一会编译的时候要用
'./configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir' '--with-freetype-dir=/usr/local/freetype' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl' '--enable-mbregex' '--enable-mbstring' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext' '--disable-fileinfo' '--enable-intl' '--with-xsl'
先停掉php-fpm
service php-fpm stop
备份下老的php版本
cd /usr/local mv php php5.4
ok,现在可以安装php7了
tar xzvf php-7.0.17.tar.gz cd php-7.0.17
带上刚才复制的Configure Command
关于Linux configure 参数解释参考: http://blog.chinaunix.net/uid-20568163-id-1632905.html
'./configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir' '--with-freetype-dir=/usr/local/freetype' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl' '--enable-mbregex' '--enable-mbstring' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext' '--disable-fileinfo' '--enable-intl' '--with-xsl'
Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php7.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/fpm/php-fpm.conf config.status: creating sapi/fpm/www.conf config.status: creating sapi/fpm/init.d.php-fpm config.status: creating sapi/fpm/php-fpm.service config.status: creating sapi/fpm/php-fpm.8 config.status: creating sapi/fpm/status.html config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands configure: WARNING: unrecognized options: --with-mysql root@aaa-VirtualBox:/home/wwwroot/tools/php-7.0.17#
提示:configure: WARNING: unrecognized options: --with-mysql 是因为php7已经不在用--with-mysql 支持mysql模块连接了,取而代之的是--with-mysqli 、--with-pdo-mysql,去掉--with-mysql=mysqlnd 便可。
如果提示:
checking if we should use cURL for url streams... no checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
执行:
apt-get install curl apt-get install libcurl4-gnutls-dev
修改configure 参数:增加参数--with-curl=/usr/local/curl
接着make && make install
问题又来了
collect2: error: ld returned 1 exit status Makefile:294: recipe for target 'sapi/cli/php' failed make: *** [sapi/cli/php] Error 1
查看报错的内容:
In function `convert’: encodings.c:73: undefined reference to `libiconv_open’ encodings.c:81: undefined reference to `libiconv’ encodings.c:101: undefined reference to `libiconv_close’
libiconv模块错误,but libiconv是安装的,不知为何提示错误,解决办法 make时加了一个参数, 参考:http://lynnteng0.blog.51cto.com/2145094/1257910 https://fukun.org/archives/10102487.html
make ZEND_EXTRA_LIBS='-liconv'
启动php-fpm
service php-fpm start
提示: 无一下提示可忽略
Job for php-fpm.service failed because the control process exited with error code. See "systemctl status php-fpm.service" and "journalctl -xe" for details. 使用systemctl status php-fpm.service 查看详情
ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2) ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf' ERROR: FPM initialization failed php-fpm.service: Control process exited, code=exited status=1 Failed to start LSB: starts php-fpm.
修改/usr/local/php/etc/php-fpm.conf.default 为 php-fpm.conf (mv)
并将/usr/local/php/etc/php-fpm.d中 www.conf.default的文件mv为www.conf文件
然后在启动php-fpm 、从新加载nginx
service php-fpm start
service nginx reload
访问IP地址或域名
502 bad gateway
这个说明php-fpm 已经运行,但php-fpm的配置有问题 参考:http://www.111cn.net/phper/31/93675.htm
关于php-fpm的配置参数参考: http://www.jb51.net/article/37749.htm
使用LNMP配置出来的php-fpm.conf文件 (LNMP可正常启动)
[global] pid = /usr/local/php/var/run/php-fpm.pid error_log = /usr/local/php/var/log/php-fpm.log log_level = notice [www] listen = /tmp/php-cgi.sock listen.backlog = -1 listen.allowed_clients = 127.0.0.1 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = dynamic pm.max_children = 10 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 6 request_terminate_timeout = 100 request_slowlog_timeout = 0 slowlog = var/log/slow.log
现在单独安装php7.0.17 生成的conf在 /usr/local/php/etc/php-f/php-fpm.d/www.conf中 (php-fpm.conf中include进来的)
修改www.conf
listen = 127.0.0.1:9000
改为
listen = /tmp/php-cgi.sock
将
listen.owner = www
listen.group = www
listen.mode = 0666
三行最前面的 ‘;’ 去掉,重启服务。
到此,php已经从php5.4升级为php7了。
扩展安装
安装扩展,可参考:
Yii2中mongodb使用ActiveRecord的数据操作
Deepin下 使用apt get install 安装nginx和php-fpm
Deepin Linux桌面版没有办法安装php的集成环境,无论是Lanmps、Lnmp、phpstudy,安装的时候就会卸载Deepin15.1的应用,包括dde桌面
那么只能手动安装php环境
1. 安装nginx
apt-get install nginx
访问localhost
默认的web目录在/var/www/html, 默认的conf在/etc/nginx/nginx.conf, 执行文件在/usr/sbin/nginx
2.安装php7.1
apt-get install php7.1-fpm
3.配置nginx支持php
gedit /etc/nginx/site-available/default
添加php 默认页面
# Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html index.php;
支持.php 文件解析
location ~ .php$ { include snippets/fastcgi-php.conf; # # # With php-fpm (or other unix sockets): fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; # # With php-cgi (or other tcp sockets): # fastcgi_pass 127.0.0.1:9000; }
重新加载nginx
service nginx reload
设置/var/www/html/index.php 内容
<?php phpinfo(); ?>
4.对mysql的支持
安装mysql
apt-get install mysql-server mysql-client
php连接mysql
apt-get install php7.1-mysql
重启服务:
service php7.1-fpm reload
service nginx reload
支持memcached
# memcached服务端 apt-get install memcached
#memcached -d -m 256 -p 11211 -u root
php-memcahced插件
# 找不到源 apt-get install php7.1-memcached
apt 安装不了,只能编译安装
编译安装的时候必须要指定phpize才能知道挂载的扩展
启用phpize:
apt-get install php7.1-dev
安装完php7.1-dev 后phpize的目录在 /usr/bin/phpize
下载php-memcahced 扩展
wget http://pecl.php.net/get/memcached-3.0.3.tgz tar xzvf memcached-3.0.3.tgz cd memcached-3.0.3 /usr/bin/phpize
当configure 的时候提示 not find libmemcached
安装libmemcached-dev
apt-get install libmemcached # 不存在 apt-get install libmemcached-dev
./configure
make && make install
在php.ini 中添加memcahced.so