CentOS 7.0 server PHP Environment setup

Source: Internet
Author: User
Tags install php

CentOS 7.0 server PHP Environment setupListen to the Voice
    • |
    • Browse:1043
    • |
    • Updated: 2016-11-30 14:18
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
Step through Reading

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.

Tools/Materials
    • CentOS 7 Server One
    • Apache
    • MariaDB
    • Php
Method/Step
  1. 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. 2

    Installing the Iptables Firewall

    Command:yum install iptables-services

  3. 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. 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. 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. 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. 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. 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. 9

    Set Apache boot up

    Command:systemctl enable Httpd.service

  10. 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. 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. 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. 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. 14

    Restart the mariadb and set it to boot

    Command:systemctl restart Mariadb.service

    Command:systemctl enable Mariadb.service

  15. 15

    Install PHP

    Command:yum install php

  16. 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

  17. Restart Apache and MARIADB

    Command:systemctl restart Mariadb.service

    Command:systemctl restart Httpd.service

  18. 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

  19. Restart Apache

    Command:systemctl restart Httpd.service

  20. 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

  21. 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

  22. Restart Apache and MARIADB

    Command:systemctl restart Mariadb.service

    Command:systemctl restart Httpd.service

  23. 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

  24. Create a index.php file

    Command:vim index.php

  25. 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

  26. 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
Precautions
    • Note that different versions of the configuration files are not necessarily the same and can be configured according to the document description

CentOS 7.0 server PHP Environment setup

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.