CentOS 7.0 LAMP server (Apache + PHP + MariaDB)
Preparation:
CentOS 7.0 system installation and configuration graphic tutorial
Http://www.osyunwei.com/archives/7829.html
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:
Systemctl stop firewalld. service # stop firewall
Systemctl disable firewalld. service # disable firewall startup
2. Install iptables Firewall
Yum install iptables-services # Installation
Vi/etc/sysconfig/iptables # edit the firewall configuration file
# 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
Systemctl restart iptables. service # restart the firewall to make the configuration take effect.
Systemctl enable iptables. service # Set firewall startup
Ii. Disable SELINUX
Vi/etc/selinux/config
# SELINUX = enforcing # comment out
# SELINUXTYPE = targeted # comment out
SELINUX = disabled # Add
: Wq! # Save and exit
Setenforce 0 # Make the configuration take effect immediately
Installation:
1. install Apache
System O & M www.osyunwei.com reminder: qihang01 original content©Copyright. For more information, see the source and source text chain.
Yum install httpd # Enter Y as prompted to install httpd.
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
Open the Server IP address in the client browser. The following interface is displayed, indicating that apache is successfully installed.
System O & M www.osyunwei.com reminder: qihang01 original content©Copyright. For more information, see the source and source text chain.
Ii. Install MariaDB
In CentOS 7.0, MariaDB has been used to replace the MySQL database.
1. Install MariaDB
Yum install mariadb-server # ask if you want to install mariadb. Enter Y to install mariadb automatically until installation is complete.
Systemctl start mariadb. service # start MariaDB
Systemctl stop mariadb. service # stop MariaDB
Systemctl restart mariadb. service # restart MariaDB
Systemctl enable mariadb. service # Set startup
Cp/usr/share/mysql/my-huge.cnf/etc/my. cnf # copy the configuration file (Note: if there is a my. cnf under the/etc directory by default, directly overwrite it)
2. Set a password for the root account
Mysql_secure_installation
Press enter and enter Y as prompted.
Enter the password twice and press Enter.
Enter Y as prompted
Thanks for using MySQL!
After setting the MySql password, restart MySQL:
Systemctl restart mariadb. service # restart MariaDB
3. install PHP
1. install PHP
Yum install php # Enter Y as prompted until installation is complete
2. Install the PHP component so that PHP supports MariaDB
Yum install php-mysql php-gd libjpeg * php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
# Select the preceding installation package for installation. Enter Y and press enter as prompted.
Systemctl restart mariadb. service # restart MariaDB
Systemctl restart httpd. service # restart apache
Configuration
1. Apache configuration
Vi/etc/httpd/conf/httpd. conf # edit the file
ServerSignature On # add, the Apache version is displayed On the error page, and Off is not displayed
Options Indexes FollowSymLinks # changed to: Options shortdes ExecCGI FollowSymLinks (allows the server to execute CGI and SSI, and prohibits the list of directories)
# AddHandler cgi-script. cgi # modify it to AddHandler cgi-script. cgi. pl (run a CGI script with the extension. pl)
AllowOverride None # modify to: AllowOverride All (allow. htaccess)
Adddefacharcharset UTF-8 # modify to: adddefadefacharset GB2312 (add GB2312 as the default encoding)
# Options Indexes FollowSymLinks # change to Options FollowSymLinks (the tree directory structure is not displayed in the browser)
DirectoryIndex index.html # changed to: DirectoryIndex index.html index.htm Default.html Default.htm index. php (set the default homepage file and add index. php)
MaxKeepAliveRequests 500 # Add MaxKeepAliveRequests 500 (Increase the number of simultaneous connections)
: Wq! # Save and exit
Systemctl restart httpd. service # restart apache
Rm-f/etc/httpd/conf. d/welcome. conf/var/www/error/noindex.html # Delete the default test page
Ii. php configuration
Vi/etc/php. ini # Edit
Date. timezone = PRC # Remove the semicolon and change it to date. timezone = PRC.
Disable_functions = passthru, exec, system, chroot, scandir, chgrp, chown, shell_exec, proc_open, proc_get_status, ini_alter, ini_alter, disconnect, dl, openlog, syslog, readlink, symlink, release, delimiter, delimiter, dll, popen, disk_free_space, checkdnsrr, checkdnsrr, getservbyname, getservbyport, delimiter, posix_getgrnam, posix_getgroups, posix_getlogin, delimiter, delimiter, posix_getpid, delimiter, delimiter, posix_getpwuid, delimiter, posix_getsid, posix_getuid, delimiter, posix_kill, posix_mkfifo, delimiter, posix_setsid, posix_setuid, posix_strerror, posix_times, posix_ttyname, posix_uname
# List functions that can be disabled by PHP. If some programs need this function, they can be deleted and disabled.
Expose_php = Off # disable display of php version information
Short_open_tag = ON # php short labels supported
Open_basedir =. :/tmp/# set to allow access to the current directory (that is, the directory where the PHP script file is located) And/tmp/directory, which can prevent php trojans from being cross-site, if there is a problem with the installation program after the change (for example, zhimeng Content Management System), you can log out of this line or directly write the program directory/data/www.osyunwei.com/:/tmp/
: Wq! # Save and exit
Systemctl restart mariadb. service # restart MariaDB
Systemctl restart httpd. service # restart apache
Test
Cd/var/www/html
Vi index. php # enter the following content
<? Php
Phpinfo ();
?>
: Wq! # Save and exit
Enter the Server IP address in the browser of the client. The configuration information shown in is displayed!
Note: The default program directory of apache is/var/www/html.
Permission settings: chown apache. apache-R/var/www/html
Now, the installation and configuration of the LAMP server (Apache + PHP + MariaDB) in CentOS 7.0 is complete!