Vagrant Series Tutorial (iii): Vagrant built PHP7 Environment

Source: Internet
Author: User

Read Catalogue

    • Start Nginx and set to boot
    • Installing Iptables
    • Edit the firewall configuration file
    • Configure Nginx to access PHP
    • Test access
    • Security Configuration for MARIADB
    • Make the extranet available for linking
    • Global Installation composer

Original: http://blog.csdn.net/hel12he/article/details/51107236

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.

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

Go back to the top to start the Nginx and set it to boot
$ systemctl Start Nginx $ 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.

$ RPM-IVH 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.

$ RPM-IVH 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.

$ systemctl Stop Firewalld.service $ systemctl Disable Firewalld.service #防止开机启动

Go back to the top of the installation iptables
$ yum Install Iptables-services

The installation process is as shown

Start Iptables Firewall

Systemctl start Iptables.service systemctl enable Iptables.service #开机自动启动
Back to top edit 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

$ yum List--enablerepo=remi--enablerepo=remi-php70 | grep php70

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-php70 php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt p Hp-mysqlnd php-pecl-xdebug php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common Php-json php- IMAP Php-pecl-redis php-pecl-memcached Php-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$ systemctl enable PHP-FPM #设置开机自启动
Back to top configure Nginx to access PHP

Enter Nginx's file configuration center,

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       ;    server_name  localhost;    CharSet Utf-8;    root/vagrant/www;# own project directory, that is, the PHP project directory location    /{        # Please note, be sure to add index.php this        index  index.php Index.html index.htm;    }    Error_page   502 503 504  /50x.html;    Location =/50x.html {        root   /usr/share/nginx/html;    }    Location ~ \.php$ {        fastcgi_pass   127.0.0.1:9000;        Fastcgi_index  index.php;        # Note the different fastcgi_param of variables here  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
    • 1
    • 1
Back to the top of the 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.

# Setup $ yum Install mariadb-server# start service $ systemctl start mariadb# boot $ systemctl Enable MARIADB
Back to the top mariadb security Configuration

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:

$ mysql-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
Back to the top let the extranet be linked
Mysql> Grant All on * * to ' root ' @ '% ' identified by ' root ';mysql> 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.
Back to top 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 (turn)

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.