召唤神龙 - 安装 centos 8, php 8, mysql 8, laravel 8 的整套 php 运行环境
程序员文章站
2022-05-31 09:12:32
...
本文编写时间:2020-11-27
传说集齐龙珠可以召唤神龙
而使用 php 的常用开发框架 laravel 这一技术栈,大版本惊人的实现了统一,均为 8。centos 8, php 8, mysql 8, laravel 8。
(假装不知道 ubuntu )
用 linux 的好处是开发环境和部署环境高度统一,而 win 10 和 docker 的普及使得所有的 php 程序员可以轻易在 windows 电脑和 mac 电脑进行 linux 环境下的开发,同时阿里巴巴开源镜像站的存在使得安装本文全部软件所需时间仅需 2 分钟左右,已经方便的没法形容了。也是写这个系列文章的初衷。
以下列出这 4 类软件的大版本为 8 时的发行时间。
首先,安装阿里的 centos 仓库。(centos 8)
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
rm -f /etc/yum.repos.d/CentOS-centosplus.repo
rm -f /etc/yum.repos.d/CentOS-PowerTools.repo
rm -f /etc/yum.repos.d/CentOS-Extras.repo
rm -f /etc/yum.repos.d/CentOS-AppStream.repo
dnf makecache
dnf repolist
安装阿里的 epel 仓库。(centos 8)
dnf install -y epel-release
sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
dnf makecache
dnf repolist
安装阿里的 remi 的仓库(centos 8)
dnf install -y https://mirrors.aliyun.com/remi/enterprise/remi-release-8.rpm
sed -i 's/https*:\/\/rpms.remirepo.net/https:\/\/mirrors.aliyun.com\/remi/g' /etc/yum.repos.d/remi*
sed -i 's/#baseurl/baseurl/g' /etc/yum.repos.d/remi*
sed -i 's|^mirrorlist|#mirrorlist|' /etc/yum.repos.d/remi*
dnf makecache
dnf repolist
安装 php 8(centos 8)
dnf install -y yum-utils
dnf install -y php80 php80-php-devel php80-php-fpm php80-php-mbstring php80-php-memcached php80-php-redis php80-php-mysqlnd php80-php-pdo php80-php-bcmath php80-php-xml php80-php-gd php80-php-gmp php80-php-igbinary php80-php-imagick php80-php-pdo_mysql php80-php-posix php80-php-simplexml php80-php-opcache php80-php-xsl php80-php-xmlwriter php80-php-xmlreader php80-php-swoole php80-php-zip php80-php-yaml php80-php-uuid
安装阿里的 composer 镜像源(centos 8)
ln -s /usr/bin/php80 /usr/bin/php
curl -o /usr/local/bin/composer https://mirrors.aliyun.com/composer/composer.phar
chmod +x /usr/local/bin/composer
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
安装 nginx 并整合 php-fpm 服务(centos 8)
echo $'[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true ' > /etc/yum.repos.d/nginx.repo
dnf makecache
dnf install -y nginx
systemctl enable nginx
systemctl enable php80-php-fpm
sed -i 's/user\ =\ apache/user\ =\ nginx/g' /etc/opt/remi/php80/php-fpm.d/www.conf
sed -i 's/group\ =\ apache/group\ =\ nginx/g' /etc/opt/remi/php80/php-fpm.d/www.conf
sed -i 's/listen\ =\ \/var\/opt\/remi\/php80\/run\/php-fpm\/www.sock/listen=9000/g' /etc/opt/remi/php80/php-fpm.d/www.conf
rm -f /etc/nginx/conf.d/default.conf
vi /etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/default.conf 文件内容如下:
server {
listen 80;
server_name localhost;
charset utf-8 ;
access_log /var/log/nginx/host.access.log main;
root /www/blog/public;
index index.php index.html index.htm;
error_page 404 500 502 503 504 /50x.html;
location = /50x.html {
root /www/blog/public;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
安装 mysql 8(centos 8)
实际也用了阿里的镜像,因为是从 AppStream 库下载的,速度极快。
dnf install -y @mysql
systemctl enable mysqld
systemctl start mysqld
mysql -uroot
mysql -uroot,这个命令是登录 mysql 服务用的。
进入后执行下面这个命令,创建一个空的数据库名叫 laravel,然后用 quit 退出。
create database laravel default charset utf8mb4;
安装 redis,git 以及其他常用库(centos 8)
dnf install -y git wget vim redis zip unzip p7zip rsync crontabs supervisor net-tools python3
systemctl enable redis
systemctl start redis
安装 laravel 8(centos 8)
实际也用了阿里的镜像,因为 composer 镜像源已设置过。
假设项目名称叫 blog,安装在 /www 目录下
mkdir -p /www
cd /www
composer create-project --prefer-dist laravel/laravel blog "8.*"
rm -f ./blog/routes/web.php
vi ./blog/routes/web.php
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
ob_start();
phpinfo(INFO_GENERAL);
$s = ob_get_contents();
ob_clean();
$system = preg_replace( '#^.+?Build.System.</td><td class="v">([^<]+?)\<.+$#s','$1',$s );
echo "operating system: ".$system."<br>\n";
echo "php: ".phpversion()."<br>\n";
echo "laravel: " . app()::VERSION."<br>\n";
$dbversion = \DB::select("select version() v");
echo "mysql: " . $dbversion[0]->v."<br>\n";
});
启动 php-fpm 和 nginx 并验证安装正确
systemctl start nginx
systemctl start php80-php-fpm
curl localhost/
就能看到类似下面的输出:
operating system : Red Hat Enterprise Linux release 8.2 (Ootpa) <br>
php : 8.0.0<br>
laravel: 8.16.1<br>
mysql: 8.0.21<br>
总结(centos 8)
感谢 php 开发组的努力,使得 php 在现代编程语言中保持了竞争力。
感谢阿里的开源镜像库
传说集齐龙珠可以召唤神龙
而使用 php 的常用开发框架 laravel 这一技术栈,大版本惊人的实现了统一,均为 8。centos 8, php 8, mysql 8, laravel 8。
(假装不知道 ubuntu )
用 linux 的好处是开发环境和部署环境高度统一,而 win 10 和 docker 的普及使得所有的 php 程序员可以轻易在 windows 电脑和 mac 电脑进行 linux 环境下的开发,同时阿里巴巴开源镜像站的存在使得安装本文全部软件所需时间仅需 2 分钟左右,已经方便的没法形容了。也是写这个系列文章的初衷。
以下列出这 4 类软件的大版本为 8 时的发行时间。
软件 | 发行时间 | 本文当前安装版本 |
centos 8 | 2019-09-24 | 8.2 |
php 8 | 2020-11-26 | 8.0.0 |
mysql 8 | 2016-09-12 | 8.0.21 |
laravel 8 | 2020-09-08 | 8.16.1 |
首先,安装阿里的 centos 仓库。(centos 8)
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
rm -f /etc/yum.repos.d/CentOS-centosplus.repo
rm -f /etc/yum.repos.d/CentOS-PowerTools.repo
rm -f /etc/yum.repos.d/CentOS-Extras.repo
rm -f /etc/yum.repos.d/CentOS-AppStream.repo
dnf makecache
dnf repolist
安装阿里的 epel 仓库。(centos 8)
dnf install -y epel-release
sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
dnf makecache
dnf repolist
安装阿里的 remi 的仓库(centos 8)
dnf install -y https://mirrors.aliyun.com/remi/enterprise/remi-release-8.rpm
sed -i 's/https*:\/\/rpms.remirepo.net/https:\/\/mirrors.aliyun.com\/remi/g' /etc/yum.repos.d/remi*
sed -i 's/#baseurl/baseurl/g' /etc/yum.repos.d/remi*
sed -i 's|^mirrorlist|#mirrorlist|' /etc/yum.repos.d/remi*
dnf makecache
dnf repolist
安装 php 8(centos 8)
dnf install -y yum-utils
dnf install -y php80 php80-php-devel php80-php-fpm php80-php-mbstring php80-php-memcached php80-php-redis php80-php-mysqlnd php80-php-pdo php80-php-bcmath php80-php-xml php80-php-gd php80-php-gmp php80-php-igbinary php80-php-imagick php80-php-pdo_mysql php80-php-posix php80-php-simplexml php80-php-opcache php80-php-xsl php80-php-xmlwriter php80-php-xmlreader php80-php-swoole php80-php-zip php80-php-yaml php80-php-uuid
安装阿里的 composer 镜像源(centos 8)
ln -s /usr/bin/php80 /usr/bin/php
curl -o /usr/local/bin/composer https://mirrors.aliyun.com/composer/composer.phar
chmod +x /usr/local/bin/composer
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
安装 nginx 并整合 php-fpm 服务(centos 8)
echo $'[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true ' > /etc/yum.repos.d/nginx.repo
dnf makecache
dnf install -y nginx
systemctl enable nginx
systemctl enable php80-php-fpm
sed -i 's/user\ =\ apache/user\ =\ nginx/g' /etc/opt/remi/php80/php-fpm.d/www.conf
sed -i 's/group\ =\ apache/group\ =\ nginx/g' /etc/opt/remi/php80/php-fpm.d/www.conf
sed -i 's/listen\ =\ \/var\/opt\/remi\/php80\/run\/php-fpm\/www.sock/listen=9000/g' /etc/opt/remi/php80/php-fpm.d/www.conf
rm -f /etc/nginx/conf.d/default.conf
vi /etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/default.conf 文件内容如下:
server {
listen 80;
server_name localhost;
charset utf-8 ;
access_log /var/log/nginx/host.access.log main;
root /www/blog/public;
index index.php index.html index.htm;
error_page 404 500 502 503 504 /50x.html;
location = /50x.html {
root /www/blog/public;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
安装 mysql 8(centos 8)
实际也用了阿里的镜像,因为是从 AppStream 库下载的,速度极快。
dnf install -y @mysql
systemctl enable mysqld
systemctl start mysqld
mysql -uroot
mysql -uroot,这个命令是登录 mysql 服务用的。
进入后执行下面这个命令,创建一个空的数据库名叫 laravel,然后用 quit 退出。
create database laravel default charset utf8mb4;
安装 redis,git 以及其他常用库(centos 8)
dnf install -y git wget vim redis zip unzip p7zip rsync crontabs supervisor net-tools python3
systemctl enable redis
systemctl start redis
安装 laravel 8(centos 8)
实际也用了阿里的镜像,因为 composer 镜像源已设置过。
假设项目名称叫 blog,安装在 /www 目录下
mkdir -p /www
cd /www
composer create-project --prefer-dist laravel/laravel blog "8.*"
rm -f ./blog/routes/web.php
vi ./blog/routes/web.php
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
ob_start();
phpinfo(INFO_GENERAL);
$s = ob_get_contents();
ob_clean();
$system = preg_replace( '#^.+?Build.System.</td><td class="v">([^<]+?)\<.+$#s','$1',$s );
echo "operating system: ".$system."<br>\n";
echo "php: ".phpversion()."<br>\n";
echo "laravel: " . app()::VERSION."<br>\n";
$dbversion = \DB::select("select version() v");
echo "mysql: " . $dbversion[0]->v."<br>\n";
});
启动 php-fpm 和 nginx 并验证安装正确
systemctl start nginx
systemctl start php80-php-fpm
curl localhost/
就能看到类似下面的输出:
operating system : Red Hat Enterprise Linux release 8.2 (Ootpa) <br>
php : 8.0.0<br>
laravel: 8.16.1<br>
mysql: 8.0.21<br>
总结(centos 8)
感谢 php 开发组的努力,使得 php 在现代编程语言中保持了竞争力。
感谢阿里的开源镜像库
上一篇: centos安装denyhost
下一篇: centos安装denyhost