Preface: the last article wrote about Git repository building, a friend said that the server has not been built, so here is an environment building.

Note: I build for Centos6 and above, there are major changes for Centos7 and above

1. Configure the firewall, enable port 80 and port 3306, delete the original iptables, and add appropriate configurations

rm -rf /etc/sysconfig/iptablesvim /etc/sysconfig/iptablesCopy the code

Add the following:

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.*filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state ESTABLISHED,RELATED -j  ACCEPT -A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMITCopy the code

:wq Save the configuration and exit. Restart the firewall for the configuration to take effect

D /iptables restart centos 7.0 or later Run systemctl restart firewalld.serviceCopy the code

Close the SELINUX

rm -rf  /etc/selinux/configvim /etc/selinux/configCopy the code

Then add a line:

SELINUX=disabledCopy the code

: wq Saves the configuration and exits

Restart the system.

shutdown -r nowCopy the code

Note: You must restart the system after configuring the firewall

Install the third-party YUM source

Install the download tool

yum install wgetCopy the code

download

wget http://www.atomicorp.com/installers/atomicCopy the code

The installation

sh ./atomicCopy the code

Update the yum source

yum check-updateCopy the code

Install Nginx

Delete the software package delivered with the system

yum remove httpd* php*Copy the code

Install nginx

yum install -y nginxCopy the code

Set nginx to boot

Chkconfig nginx on Centos 7.0 or later Run systemctlenable nginx.serviceCopy the code

Start the nginx

Service nginx startCentos 7.0 or higher systemctl start nginx.serviceCopy the code

Note:
nginxThe startup may fail. You need to modify the configuration file

Starting nginx: nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol) [failed]Copy the code

Processing method

vim /etc/nginx/conf.d/default.confCopy the code

will

listen       80 default_server;
listen       [::]:80 default_server;Copy the code

To:

listen       80;#listen [::]:80 default_server;Copy the code

Save the exit
:wq,Restart the success

Open the browser and enter the IP address. The NGINx welcome page is displayed

Install PHP

Check the PHP package currently installed

yum list installed | grep phpCopy the code

If there are installed PHP packages, remove them first, such as:

yum remove php.x86_64 php-cli.x86_64 php-common.x86_64Copy the code

Configure the installation package source:

Centos 5.X 
 rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
CentOs 6.x  
 rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
CentOs 7.X  
 rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm  
 rpm -Uvh   https://mirror.webtatic.com/yum/el7/webtatic-release.rpmCopy the code

Note: Different versions of the server need to configure the corresponding installation package, if you want to delete the above installation package and reinstall

rpm -qa | grep webstaticrpm -e[The packages searched above are ok]Copy the code

Perform the installation

yum -y install php56w.x86_64
yum -y --enablerepo=webtatic install php56w-devel
yum -y install php56w-gd.x86_64 php56w-ldap.x86_64  php56w-mbstring.x86_64 php56w-mcrypt.x86_64 
yum -y install php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64Copy the code

Note: For each command see Complete! Only successful

The installation
PHP FPM

yum -y install php56w-fpmCopy the code

Set phP-fpm to boot upon startup

Chkconfig php-fpm onCentos7.0 or above systemctlenable php-fpm.serviceCopy the code

Start the PHP – FPM

/etc/init.d/php-fpm startCentos 7.0 or higher systemctl start php-fpmCopy the code

Note: if you want to switch to php5.5 or 5.4, change the 56w to 55w or 54w directly

Install MySQL

The installation

 yum install -y mysql mysql-serverCopy the code

Start the MySQL

/etc/init.d/mysqld startCopy the code

Set to boot on

chkconfig mysqld onCopy the code

Copy the configuration file (note: if there is a my.cnf in /etc directory by default, overwrite it directly)

cp /usr/share/mysql/my-medium.cnf /etc/my.cnfCopy the code

Set the password for user root

mysql_secure_installationCopy the code

Press Enter, enter Y as prompted, enter the password twice, press enter, enter Y as prompted, finally appear:

Thanks for using MySQL!Copy the code

MySql > select * from ‘MySql’ where ‘password’ is set

# to restart

/etc/init.d/mysqld restartCopy the code

stop

/etc/init.d/mysqld stopCopy the code

Start the

/etc/init.d/mysqld startCopy the code

Configure nginx

The nginx directory where I put it

[root@iZ2zeftluibm3hesz36v3tZ conf.d]# pwd
/etc/nginx/conf.d
Copy the code

[root@iZ2zeftluibm3hesz36v3tZ conf.d]# ll
total 20
-rw-r--r-- 1 root root 1501 Feb  9 10:54 admin.shop.conf
-rw-r--r-- 1 root root  434 Dec 25 20:39 default.conf.bak
-rw-r--r-- 1 root root 1419 Feb  8 17:19 web.shop.conf
Copy the code

Because in nginx.conf

include /etc/nginx/conf.d/*.conf;
Copy the code

/etc/nginx/conf.d create a.conf file and copy it to {listen 80; Server_name Resolve domain name; index index.php index.html index.htm default.html default.htm default.php; client_header_buffer_size 16k; large_client_header_buffers 4 32k; client_max_body_size 300m; client_body_buffer_size 128k; Location / {root project path; index index.php; proxy_connect_timeout 3000; proxy_send_timeout 3000; proxy_read_timeout 3000; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k;if (!-e $request_filename) { rewrite ^/index.php(.*)$ /index.php? s=The $1last; rewrite ^(.*)$ /index.php? s=The $1 last;
                        break; }} location ~ \.php${root; Fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name; include fastcgi_params; }}Copy the code

: wq Saves the configuration and exits

Configure phP-fpm

vim /etc/php-fpm.d/www.confCopy the code

Set the user and user group to nginx, such as:

Example Change the user name to nginx

user = nginxCopy the code

Change the group to nginx

group = nginxCopy the code

8. Start testing

cd /var/www
vim index.php
Copy the code
Add the following code

<? php phpinfo(); ? > :wq!Copy the code
Save the exit

# Set permissions

chown nginx.nginx /var/www -RCopy the code

# restart nginx

service nginx restartCopy the code

# restart PHP – FPM

service php-fpm restartCopy the code

If your mysql database cannot be connected remotely, you should authorize it

USE mysql;  GRANT ALL PRIVILEGES ON *.* TO 'root'@The '%'WITH GRANT OPTION;  FLUSH PRIVILEGES;Copy the code

GRANT ALL PRIVILEGES. The first * in *.* is the name of the database in which PRIVILEGES are granted, the root is the user name, and the % is ALL the IP addresses in which PRIVILEGES are granted.

Here is roughly finished, the establishment of a lot of server environment, I also comprehensive each previous experience, add some of their own understanding, hope to have a little help for friends in need. Here is my previous Git repository build.

Ha ha, knowledge lies in sharing, wish you grow together.