广告:宝塔Linux面板高效运维的服务器管理软件 点击【 https://www.bt.cn/p/uNLv1L 】立即购买
安装与配置PHP8.0的正式版早已发布,本文就介绍下它的安装,并使用laravel对比下PHP7【推荐:PHP视频教程】
本次使用的操作系统Ubuntu 18.04.4 LTS
安装
1.准备必要库
apt-get install -y autoconf libxml2-dev libsqlite3-dev \libcurl4-openssl-dev libssl-dev libonig-dev libtidy-dev zlib1g-dev登录后复制
2.去官网下载8.0正式版 https://www.php.net/releases/8.0/en.php
3.解压安装
tar php-8.0.0.tar.gzcd php-8.0.0./configure --prefix=/opt/php8 --with-config-file-path=/opt/php8/etc \--enable-fpm --enable-mysqlnd --enable-opcache --enable-pcntl \--enable-mbstring --enable-soap --enable-zip --enable-calendar \--enable-bcmath --enable-exif --enable-ftp --enable-intl --with-mysqli \--with-pdo-mysql --with-openssl --with-curl --with-gd --with-gettext \--with-mhash --with-openssl --with-mcrypt --with-tidy --enable-wddx \--with-xmlrpc --with-zlibmakemake installcp php.ini-production /opt/php/etc/php.inicd /opt/php8/etccp php-fpm.conf.default php-fpm.confcp ./php-fpm.d/www.conf.default ./php-fpm.d/www.conf登录后复制
4.做个软连接
ln -s /opt/php8/bin/php /usr/bin/php8登录后复制
5.安装composer
cd /opt/php8/bin/curl -sS https://getcomposer.org/installer | php8ln -s /opt/php8/bin/composer.phar /usr/bin/composer8composer8 config -g repo.packagist composer https://mirrors.aliyun.com/composer/登录后复制
6.添加一个php8.0的system service
vim /lib/systemd/system/php8.0-fpm.service登录后复制
内容如下
[Unit]Description=The PHP 8.0 FastCGI Process ManagerDocumentation=man:php-fpm8.0(8)After=network.target[Service]Type=simplePIDFile=/var/run/php8.0-fpm.pidExecStart=/opt/php8/sbin/php-fpm --nodaemonize --fpm-config /opt/php8/etc/php-fpm.confExecReload=/bin/kill -USR2 $MAINPID[Install]WantedBy=multi-user.target登录后复制
配置
fpm-fpm,php.ini配置
和PHP7一样,注意下用户权限
opcache配置
PHP8多了一个jit配置,如下
[opcache]zend_extension=opcache.soopcache.enable=1 opcache.jit_buffer_size=100Mopcache.jit=1255登录后复制
启动
systemctl start php8.0-fpm登录后复制laravel
创建一个laravel项目【推荐:laravel视频教程】
cd /opt/webcomposer8 create-project --prefer-dist laravel/laravel php8登录后复制
配置一下.env文件
nginx配置
nginx的配置和PHP7的一致
server { listen 94; access_log /tmp/test94.log main; root /opt/web/php8/public; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php { fastcgi_pass unix:/run/php/php8.0-fpm.sock; fastcgi_index /index.php; include fastcgi_params; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }}登录后复制
添加一个接口
laravel7的路由写法在laravel8中有点问题,改下RouteServiceProvider.php
的写法。 比如API路由,将$this->namespace
改为App\Http\Controllers\Api
。
tar php-8.0.0.tar.gzcd php-8.0.0./configure --prefix=/opt/php8 --with-config-file-path=/opt/php8/etc \--enable-fpm --enable-mysqlnd --enable-opcache --enable-pcntl \--enable-mbstring --enable-soap --enable-zip --enable-calendar \--enable-bcmath --enable-exif --enable-ftp --enable-intl --with-mysqli \--with-pdo-mysql --with-openssl --with-curl --with-gd --with-gettext \--with-mhash --with-openssl --with-mcrypt --with-tidy --enable-wddx \--with-xmlrpc --with-zlibmakemake installcp php.ini-production /opt/php/etc/php.inicd /opt/php8/etccp php-fpm.conf.default php-fpm.confcp ./php-fpm.d/www.conf.default ./php-fpm.d/www.conf0登录后复制
其他一样,不用修改。
加个测试接口看看:
tar php-8.0.0.tar.gzcd php-8.0.0./configure --prefix=/opt/php8 --with-config-file-path=/opt/php8/etc \--enable-fpm --enable-mysqlnd --enable-opcache --enable-pcntl \--enable-mbstring --enable-soap --enable-zip --enable-calendar \--enable-bcmath --enable-exif --enable-ftp --enable-intl --with-mysqli \--with-pdo-mysql --with-openssl --with-curl --with-gd --with-gettext \--with-mhash --with-openssl --with-mcrypt --with-tidy --enable-wddx \--with-xmlrpc --with-zlibmakemake installcp php.ini-production /opt/php/etc/php.inicd /opt/php8/etccp php-fpm.conf.default php-fpm.confcp ./php-fpm.d/www.conf.default ./php-fpm.d/www.conf1登录后复制
test
接口查一条数据并返回
tar php-8.0.0.tar.gzcd php-8.0.0./configure --prefix=/opt/php8 --with-config-file-path=/opt/php8/etc \--enable-fpm --enable-mysqlnd --enable-opcache --enable-pcntl \--enable-mbstring --enable-soap --enable-zip --enable-calendar \--enable-bcmath --enable-exif --enable-ftp --enable-intl --with-mysqli \--with-pdo-mysql --with-openssl --with-curl --with-gd --with-gettext \--with-mhash --with-openssl --with-mcrypt --with-tidy --enable-wddx \--with-xmlrpc --with-zlibmakemake installcp php.ini-production /opt/php/etc/php.inicd /opt/php8/etccp php-fpm.conf.default php-fpm.confcp ./php-fpm.d/www.conf.default ./php-fpm.d/www.conf2登录后复制对比测试PHP7
本次使用PHP7.3,接口代码和PHP8一致,两者都开启opcache。
服务器配置是1核2G,用ab简单测试下。
tar php-8.0.0.tar.gzcd php-8.0.0./configure --prefix=/opt/php8 --with-config-file-path=/opt/php8/etc \--enable-fpm --enable-mysqlnd --enable-opcache --enable-pcntl \--enable-mbstring --enable-soap --enable-zip --enable-calendar \--enable-bcmath --enable-exif --enable-ftp --enable-intl --with-mysqli \--with-pdo-mysql --with-openssl --with-curl --with-gd --with-gettext \--with-mhash --with-openssl --with-mcrypt --with-tidy --enable-wddx \--with-xmlrpc --with-zlibmakemake installcp php.ini-production /opt/php/etc/php.inicd /opt/php8/etccp php-fpm.conf.default php-fpm.confcp ./php-fpm.d/www.conf.default ./php-fpm.d/www.conf3登录后复制
PHP7.3的测试结果如下:
tar php-8.0.0.tar.gzcd php-8.0.0./configure --prefix=/opt/php8 --with-config-file-path=/opt/php8/etc \--enable-fpm --enable-mysqlnd --enable-opcache --enable-pcntl \--enable-mbstring --enable-soap --enable-zip --enable-calendar \--enable-bcmath --enable-exif --enable-ftp --enable-intl --with-mysqli \--with-pdo-mysql --with-openssl --with-curl --with-gd --with-gettext \--with-mhash --with-openssl --with-mcrypt --with-tidy --enable-wddx \--with-xmlrpc --with-zlibmakemake installcp php.ini-production /opt/php/etc/php.inicd /opt/php8/etccp php-fpm.conf.default php-fpm.confcp ./php-fpm.d/www.conf.default ./php-fpm.d/www.conf4登录后复制
PHP8.0的测试结果如下:
tar php-8.0.0.tar.gzcd php-8.0.0./configure --prefix=/opt/php8 --with-config-file-path=/opt/php8/etc \--enable-fpm --enable-mysqlnd --enable-opcache --enable-pcntl \--enable-mbstring --enable-soap --enable-zip --enable-calendar \--enable-bcmath --enable-exif --enable-ftp --enable-intl --with-mysqli \--with-pdo-mysql --with-openssl --with-curl --with-gd --with-gettext \--with-mhash --with-openssl --with-mcrypt --with-tidy --enable-wddx \--with-xmlrpc --with-zlibmakemake installcp php.ini-production /opt/php/etc/php.inicd /opt/php8/etccp php-fpm.conf.default php-fpm.confcp ./php-fpm.d/www.conf.default ./php-fpm.d/www.conf5登录后复制
以上就是PHP8.0的编译安装与使用(详解)的详细内容,更多请关注9543建站博客其它相关文章!
发表评论