CentOS 7.0 (64-bit) server environment build (apache+mariadb+php), by the author side, may appear different version of the configuration of the situation.
- 1
CentOS 7 defaults to using firewall as the firewall, changing it to iptables firewall
Close Firewall Service
Command:systemctl stop Firewalld.service
Disable firewall boot
Command:systemctl disable Firewalld.service
- 2
Installing the Iptables Firewall
Command:yum install iptables-services
- 3
Edit the firewall configuration file
Command:vim/etc/sysconfig/iptables
Press I to enter insert mode and add the following:
-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
Then press ESC to exit Insert mode, enter: Wq Save and exit
- 4
Restart the firewall for configuration to take effect
Command:systemctl restart Iptables.service
Setting up a firewall boot
Command:systemctl enable Iptables.service
- 5
Turn off SELinux
Modifying a configuration file
Command:vim/etc/selinux/config
Press I to enter insert mode,
The selinuxtype=targeted #注释掉
Press ESC to exit, enter: Wq Save and exit
Note: If not the same, you can modify the configuration file according to the above requirements
- 6
Make configuration effective immediately
Command:setenforce 0
Description, SELinux is completely closed
Note:
Setenforce 1 setting SELinux to become enforcing mode
Setenforce 0 Setting SELinux to become permissive mode
- 7
Installing Apache
Command:yum install httpd
Commands that may be used:
systemctl start Httpd.service #启动apache
systemctl Stop Httpd.service #停止apache
systemctl Restart Httpd.service #重启apache
systemctl enable Httpd.service #设置apache开机启动
- 8
Restart Apache
After restarting, enter the domain name or IP address in the browser, if the machine can enter localhost for testing
Appears as follows, indicating that the installation was successful.
- 9
Set Apache boot up
Command:systemctl enable Httpd.service
- 10
Installing the Database
Command:yum install mariadb mariadb-server
Note: In CentOS 7.0, the MySQL database has been replaced with MARIADB
Commands that may be used:
systemctl start Mariadb.service #启动MariaDB
systemctl Stop Mariadb.service #停止MariaDB
systemctl Restart Mariadb.service #重启MariaDB
systemctl enable Mariadb.service #设置开机启动
- 11
Copy configuration file
Command:cp/usr/share/mysql/my-huge.cnf/etc/my.cnf
Note: Copy the configuration file (Note: if the/etc directory has a default MY.CNF, you can directly overwrite it)
- 12
Restart MARIADB
Command:systemctl restart Mariadb.service
If the following conditions indicate that MARIADB is not started, you can press CTRL + C to exit and start the database.
- 13
Set a password for root
Command:mysql_secure_installation
Here, you can press ENTER directly (no password at the beginning, then you need to enter a password to change the password)
You will then be asked to enter the password two times, then enter
Then press Y plus enter.
Until the thanks for using MariaDB appears
- 14
Restart the mariadb and set it to boot
Command:systemctl restart Mariadb.service
Command:systemctl enable Mariadb.service
- 15
Install PHP
Command:yum install php
- 16
Install PHP components to enable PHP support MariaDB
Command:yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath PHP-MHA SH
Restart Apache and MARIADB
Command:systemctl restart Mariadb.service
Command:systemctl restart Httpd.service
-
Configure Apache
Editing a configuration file
Command:vim/etc/httpd/conf/httpd.conf
Press I to enter insert mode
Modify the configuration file according to the following requirements:
Serversignature on #添加, the Apache version is displayed on the error page, off is not displayed
AllowOverride None #修改为: allowoverride All (Allow. htaccess)
Options Indexes FollowSymLinks (some may be Options None) #修改为: Options includes execcgi followsymlinks (allows the server to execute CGI and SSI, Prohibit list of directories)
#AddHandler cgi-script. CGI #修改为: AddHandler cgi-script. cgi. PL (allows CGI scripts with extension. pl to run)
Adddefaultcharset UTF-8 #修改为: Adddefaultcharset GB2312 (add GB2312 as default encoding)
DirectoryIndex index.html #修改为: DirectoryIndex index.html index.htm default.html default.htm index.php (set default home file, add index.php)
Maxkeepaliverequests #添加MaxKeepAliveRequests 50 (increased number of simultaneous connections)
If you have a domain name, you can change the domain name to your domain name at servername.
Finally press ESC to exit Insert mode, enter: Wq Save and exit
Restart Apache
Command:systemctl restart Httpd.service
Delete the default Test home page (This step can be ignored)
Command:rm-f/etc/httpd/conf.d/welcome.conf/var/www/error/noindex.html
Configure PHP
Editing a configuration file
Command:Vim/etc/php.ini
Press I to enter insert mode
Modify according to the following requirements
Date.timezone = PRC #把前面的分号去掉, changed 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/
Press ESC to exit Insert mode, enter: Wq Exit and save
Restart Apache and MARIADB
Command:systemctl restart Mariadb.service
Command:systemctl restart Httpd.service
Test
Enter the root directory of the server (default is var/www/html, which can be modified in the configuration file)
Command:cd/var/www/html
Create a index.php file
Command:vim index.php
Write the following content
Press I to enter insert mode
Enter the following:
<?php
Phpinfo ();
?>
Press ESC to exit Insert mode, enter: Wq Save and exit
View Final Results
Enter the server IP or domain name in the browser, native can enter localhost, appear as shown in the result is successful
END