CentOS 7 Install Apache PHP MariaDB

Source: Internet
Author: User
Tags apache php install php iptables

Prepare the article:

First, configure the firewall, open 80 port, 3306 port

CentOS 7 defaults to using firewall as the firewall, where the iptables firewall is changed.

1. Close firewall:

Systemctl Stop Firewalld.service #停止firewall

Systemctl Disable Firewalld.service #禁止firewall开机启动

2. Install iptables Firewall

Yum Install iptables-services #安装

Vi/etc/sysconfig/iptables #编辑防火墙配置文件

# Firewall configuration written by System-config-firewall

# Manual Customization of this file are 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! #保存退出

Systemctl Restart Iptables.service #最后重启防火墙使配置生效

Systemctl Enable Iptables.service #设置防火墙开机启动

Second, to close SELinux

Vi/etc/selinux/config

#SELINUX =enforcing #注释掉

#SELINUXTYPE =targeted #注释掉

Selinux=disabled #增加

: wq! #保存退出

Setenforce 0 #使配置立即生效

Installation article:

First, install Apache

Yum Install httpd #根据提示, enter Y to install successfully

Systemctl Start Httpd.service #启动apache

Systemctl Stop Httpd.service #停止apache

Systemctl Restart Httpd.service #重启apache

Systemctl Enable Httpd.service #设置apache开机启动

Second, installation mariadb

In CentOS 7.0, the MySQL database has been replaced with MARIADB

1, installation mariadb

Yum Install mariadb mariadb-server #询问是否要安装, enter y for automatic installation until installation is complete

Systemctl Start Mariadb.service #启动MariaDB

Systemctl Stop Mariadb.service #停止MariaDB

Systemctl Restart Mariadb.service #重启MariaDB

Systemctl Enable Mariadb.service #设置开机启动

CP/USR/SHARE/MYSQL/MY-HUGE.CNF/ETC/MY.CNF #拷贝配置文件 (Note: If the/etc directory has a my.cnf under the default, you can directly overwrite it)

2. Set the password for the root account

Mysql_secure_installation

Enter, follow the prompts for Y

Enter Password 2 times, enter

Enter Y as prompted

Last appearance: Thanks for using mysql!

MySQL password setup is complete, restart MySQL:

Systemctl Restart Mariadb.service #重启MariaDB

Third, install PHP

1. Install PHP

Yum Install PHP #根据提示输入Y直到安装完成

2, install PHP components, so that PHP support MariaDB

Yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath Php-mhash

#这里选择以上安装包进行安装, enter Y return as prompted

Systemctl Restart Mariadb.service #重启MariaDB

Systemctl Restart Httpd.service #重启apache

Configuration Chapter

One, Apache configuration

Vi/etc/httpd/conf/httpd.conf #编辑文件

Serversignature on #添加, the Apache version is displayed on the error page, off is not displayed

Options Indexes followsymlinks #修改为: Options includes execcgi followsymlinks (Allow server to execute CGI and SSI, disallow listing of directories)

#AddHandler cgi-script. CGI #修改为: AddHandler cgi-script. cgi. PL (allows CGI scripts with extension. pl to run)

AllowOverride None #修改为: allowoverride All (Allow. htaccess)

Adddefaultcharset UTF-8 #修改为: Adddefaultcharset GB2312 (add GB2312 as default encoding)

#Options Indexes followsymlinks #修改为 Options followsymlinks (does not show the tree structure on the browser)

DirectoryIndex index.html #修改为: DirectoryIndex index.html index.htm default.html default.htm index.php (set default home file, add index.php)

Maxkeepaliverequests #添加MaxKeepAliveRequests 500 (increase the number of simultaneous connections)

: wq! #保存退出

Systemctl Restart Httpd.service #重启apache

Rm-f/etc/httpd/conf.d/welcome.conf/var/www/error/noindex.html #删除默认测试页

Second, PHP configuration

Vi/etc/php.ini #编辑

;d Ate.timezone = PRC #把前面的分号去掉, change to Date.timezone = PRC

Disable_functions = Passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_ Alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server, Escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space, POSIX_CTERMID,POSIX_GET_LAST_ERROR,POSIX_GETCWD, Posix_getegid,posix_geteuid,posix_getgid, Posix_getgrgid,posix_ Getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, Posix_getppid,posix_getpwnam, Posix_getpwuid, Posix_getrlimit, Posix_getsid,posix_getuid,posix_isatty, Posix_kill,posix_mkfifo,posix_setegid, Posix_seteuid,posix_setgid, Posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname, Posix_uname

#列出PHP可以禁用的函数, if some programs need to use this function, you can delete, cancel disable.

expose_php = Off #禁止显示php版本的信息

Short_open_tag = on #支持php短标签

Open_basedir =.:/ tmp/#设置表示允许访问当前目录 (that is, the PHP script files in the directory) and/tmp/directory, you can prevent the PHP Trojan cross-site, if you change the installation program after the problem (for example: Dream Content Management System), you can log off this line, or directly write the program directory/data/ www.osyunwei.com/:/tmp/

: wq! #保存退出

Systemctl Restart Mariadb.service #重启MariaDB

Systemctl Restart Httpd.service #重启apache

Test article

Cd/var/www/html

VI index.php #输入下面内容

1 <? PHP 2 3 Phpinfo (); 4 5 ?>

: wq! #保存退出

Enter the server IP address in the client browser and see Phpinf () Print the information that is successful 1

CentOS 7 Install Apache PHP MariaDB

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.