1. 程式人生 > 實用技巧 >vagrant centos7 安裝PHP 5.6筆記

vagrant centos7 安裝PHP 5.6筆記

[vagrant@localhost ~]$ sudo yum install -y wget vim

[vagrant@localhost ~]$ sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
#安裝第三方源epel-release
[vagrant@localhost ~]$ sudo yum install epel-release
[vagrant@localhost ~]$ sudo vi /etc/yum.repos.d/remi.repo

[remi] 節點下的 enabled的值由0 改為 1

列出 /etc/yum.repos.d資料夾下的檔案列表

[vagrant@localhost yum.repos.d]$ ls
CentOS-Base.repo       CentOS-Sources.repo        mysql-community.repo         remi-glpi94.repo   remi-php72.repo  remi-safe.repo
CentOS-CR.repo         CentOS-Vault.repo          mysql-community-source.repo  remi-modular.repo  remi-php73.repo
CentOS-Debuginfo.repo  CentOS-x86_64-kernel.repo  remi-glpi91.repo             remi-php54.repo    remi-php74.repo
CentOS-fasttrack.repo  epel.repo                  remi-glpi92.repo             remi-php70.repo    remi-php80.repo
CentOS-Media.repo      epel-testing.repo          remi-glpi93.repo             remi-php71.repo    remi.repo

沒有需要安裝的php 5.6

yum list --enablerepo=remi --enablerepo=remi-php56 | grep php
sudo yum install --enablerepo=remi --enablerepo=remi-php56 php
sudo yum install --enablerepo=remi --enablerepo=remi-php56 php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-pecl-xdebug php-pecl-xhprof

sudo yum install --enablerepo=remi --enablerepo=remi-php56 php-cli php-curl php-json php-pdo php-mysql php-gd php-bcmath php-xml php-mbstring php-mcrypt php-redis php-crypto

配置Apache 配置檔案

sudo vi /etc/httpd/conf/httpd.conf

將配置檔案中<Directory "/var/www/html">內的 AllowOverride None改為 AllowOverride All

apachectl configtest # 測試配置檔案格式是否正確

vagrant centos 啟動之後:

==> default: Mounting shared folders...
    default: /var/www/html => D:/workspace/centoslamp
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=1000,gid=1000 var_www_html /var/www/html

The error output from the command was:

mount: unknown filesystem type 'vboxsf'

我參考別人部落格的處理方法是:

#安裝 vagrant-vbguest 外掛
vagrant plugin install vagrant-vbguest --plugin-clean-sources --plugin-source https://gems.ruby-china.com/

Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Fetching micromachine-3.0.0.gem
Fetching vagrant-vbguest-0.24.0.gem
Installed the plugin 'vagrant-vbguest (0.24.0)'!

安裝成功之後,重啟 vagrant 虛擬機器 vagrant reload

如果問題依舊,可嘗試再次安裝 vagrant-vbguest 外掛,再次重啟 vagrant 虛擬機器

當出現型別下面的內容,好像是在自動開始安裝 Virtualbox Guest Additions 元件了

[default] No Virtualbox Guest Additions installation found.
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
....
VirtualBox Guest Additions: Building the modules for kernel
3.10.0-1127.19.1.el7.x86_64.
Redirecting to /bin/systemctl start vboxadd.service
Redirecting to /bin/systemctl start vboxadd-service.service
Unmounting Virtualbox Guest Additions ISO from: /mnt
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /cygdrive/d/workspace/vagrant/centos/ => /vagrant
==> default: Mounting shared folders...
    default: /var/www/html => D:/workspace/centoslamp
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

-- 複製表結構及資料到新表
CREATE TABLE 新表 SELECT * FROM 舊錶
-- 只複製表結構到新表 即:讓WHERE條件不成立.
CREATE TABLE 新表 SELECT * FROM 舊錶 WHERE 1=2

Centos vhost,在 /etc/httpd/conf.d 新增Domain Name.conf 如: test1.local.conf

<VirtualHost *:80>
    ServerName test1.local
    ServerAlias test1.local
    DocumentRoot /var/www/html/test1

    <Directory /var/www/html/test1>
        Options  FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
                Order allow,deny
                allow from all
    </Directory>

    ErrorLog /var/log/httpd/test1.local-error.log
    CustomLog /var/log/httpd/test1.local-access.log combined
#RewriteEngine on
#RewriteCond %{SERVER_NAME} =test1.local
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

訪問vhost 403:

嘗試1:

修改同步資料夾的 使用者組和使用者

config.vm.synced_folder "D:/workspace/centoslamp", "/var/www/html", create: true, owner: "vagrant", group: "apache"

嘗試2:

setenforce 0

修改配置檔案 /etc/selinux/config,將 SELINUX=enforcing 改為 SELINUX=disabled

最終可以訪問到了

References