ubuntu18.04安装php-fpm7.2套件

ubuntu18.04安装php-fpm7.2套件

[b][size=x-large]准备工作[/size][/b]

首先替换镜像源
[quote]
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
[/quote]

用上面这些内容替换掉 / etc / apt / sources.list 这个文件。

依次执行
apt-get update
apt-get upgrade
apt-get install -y software-properties-common
apt-get install -y vim wget

[b][size=x-large]安装php[/size][/b]
add-apt-repository ppa:ondrej/nginx
按回车继续

add-apt-repository ppa:ondrej/php
按回车继续

apt-get install -y php7.2

途中选时区,选 6,再选69

装好了。
再安装各种php模块。
apt-get install -y php7.2-bcmath php7.2-bz2 php7.2-dba php7.2-enchant php7.2-fpm php7.2-imap php7.2-interbase php7.2-intl php7.2-mbstring php7.2-phpdbg php7.2-soap php7.2-sybase php7.2-xsl php7.2-zip php7.2-xmlrpc php7.2-xml php7.2-tidy php7.2-sqlite3 php7.2-snmp php7.2-recode php7.2-readline php7.2-pspell php7.2-pgsql php7.2-opcache php7.2-odbc php7.2-mysql

apt-get install -y php7.2-ldap php7.2-json php7.2-gmp php7.2-gd php7.2-dev php7.2-curl php7.2-common php7.2-cli php7.2-cgi

如何验证php安装成功。
php7.2 -v
php-fpm7.2 -v

看到都有信息,表示php和php-fpm都安装好了。

如果想看php和php-fpm的模块,则
php7.2 -m
php-fpm7.2 -m

发现都很好,将近70个,差swoole

pecl install swoole
这里要选择选项,直接按回车是对那一项取消,如果全选,可能安装失败。因为选的越多,对其他类库要求越多。
我假设这里全部回车,不安装swoole的附加选项,则创建so文件成功。

find / -name swoole.so
一般是
/usr/lib/php/20170718/swoole.so



echo "extension=swoole.so" >> /etc/php/7.2/cli/php.ini

php7.2 -m|grep swoole
如果swoole能看到,则说明安装成功。

vim /etc/php/7.2/fpm/pool.d/www.conf
注意,确保下面这个sock文件和nginx那个配置一样。
listen = /run/php/php7.2-fpm.sock

启动php-fpm
service php7.2-fpm start

===========================================================================

[b][size=x-large]安装nginx[/size][/b]
apt-get install nginx
这里发现会自动安装最新的nginx 1.14

vim /etc/nginx/sites-enabled/default
修改这个文件
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
然后启动
service nginx start

实测效果很棒。

vi /var/www/html/1.php
phpinfo();

然后,wget http://127.0.0.1/1.php

然后,cat 1.php
可以看到很好。

==============================================================

[b][size=x-large]安装mysql[/size][/b]
apt-get install mysql-server mysql-client
service mysql start


这个命令是配置msql 服务的。
mysql_secure_installation

cat /etc/mysql/debian.cnf
找到类似下面的语句

user = debian-sys-maint
password = sKuCU0ruhYVVIs99

然后写php
vi /var/www/html/2.php

header("Content-type: text/html; charset=utf-8");

$sql='select version(),FROM_UNIXTIME(UNIX_TIMESTAMP() )';
$db = Sys::getdb();
$dbresult = $db->query($sql)->fetch_all(MYSQLI_ASSOC);
var_dump($dbresult);

class Sys
{
private $mysqli;
public static function getredis()
{
static $redis = null;
if ($redis == null) {
$redis = new \Redis();
$redis->connect('build_redis-db_1','6379');

}
return $redis;
}

public static function getdb()
{
$mysqli = new mysqli('localhost', 'debian-sys-maint', 'sKuCU0ruhYVVIs99' );
$sql="set names utf8";
$mysqli->query($sql);
return $mysqli;
}
}

用户名和密码用上面的debian.cnf文件里的。


wget http://127.0.0.1/2.php
效果如下
[quote]
array(1) {
[0]=>
array(2) {
["version()"]=>
string(23) "5.7.23-0ubuntu0.18.04.1"
["FROM_UNIXTIME(UNIX_TIMESTAMP() )"]=>
string(19) "2018-08-31 17:51:54"
}
}
[/quote]

php真棒!

你可能感兴趣的:(PHP)