VM VirtualBox Virtual installation of CentOS, installation of nginx,mysql,php, and network configuration

Source: Internet
Author: User
Tags chmod fpm install php mcrypt iptables vm virtualbox

After installing CentOS on a computer virtual machine, it is generally not connected to the external network at this time using Yum can not install gcc,gcc++ and other compiled software, then you can not compile the installation apache.mysql, you need to change the network configuration file.

In the virtual machine set up network 1 for network address translation NAT instead of NAT mode, Network 2 is bridged mode.

Vi/etc/sysconfig/network-scripts/ifcfg-eth0

Make the following configuration in the inside

DEVICE=ETH1//NIC Name
Onboot=yes//Start
BOOTPROTO=DHCP//Using DHCP
Peerdns=yes//Change DNS file

hwaddr=08:00:27:90:9b:08//mac address written on your CentOS MAC address

And then save the exit

Add a network card to CentOS using bridging mode

Vi/etc/sysconfig/network-scripts/ifcfg-eth1

Device=eth1

Onboot=yes

Bootrpoto=none//Do not use DHCP

Ipaddr= your LAN IP

netmask=255.255.255.0

gateway= LAN Gateway

Hwaddr=mac Address

Save exit

Restart the network to load the changes.

Service Network restart//Restart Network Service

You can now use the ping command to test the

PING-C 4 Gateway IP

If you return correctly, you can connect to the extranet. If the error can be the network 1, Network 2 settings Exchange.

Install MySQL

Generally appears, the library character prompts; to prevent errors

Yum-y install gcc gcc-c++ ncursese ncurses-devel wget

Get MySQL

Cd/usr/local/src

wget http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.1/5.1.73.tar.gz//Get MySQL

TAR-ZXVF mysql-5.1.73//Decompression MySQL

CD mysql-5.1.73

Configuring the compilation File
./configure--prefix=/usr/local/mysql--enable-thread-safe-client--enable-assembler--with-big-tables-- With-client-ldflags=-all-static--with-mysqld-ldflags=-all-static--with-charset=utf8--with-collation=utf8_ General_ci--with-extra-charsets=complex

Make//Compile
Make Install//install

MySQL configuration:

Add MySQL User

Groupadd MySQL

Useradd-g mysql-s/sbin/nologin MySQL

Change Data Directory Permissions
Chown-r Mysql.mysql/usr/local/mysql/var
Chmod-r 700/usr/local/mysql/var

Initialize Authorization table
./lib/mysql_install_db--user=mysql

Copy configuration file to etc so that MySQL configuration is detected when starting MySQL on boot
CP./SHARE/MYSQL/MY-MEDIUM.CONF/ETC/MY.CNF

Set boot up:
CP./share/mysql/mysql.server/etc/rc.d/init.d/mysqld
chmod +x/etc/rd.d/init.d/mysqld
Chkconfig--add mysqld
Add the MySQL environment variable:
Vi/etc/profile
Add to
Path= $PATH:/usr/local/mysql/bin//Add Linux environment variable
Export PATH
Perform. /etc/profile
Start MySQL
Service MySQL Start

PHP Installation

errors that are commonly seen in compiling

When the PHP installation error XML appears:
Yum-y Install LIBXML2 Libxml2-devel
Yum-y Install Libpng-devel Libjpeg-devel
Installing Libmcrypt
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
When a flock error occurs: (Unable to find the library error)
Vim/etc/ld.so.conf.d/local.conf # Edit Library file
/usr/local/lib # Add this line
: Wq # Save exit
Ldconfig-v # Make it come into effect

When using Nginx as a Web server, Nginx supports PHP in a CGI way, so the PHP php-fpm function is turned on when you install PHP.
Download PHP
wget http://cn2.php.net/distributions/php-5.4.7.tar.gz
./configure--prefix=/usr/local/php \
--ENABLE-FPM \
--with-mcrypt \
--enable-mbstring \
--DISABLE-PDO \
--with-curl \
--disable-debug \
--disable-rpath \
--enable-inline-optimization \
--WITH-BZ2 \
--enable-sockets \
--enable-sysvsem \
--ENABLE-SYSVSHM \
--ENABLE-PCNTL \
--enable-mbregex \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-mysql=/usr/local/mysql \ # # needs to install MySQL first
--with-mysqli=/usr/local/mysql/bin/mysql_config \ # #需啊哟先安装MYSQL
--WITH-GD \
--with-jpeg-dir

