Configure Apache + MySQL + PHP in CentOS7

Source: Internet
Author: User

Configure Apache + MySQL + PHP in CentOS7

1. configure the firewall and enable port 80 and port 3306

CentOS 7.0 uses firewall as the firewall by default. Here, it is changed to iptables firewall.

1. Disable firewall:

# Stop the firewall Service

  1. Systemctl stop firewalld. service
# Disable firewall startup
  1. Systemctl disable firewalld. service

2. Install iptables Firewall

# Installation

  1. Yum install iptables-services
# Edit the firewall configuration file
  1. Vi/etc/sysconfig/iptables

# 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

COMMIT

: Wq! # Save and exit

# Restart the firewall to make the configuration take effect.

  1. Systemctl restart iptables. service
# Set firewall startup
  1. Systemctl enable iptables. service

Ii. Disable SELINUX
# Modifying the configuration file

  1. Vi/etc/selinux/config

# SELINUX = enforcing # comment out

# SELINUXTYPE = targeted # comment out

SELINUX = disabled # Add

: Wq! # Save and exit

# Make the configuration take effect immediately

  1. Setenforce 0

3. install apache

  1. Yum install httpd

Which may be used:

Systemctl start httpd. service # start apache

Systemctl stop httpd. service # stop apache

Systemctl restart httpd. service # restart apache

Systemctl enable httpd. service # Set apache startup


Restart, and then:
Enter localhost
After it appears, it indicates that it has been installed.

4. Install mysql

1. Method 1: Install mariadb

The MariaDB database management system is a branch of MySQL. It is mainly maintained by the open-source community and licensed by GPL. One of the reasons for developing this branch is that after Oracle acquired MySQL, there is a potential risk of closing the source of MySQL. Therefore, the community uses the branch method to avoid this risk. MariaDB is designed to be fully compatible with MySQL, including APIs and command lines, so that it can easily become a substitute for MySQL.

Install mariadb. The size is 59 MB.

[root@yl-web yl]# yum install mariadb-server mariadb 

The commands related to the mariadb database are:

Systemctl start mariadb # start MariaDB

Systemctl stop mariadb # stop MariaDB

Systemctl restart mariadb # restart MariaDB

Systemctl enable mariadb # Set startup

So start the database first.

[root@yl-web yl]# systemctl start mariadb

Then you can use mysql normally.

[root@yl-web yl]# mysql -u root -pEnter password: Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 3Server version: 5.5.41-MariaDB MariaDB ServerCopyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               |+--------------------+4 rows in set (0.00 sec)MariaDB [(none)]> 

Mariadb [(none)]> is displayed after MariaDB is installed. It may seem a bit unaccustomed. The following is the second method.

2. Method 2: download and install mysql-server on the official website

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm# rpm -ivh mysql-community-release-el7-5.noarch.rpm# yum install mysql-community-server

After successful installation, restart the mysql service.

# service mysqld restart

The first time mysql is installed, the root account does not have a password.

[root@yl-web yl]# mysql -u root Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.6.26 MySQL Community Server (GPL)Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               |+--------------------+4 rows in set (0.01 sec)mysql> 

Set Password

mysql> set password for 'root'@'localhost' =password('password');Query OK, 0 rows affected (0.00 sec)mysql> 

It takes effect without restarting the database.

The following content is displayed during mysql installation:

Installed: mysql-community-client.x86_64 0:5.6.26-2.el7 mysql-community-devel.x86_64 0:5.6.26-2.el7  mysql-community-libs.x86_64 0:5.6.26-2.el7 mysql-community-server.x86_64 0:5.6.26-2.el7 Dependency Installed: mysql-community-common.x86_64 0:5.6.26-2.el7 Replaced: mariadb.x86_64 1:5.5.41-2.el7_0 mariadb-devel.x86_64 1:5.5.41-2.el7_0 mariadb-libs.x86_64 1:5.5.41-2.el7_0  mariadb-server.x86_64 1:5.5.41-2.el7_0 

After installation, mariadb is automatically replaced and will no longer take effect.

[root@yl-web yl]# rpm -qa |grep mariadb[root@yl-web yl]# 

3. Configure mysql

1) Encoding

The mysql configuration file is/etc/my. cnf.

Add the encoding Configuration

[mysql]default-character-set =utf8

The character encoding must be consistent with/usr/share/mysql/charsets/Index. xml.

2) remote connection settings

Assign all permissions for all tables in all databases to the root user at all IP addresses.

mysql> grant all privileges on *.* to root@'%'identified by 'password';

If it is a new user rather than a root user, you must create a new user first.

mysql>create user 'username'@'%' identified by 'password';  

Now you can make a remote connection.


5. install php

  1. Yum install php
Install the PHP component to make PHP support mysql
  1. Yum install php-mysql php-gd libjpeg * php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
Restart the corresponding service
  1. Systemctl restart mysqld. service
  2. Systemctl restart httpd. service

Reference blog http://blog.itpub.net/29773961/viewspace-1261417/,http://www.cnblogs.com/starof/p/4680083.html

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.