Configure the Apache + PHP5 + MySQL environment in CentOS 6.4

Source: Internet
Author: User

Preparation

1. Configure the firewall and enable port 80 and Port 3306.
Vi/etc/sysconfig/iptables
-A input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT # Allow port 80 to pass the firewall
-A input-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT # Allow Port 3306 to pass the firewall

Note: Many users add these two rules to the last line of the firewall configuration, resulting in firewall startup failure,

The correct rule should be added to the default port 22.

As follows:
################################ The following figure shows the firewall rules after they are added # ###############################
# 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
######################################## ######################################## #######
/Etc/init. d/iptables restart # restart the firewall to make the configuration take effect.

2. Disable SELINUX
Vi/etc/selinux/config
# SELINUX = enforcing # Comment out
# SELINUXTYPE = targeted # Comment out
SELINUX = disabled # Add
: Wq # save and exit
Shutdown-r now # restart the system

3. Install a third-party yum source

Yum install wget # install the download tool

System O & M www.111cn.net reminder: qihang01 original content is copyrighted. For reprinting, please indicate the source and original link.

Wget http://www.atomicorp.com/installers/atomic # Download

Sh./atomic # installation

Yum check-update # update yum source

System O & M www.111cn.net reminder: qihang01 original content is copyrighted. For reprinting, please indicate the source and original link.

Installation

1. Install nginx

Yum remove httpd * php * # Delete the built-in software package

Yum install nginx # install nginx by entering y as prompted

Chkconfig nginx on # set nginx startup

Service nginx start # start nginx

II. Install MySQL

1. Install MySQL

Yum install mysql-server # enter Y to automatically install mysql until installation is complete.

/Etc/init. d/mysqld start # start MySQL

Chkconfig mysqld on # set to boot

Cp/usr/share/mysql/my-medium.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. Enter Y as Prompted. Enter the password twice. Press Enter. Enter Y as Prompted. Thanks for using MySQL appears!

After setting the MySql password, restart MySQL:

/Etc/init. d/mysqld restart # restart

/Etc/init. d/mysqld stop # stop

/Etc/init. d/mysqld start # start

3. Install PHP5

1. Install PHP5

Yum install php-fpm # enter Y as prompted until installation is complete

2. Install the PHP component to make PHP5 support MySQL

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

# Select the preceding installation package for installation. Enter Y and press enter as prompted.

System O & M www.111cn.net reminder: qihang01 original content is copyrighted. For reprinting, please indicate the source and original link.

Chkconfig php-fpm on # set the startup of php-fpm

/Etc/init. d/php-fpm start # start php-fpm

Configuration

1. Configure nginx to support php
Cp/etc/nginx. conf/etc/nginx. confbak # back up the original configuration file
Vi/etc/nginx. conf # Edit
User nginx; # Change the nginx running account to: nginx user in the nginx Group
: Wq # save and exit
Cp/etc/nginx/conf. d/default. conf/etc/nginx/conf. d/default. confbak # back up the original configuration file
Vi/etc/nginx/conf. d/default. conf # Edit

Index. php index.html index.htm; # Add index. php

# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ . Php $ {
Root html;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Include fastcgi_params;
}
# Cancel the location comment of the FastCGI server and change the parameter of the fastcgi_param line to $ document_root $ fastcgi_script_name or use the absolute path.
Service nginx restart # restart nginx

II. php configuration
Vi/etc/php. ini # Edit
Date. timezone = PRC # Remove the semicolon in front of row 946 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, ini_restore, dl, ope

Nlog, syslog, readlink, symlink, popepassthru, stream_socket_server, escapeshellcmd, dll, popen, disk_free_space, checkdnsrr, checkdns

Rr, 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
# List the functions that PHP can disable in row 3. If some programs need this function, delete it and disable it.
Expose_php = Off # Disable Display of php version information in line 432
Magic_quotes_gpc = On # enable magic_quotes_gpc On Line 1 to prevent SQL injection
Short_open_tag = ON # php short labels are supported in line 229
Open_basedir =. :/tmp/# set in row 380 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.111cn.net/:/tmp/
: Wq! # Save and exit

3. Configure php-fpm
Cp/etc/php-fpm.d/www. conf/etc/php-fpm.d/www. confbak # back up the original configuration file
Vi/etc/php-fpm.d/www. conf # Edit
User = nginx # Change the user to nginx
Group = nginx # Change the group to nginx
: Wq # save and exit

Test

Cd/usr/share/nginx/html

Vi index. php # add the following code
<? Php
Phpinfo ();
?>

: Wq! # Save and exit

Chown nginx. nginx/usr/share/nginx/html-R # set permissions

Service nginx restart # restart nginx

Service php-fpm restart # restart php-fpm

Enter the server IP address in the client browser to view the configuration information!

Indicates that lnmp is successfully configured!

At this point, the installation and configuration of LNMP (Nginx + PHP + MySQL) tutorial in the same language as the Nginx 6.4 is complete. Next we will start to configure the apache site.

Redhat Enterprise Linux (including CentOS Linux) is the most widely used Linux server. A large number of website applications are deployed on it.
1. Open the file/etc/httpd/conf/httpd. conf, search for VirtualHost example, and find the code as follows:
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# Server name.
#
# <VirtualHost *: 80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot/www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
# </VirtualHost>
2. Add a piece of code to specify the website of a domain name.
#
# DocumentRoot is the root directory for storing website files
# ServerName is the website domain name, which must be consistent with the domain name pointed to by DNS
#
<VirtualHost *: 80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot/var/www/httpdocs/demo_neoease_com
ServerName demo.neoease.com
ErrorLog logs/demo.neoease.com-error. log
CustomLog logs/demo.neoease.com-access. log common
</VirtualHost>
3. Restart the httpd service and execute the following statement.
Service httpd restart

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.