Make

Make install

CP./etc/php-fpm.conf.default./etc/php-fpm.conf

VI./etc/php-fpm.conf

User=www-data

Group=www-data

: Wq

./bin/php-fpm start;

Installing Nginx

Because Nginx does not have native support, gzip compression, PREC support URL rewriting
wget ftp://ftp.csx.cam.ac.uk/pub.software/programming/pcre/pcre-8.34.tar.gz
To install the Zlib library:
wget http://zlib.net/zlib-1.2.8.tar.gz
Download Nginx
wget http://nginx.org/download/nginx-1.4.2.tar.gz


After decompression:
Compile:
./configure--sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.34 \
--with-zlib=/usr/local/src/zlib-1.2.8 \

Make
Make install

Configuring Nginx Support PHP

  

In the NGINX.CONF server field, add the
User=nobody
Location ~ \.php$ {
root HTML;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename/usr/local/nginx/html/$fastcgi _script_name;
Include Fastcgi_params;
}

Start Nginx
Sudo/usr/local/nginx/nginx

Then see if Apache joins the PHP module

If not joined

Vi/etc/httpd/conf.d/php.conf

<ifmodule prefork.c>

LoadModule Php5_module modules/libphp5.so

</IfModule>

<ifmodule worker.c>

LoadModule Php5_module modules/libphp5-zts.so

</IfModule>

AddHandler php5-sceipt. php

AddType text.html. php

DirectoryIndex. index.php

And then save the exit

Service httpd Restart

Install MySQL

Yum install MySQL mysql-server mysql-devel

After the installation is successful

Then edit the firewall settings to allow ports 80 and 3306

Vi/etc/sysconfig/iptables

-A input-m state–state new-m tcp-p tcp–dport 80-j ACCEPT (allow 80 ports through the firewall)
-A input-m state–state new-m tcp-p tcp–dport 3306-j ACCEPT (Allow 3306 ports through the firewall)
Special Note: Many netizens add these two rules to the last line of the firewall configuration, causing the firewall to fail to start, the correct one should be added to the default 22 port under this rule

/etc/init.d/iptables restart

If it doesn't work, you can use it this way.

[[email protected] httpd]#/sbin/iptables-i input-p TCP--dport 80-j ACCEPT

[Email protected] httpd]#/etc/rc.d/init.d/iptables Save

[Email protected] httpd]#/etc/init.d/iptables restart

Add a third network card to CentOS, select only mode so that the virtual machine can be accessed between

What we need to do is to enter the/etc/sysconfig/network-scripts directory and modify the ifcfg files of the two NICs.
A. Modify the Ifcfg-eth0 file to configure the Host-only network:
# first NIC
Device=eth2
# Boot up
Onboot=yes
# Launch Protocol, NONE/DHCP
Bootproto=none
# Configure DNS
dns=192.168.56.1
# If the/etc/resolv.conf file is automatically modified after the DNS directive is set, the default yes for the start protocol is DHCP
Peerdns=yes
# IP Address
ipaddr=192.168.56.110
# Mask
netmask=255.255.255.0
# Gateway
gateway=192.168.56.1
# Physical Address of the NIC device, default, consistent with VirtualBox network Setup interface
Hwaddr=08:00:27:75:ad:13
# non-root user cannot control this device
Userctl=no

MySQL Set root password

Use MySQL

UPDATE user set Password=password (' password ') WHERE user = ' root ';

Flush privileges;

Setting up a MySQL remote connection

UPDATE user set host= '% ' WHERE user= ' root ';

GRANT all privileges on * * to [email protected] '% ' indentified by ' password ' with GRANT OPTION;

Flush privileges;

VM VirtualBox Virtual installation of CentOS, installation of nginx,mysql,php, and network configuration

Related Article

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.