vagrant系列课程(三):vagrant搭建的php7环境
vagrant系列教程(三):vagrant搭建的php7环境
前面已经把vagrant的基础知识已经基本过了一遍 了,相信只要按着教程来,你已经搭建好了自己的基础环境。接下来说一说如何搭建php7的开发环境。
申明一下,这里使用的box,就是前面演示的centos7
地址奉上:
https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box
安装nginx
首先需要跟新一些ngin的相关源。
1 |
|
看到以下界面时,请稍等,如果需要输入的地方,请直接按 y
然后回车。
启动nginx并设置为开机启动
1 |
|
安装epel与remi源
安装epel,epel是Fedora小组维护的一个软件仓库项目,为RHEL/CentOS提供他们默认不提供的软件包。安装时一定需要注意一下自己系统的版本额。
1 |
|
remi源种包含最新的php相关信息,如:php7、mysql等,因此为了便捷获取php7的最新信息,也需要安装一下这个源。
1 |
|
iptables防火墙
因为以前经常使用iptables,对centos7自带的firewalld防火墙不熟悉,因此我就将关闭centos7自带的firewalld,启用自己熟悉的iptables吧。
首先,关闭自带的firewalld防火墙
1 |
|
安装iptables
1 |
|
安装进程如下图所示
启动iptables防火墙
1 |
|
编辑防火墙配置文件
为了我们在自己的主机上能够顺利访问,需要开启以下端口,
vim /etc/sysconfig/iptables
编辑防火墙,设置80(nginx) 3306(mysql/mariadb) 6379(redis)端口,外网可访问
PHP7.0的安装
查看remi源中可安装的php信息
1 |
|
该列表会列出所有可以安装的php模块信息,从中安装自己需要的模块,下面安装模块,是我自己的一个模块选择情况。其中有一部分是必须的,有一部分是可选的。比如php-fpm就是必须的,如果你用的是nginx的话。
1 |
|
安装完成后,输入 php -v
可以查看当前安装的php版本信息。
启动php-fpm,因为nginx需要通过它来解析php程序
1 |
|
配置nginx可以访问php
进入nginx的文件配置中心,
1 |
|
首先先通过vim编辑default文件。将监听端口改为8080, 因为后面我们自己的php.conf会用到80端口。
现在来编辑复制的php.conf文件,可以直接复制以下内容,至于配置的含义,后面再开一篇文章来单独讲解吧。
1 |
|
修改完文件后,必须要重新启动nginx,才会使当前的配置生效。
1 |
|
测试访问
在/vagrant/www下新建一个文件index.php
1 |
|
在浏览器中打开,访问对应的ip,可以看到输出的php信息
注:如果在使用过程中,有新增加的php模块,需要重新启动php-fpm
systemctl reload php-fpm
Mariadb的安装
这里很多同学可能第一次听说mariadb,他呢是mysql的一个重要分子,或者可以理解为mysql的替代品,自从mysql被控制后,更新速度已经慢太多了。两者的用法基本没有区别,实际中有哪些坑,大家可以自己去踩一踩。哈哈,别说我不负责任。
1 |
|
MariaDB的安全配置
MariaDB默认root密码为空,我们需要设置一下,执行脚本:
1 |
|
这个脚本会经过一些列的交互问答来进行MariaDB的安全设置。
首先提示输入当前的root密码:
Enter current password for root (enter for none):
初始root密码为空,我们直接敲回车进行下一步。Set root password? [Y/n]
设置root密码,默认选项为Yes,我们直接回车,提示输入密码,在这里设置您的MariaDB的root账户密码。Remove anonymous users? [Y/n]
是否移除匿名用户,默认选项为Yes,建议按默认设置,回车继续。Disallow root login remotely? [Y/n]
是否禁止root用户远程登录?如果您只在本机内访问MariaDB,建议按默认设置,回车继续。 如果您还有其他云主机需要使用root账号访问该数据库,则需要选择n。Remove test database and access to it? [Y/n]
是否删除测试用的数据库和权限? 建议按照默认设置,回车继续。Reload privilege tables now? [Y/n]
是否重新加载权限表?因为我们上面更新了root的密码,这里需要重新加载,回车。
完成后你会看到Success!的提示,MariaDB的安全设置已经完成。我们可以使用以下命令登录MariaDB:
1 |
|
按提示输入root密码,就会进入MariaDB的交互界面,说明已经安装成功。
最后我们将MariaDB设置为开机启动。
1 |
|
让外网可以进行链接
1 |
|
安装composer
composer的大名,我就不想介绍了,如果你是一个phper,没用过,我也就不怪你,毕竟但是他现在才刚过1.0版,但是如果听都没听过,请面壁去……
安装说明
1 |
|
上述 3 条命令的作用依次是:
- 下载安装脚本(composer-setup.php)到当前目录。
- 执行安装过程。
- 删除安装脚本 – composer-setup.php 。
全局安装composer
全局安装是将 Composer 安装到系统环境变量 PATH 所包含的路径下面,然后就能够在命令行窗口中直接执行 composer 命令了。
Mac 或 Linux 系统:打开命令行窗口并执行如下命令将前面下载的 composer.phar 文件移动到 /usr/local/bin/ 目录下面:
1 |
|
然后执行: composer -v
由于composer的包都在国外,这里设置一下composer的配置,让其每次运行时,都使用国内的包
1 |
|
查看composer的配置文件
vim /root/.composer/config.json
看到以上内容,表示配置成功!
至此,基本的php7环境搭建已经完成了。然后呢,下一次说一说用vagrant搭建redis吧。当然我不会仅仅只说redis的搭建额。到时候看啊吧!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

I had a tough problem when working on a project with a large number of Doctrine entities: Every time the entity is serialized and deserialized, the performance becomes very inefficient, resulting in a significant increase in system response time. I've tried multiple optimization methods, but it doesn't work well. Fortunately, by using sidus/doctrine-serializer-bundle, I successfully solved this problem, significantly improving the performance of the project.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

When developing Yii framework projects, you often encounter situations where you need to obtain a large amount of data from the database. If appropriate measures are not taken, directly obtaining all data may cause memory overflow and affect program performance. Recently, when I was dealing with a project on a large e-commerce platform, I encountered this problem. After some research and trial, I finally solved the problem through the extension library of pavle/yii-batch-result.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I'm having a tough problem when developing a complex web application: how to effectively handle JavaScript errors and log them. I tried several methods, but none of them could meet my needs until I discovered the library dvasilenko/alterego_tools. I easily solved this problem through the installation of this library through Composer and greatly improved the maintainability and stability of the project. Composer can be learned through the following address: Learning address

When developing a Laravel application, I encountered a common but difficult problem: how to improve the security of user accounts. With the increasing complexity of cyber attacks, a single password protection is no longer enough to ensure the security of users' data. I tried several methods, but the results were not satisfactory. Finally, I installed the wiebenieuwenhuis/laravel-2fa library through Composer and successfully added two-factor authentication (2FA) to my application, greatly improving security.

The Laravel framework has built-in methods to easily view its version number to meet the different needs of developers. This article will explore these methods, including using the Composer command line tool, accessing .env files, or obtaining version information through PHP code. These methods are essential for maintaining and managing versioning of Laravel applications.
