Vagrant Series Tutorial (iii): Vagrant built PHP7 Environment

Source: Internet
Author: User

The basic knowledge of vagrant has already been basically over once, I believe as long as the tutorial, you have set up your own basic environment. Let's talk about how to build a PHP7 development environment.

To be clear, the box used here is the centos7 of the previous demo.
Address:
Https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box

Installing Nginx

You need to start with some new ngin related sources.

$ rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

When you see the following screen, please wait a moment, if you need to enter the place, please press y and then enter.

Start Nginx and set to boot
$ $ systemctl enable nginx
Installing Epel and Remi sources

Installing Epel,epel is a software warehouse project maintained by the Fedora team, providing Rhel/centos with packages they do not provide by default. You must pay attention to the version amount of your system when installing.

$ http://mirrors.opencas.cn/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

Remi Source contains the latest PHP related information, such as: PHP7, MySQL, etc., so in order to easily get the latest information PHP7, also need to install this source.

$ http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
iptables Firewall

Because I used to often use iptables, Centos7 FIREWALLD Firewall is not familiar with, so I will close CENTOS7 bring FIREWALLD, enable their familiar iptables bar.

First, close the FIREWALLD firewall that comes with it.

$ $ #防止开机启动
Installing Iptables
$ yum install iptables-services

The installation process is as shown

Start Iptables Firewall

systemctl start iptables.service systemctl enable iptables.service#开机自动启动
Edit the firewall configuration file

In order for us to successfully access on our own host, we need to open the following ports,
Vim/etc/sysconfig/iptables
Edit firewall, set up (Nginx) 3306 (mysql/mariadb) 6379 (Redis) port, access to extranet

Installation of PHP7.0

View PHP information that can be installed in the Remi Source

$yumlist--enablerepo=remi--enablerepo=remi-php70|grepphp70

This list will list all the PHP module information that can be installed, install the module that you need, install the module below, is my own module choice situation. Some of them are necessary and some are optional. For example, PHP-FPM is a must, if you use Nginx.

$ yum Install–enablerepo=Remi–enablerepo=Remi-php70PHP php-opcachePhp-pecl-APCUPhp-develPhp-mbstringPhp-mcryptPhp-mysqlndPhp-pecl-xdebugPhp-pdoPhp-pearPhp-FPMPhp-cliPhp-xmlPhp-bcmathPhp-processPhp-GDPhp-commonPhp-jsonPhp-imapPhp-pecl-redisPhp-pecl-memcachedPhp-pecl-mongodb

After the installation is complete, enter php -v to view the currently installed PHP version information.

Start php-fpm because Nginx needs to parse the PHP program through it.

$ systemctl start php-fpm$ #设置开机自启动
Configure Nginx to access PHP

Enter Nginx's file configuration center,

$ cd /etc/nginx/conf.d/# 复制默认的配置文件 cp default.conf php.conf

First, the default file is edited with Vim. Change the listening port to 8080, because our own php.conf will use 80 ports later.

Now to edit the copied php.conf file, you can directly copy the following, as to the meaning of the configuration, and then open an article to explain it separately.

Server{Listen the;    server_name localhost; CharSet utf-8; root/vagrant/www;# Own project directory, which is the directory where the PHP project residesLocation/{# Please note, be sure to add index.php this        Index  Index. phpIndex. htmlIndex. htm; } error_page - 502 503 504/ -x.html; Location =/ -x.html {root/usr/share/nginx/html; } location ~ \.php$ {Fastcgi_pass127.0. 0. 1:9000; Fastcgi_indexIndex. php;# Note The differences in the variables hereFastcgi_param script_filename $document _root$fastcgi_script_name;    Include Fastcgi_params; }}

After modifying the file, you must restart Nginx before the current configuration takes effect.

$ systemctl reload nginx
Test access

Create a new file under/vagrant/www index.php

<?php    phpinfo();

Open in the browser, access to the corresponding IP, you can see the output of PHP information

Note: If you have a new PHP module in use, you need to restart PHP-FPM

systemctl reload php-fpm

Installation of MARIADB

Many students here may have heard of mariadb for the first time, he is an important member of MySQL, or can be understood as a substitute for MySQL, since MySQL was controlled, the update speed is too much. The use of the two basically no difference, the actual pit, we can step on their own. Haha, don't say I'm irresponsible.

# 安装$ yum install mariadb-server# 启动服务$ systemctl start mariadb# 开机启动$ systemctl enable mariadb
Security Configuration for MARIADB

MARIADB The default root password is empty, we need to set it up and execute the script:

sudo mysql_secure_installation

This script will go through some columns of interactive questions and answers to MARIADB security settings.

First prompt for the current root password:

Enter current password to root (enter for none):
The initial root password is empty, we directly hit enter to proceed to the next step.

Set root Password? [y/n]
Set root password, the default option is yes, we directly enter, prompt for password, here set your mariadb root account password.

Remove anonymous users? [y/n]
Whether to remove anonymous users, the default option is yes, we recommend that you press the default setting and enter continue.

Disallow Root login remotely? [y/n]
Do you want to prevent root users from logging on? If you only access mariadb within this machine, we recommend that you press the default setting and enter continue. If you have other cloud hosts that need to use the root account to access the database, you need to select N.

Remove test database and access to it? [y/n]
Do you want to delete the database and permissions for the test? We recommend that you follow the default settings and enter continue.

Reload privilege tables now? [y/n]
Do you want to reload the permissions table? Because we have updated the root password above, we need to reload, enter.

Upon completion you will see Success! 's prompt, MARIADB security settings have been completed. We can log in to mariadb using the following command:

-uroot-p

When prompted to enter the root password, it will enter the MARIADB interface, indicating that the installation has been successful.

Finally we set the mariadb to boot.

sudo systemctl enable mariadb
Make the extranet available for linking

Grant all on. To ' root ' @ '% ' of ' identified by ' root ';
Flush privileges;

Installing composer

Composer's name, I do not want to introduce, if you are a phper, useless, I do not blame you, after all, but he now just after 1.0 version, but if not heard, please wall go ...

Installation Instructions

$ php -r “readfile(‘https://getcomposer.org/installer‘);” > composer-setup.php$ php composer-setup.php$ php -r “unlink(‘composer-setup.php’);”

The functions of the above 3 commands are:

  1. Download the installation script (composer-setup.php) to the current directory.
  2. Perform the installation process.
  3. Remove the installation script –composer-setup.php.
Global Installation composer

The global installation is to install Composer under the path contained in the system environment variable path, and then be able to execute the Composer command directly in the command-line window.

Mac or Linux system: Open a command-line window and execute the following command to move the previously downloaded Composer.phar file to the/usr/local/bin/directory:

$ sudo mv composer.phar /usr/local/bin/composer

Then execute:
composer -v

Since composer's packages are all abroad, here is a set of composer configuration, so that each time they run, use the domestic package

$ composer config -g repo.packagist composer https://packagist.phpcomposer.com

View Composer's configuration file
Vim/root/.composer/config.json

See above to indicate a successful configuration!

At this point, the basic PHP7 environment has been built. Then, next time talk about building Redis with vagrant. Of course I'm not just talking about Redis's build amount. Look at it then!

Vagrant Series Tutorial (iii): vagrant-built PHP7 environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.