Introduction to apache+nginx+mysql+php Configuration

Source: Internet
Author: User
Tags fpm install php openssl php file php script php source code iptables phpmyadmin

1. After installing the system, turn on the sshd, close the firewall (otherwise the link is not access to Apache) shut down the security system SELinux (otherwise reported 403 access page error)
Permanently effective after reboot
Chkconfig sshd on (open sshd)
Chkconfig iptables off (firewall off)
Modify the/etc/selinux/config file to set selinux=disabled (Close SELinux)
Immediate effect, reboot disabled
#service sshd Start (open sshd)
#service iptables Stop (firewall shutdown)
#setenforce 0 (Close SELinux)
2. The default CENTOS6 installed Mysql+apache available rpm-q MySQL or httpd to see if the default has been installed
Chkconfig is set to boot up (Chkconfig--list is listed currently, if there are no mysqld and httpd in the list, use Chkconfig--add mysqld and httpd)
Then Chkconfig httpd on and Chkconfig mysqld on this is only to be restarted only after it is permanently effective if immediate effect with service httpd start service mysqld start
3. Modify Apache configuration files such as changing the Web site document directory or different domain names point to different folders or openings, and so on the default profile in the/etc/httpd/conf folder httpd.conf
1. Modify the Web site document directory under httpd.conf modify DocumentRoot "/var/www" <directory "/var/www" > these two directories
2. Different domain names point to different directories in the httpd.conf lookup #Inculde/etc/httpd/conf/httpd-vhosts.conf Remove the previous #号如果不存在刚加上这一句且创建 httpd-vhosts.conf file ( Or build a httpd-vhosts.conf directly under the/ETC/HTTPD/CONF.D directory because http.conf is #inculde/etc/httpd/conf.d/*.conf.
# Make sure Apache has one of the following words in the 80 port, httpd.conf file, which you can actually put in the httpd-vhosts.conf.

Listen 80 Modify the httpd-vhost.conf file format as follows
# Monitor all IP addresses for the virtual host

The code is as follows Copy Code
Namevirtualhost *:80
<virtualhost *:80>
ServerAdmin edu1211@163.com
documentroot/var/www/
ServerName www.example.com
# You can add other instructions here
</VirtualHost>
<virtualhost *:80>
documentroot/var/www/a
ServerName www.a.com
# You can add other instructions here
Errorlog "Logs/a.log"
Customlog "Logs/b.log" common
</VirtualHost>

The above can change the/etc/hosts file on the external computer such as changing the C:windowssystem32driversetchosts file on the Windows platform (assuming 192.168.0.110 is the server we are deploying)
127.0.0.1 localhost
192.168.0.110 www.example.com
192.168.0.110 www.a.com
192.168.0.110 www.b.com

Then enter www.example.com on the external computer and skip to the/var/www/directory.
The input www.a.com on the external computer is selected to the/var/www/a directory.
The input www.b.com on the external computer is selected to the/var/www/directory.
Why input www.b.com will be picked up in the/var/www/directory because the server cannot find the virtual host name in httpd-vhosts.conf the first virtual directory of Port 80 has just been picked up by default
3. Open a different port for the website first in httpd.conf or httpd-vhosts.conf (recommended to write here) plus the ports to listen on
Listen 8080//Added to open fracture
Then httpd-vhost.conf add the same format as 80 ports
Reference documentation http://blog.111cn.net/edisonlg/article/details/7217153
4. Install PHP initial system is not installed Yum install PHP can
PHP configuration file is php.ini can use Find/-name php.ini general in/etc/php.ini this position
Now you want Apache to support (BIND) the PHP scripting language
That is, to modify the Apache configuration file httpd.conf The following two lines under #addtype Application/x-tar. tgz
AddType application/x-httpd-php. php
AddType Application/x-httpd-php-source. Phps
DirectoryIndex index.html Index.html.var index.php//that plus access to the directory index.php in fact, the above can be changed/ETC/HTTPD/CONF.D directory php.conf on it ( This is recommended because/etc/httpd/conf/httpd.conf already has include conf.d/*.conf)
In php.conf we can see the Apache bound PHP script language code so the above httpd-vhosts.conf file can be written directly in the/ETC/HTTPD/CONF.D directory.
At the same time modify the PHP configuration file php.ini Open the MySQL extension is removed; extension=mysql.so semicolon
Then restart Apache to service httpd restart
5. Install phpMyAdmin
1 to the official website download the latest phpMyAdmin package
2) Decompression Package tar zxvf phpmyadmin-2.113-all-languages.tar.gz
3 MV Phpmyadmin-2.113-all-languages/var/www/phpmyadmin
4 phpmyadmin configuration file in/phpmyadmin/libraies/config.default.php file (if the config.ini.php is installed with the root directory exception)
The installation is complete to log on through the Web page but the default MySQL is a blank password and phpmyadmin prohibit the blank password login can change the MySQL password or change the phpMyAdmin configuration file by the command line to allow the null password to log in
Open configuration file to find
$cfg [' Servers '] [$i] [' Nopassword '] =false
$cfg [' Servers '] [$i] [' Allownopassword '] =false
Change the false of these two lines to true
$cfg [' Servers '] [$i] [' auth_type '] = ' cookie ';
is the default, if more into
$cfg [' Servers '] [$i] [' auth_type ']= ' config ';
Config mode requires User,password parameters, when the login phpMyAdmin do not need to enter a username password, security is low, suitable for multiuser test development that is
$cfg [' Servers '] [$i] [' User ']= ' root ';
$cfg [' Servers '] [$i] [' Password ']= ']; You are logged in as a default
6. Install PHP expansion module
Linux under the PHP extension installation modules such as Open phpMyAdmin will be prompted not to find the PHP extension mbstring, and you now seem to be using multibyte character sets. phpMyAdmin that do not have mbstring extensions do not correctly segment strings, which can produce unexpected results.
Then in php.ini plus extension=mbstring.so restart Apache (httpd) or not then run Find/-name mysql.so Locate the directory of the storage module is generally/usr/lib/php/modules/ Mysql.so This position is looking for the/usr/lib/php/modules/directory there is no mbstring.so
It shows that you don't have to install Yum install php-mbstring and then restart Apache (httpd) just prompted the error.
7. Installation nginx+php (to source installation)
1) Installation Nginx
CentOS The default is to install Apache so use yum remove httpd and then install Ngnix because Yum source is not including Ngnix
Yum installation instructions are available at the official website:

  code is as follows copy code
centos:
To Add Nginx yum Repository, create a file Named/etc/yum.repos.d/nginx.repo and paste one of the configurations below:
[ Nginx]
Name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
Gpgcheck=0
Enabled=1

Other system Reference Http://wiki.nginx.org/Install
Of course there are source code installed but need you to install a dependency pack (a bit cumbersome)
Nginx's profile in   /etc/nginx/ Nginx.conf
But the end of the file is     include/etc/nginx/conf.d/*.conf that contains the other files;
then    #service nginx start    #chkconfig Nginx on
2) install PHP
But if you install PHP directly yum the PHP is not OK
because by default Nginx and PHP are a little Feel no, before, many friends have built apache+php, apache+php compiled after the module file, and nginx+php need PHP to generate executable files can, so to use the FASTCGI technology to achieve N Ginx and PHP integration, this only To install it is to enable FastCGI. This time we installed PHP not only used FastCGI, but also used php-fpm such a dongdong, PHP-FPM plainly is a management FastCGI a manager, it as a PHP plug-in pure in the installation of PHP to use PHP-FPM when you need to put php- FPM installed in the form of a patch to PHP, and PHP to be consistent with the PHP-FPM version, this is necessary, remember!
So the PHP source code when the installation of the PHP-FRM option is to extract the PHP source code package after
Install the GCC suite This is a compiler yum install gcc   yum Install (gcc-c++ PT to use)
./configure--prefix=/usr/local/php--with-gd--enable-mbstring--with-mysql--with-mysqli --with-zlib--with-openssl--with-mcrypt--enable-fastcgi--enable-fpm

The following error occurs in this procedure
A) Error:xml2-config not found. Please check your LIBXML2 installation.
Because PHP5 is needed LIBXML2 support Rpm-qa|grep LIBXML2
Only need to install Libxml2-dev, yum install Libxml2-devel
b The same will appear OpenSSL error so yum install Openssl-devel
c) configure:error:jpeglib.h not found. The solution is: Yum install Libjpeg-devel
d) configure:error:png.h not found solution is: Yum install Libpng-devel
e) configure:error:mcrypt.h not found. Please reinstall Libmcrypt.
Solution Yum Code installation can not be so Baidu search Libmcrypt source code
Download page http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/(this and PHP version can be different)
Libmcrypt./configure (This cannot be--prefix specify the installation path, or the following installation or error) may be reported check .... No ignore these checking for G77 ... no what fastcgi warning but not out Now it's wrong, like Configure:error:No F77 compiler found, so.
Then #make #make Install
Skip to the PHP directory to continue./configure--prefix=/usr/local/php--with-gd--enable-mbstring--with-mysql--with-mysqli--with-jpeg-dir --with-zlib--with-openssl--with-mcrypt--enable-fastcgi--enable-fpm
Installation of PHP process will encounter errors can refer to http://www.cnblogs.com/1110111abc/articles/2528102.html
Then
#make
#make Install
#cp Php.ini-production/usr/local/php/etc/php.ini
#mv/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf//or the following boot PHP-FPM will make an error. php-fpm.conf File not found

Now we're going to start php-fpm.
#/usr/local/php/sbin/php-fpm-c/usr/local/php/etc/php.ini//If no-c parameter is specified for his php.ini parameter (must not be able to modify his php.ini file later) (Lsof-i : 9000 can view 9000 port occupancy details on the net said that the next plus start is not possible (may be the previous version of it)

Vim/etc/rc.local
At the end of this file, add the following statement:
/usr/local/php/sbin/php-fpm-c/usr/local/php/etc/php.ini Here you have to start the service must write is the absolute path form!! Otherwise, this service is not start up!!
The last step is to associate Nginx with PHP

#vim/etc/nginx/conf.d/default.conf
#location ~ php$ {
# root HTML;
# Fastcgi_pass 127.0.0.1:9000;
# Fastcgi_index index.php;
# Fastcgi_param Script_filename/usr/share/nginx/html$fastcgi_script_name;
# include Fastcgi_params;
#}

Change into

Location ~. php$ {
root HTML;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename/scripts$fastcgi_script_name;
Include Fastcgi_params;
Tip: Nginx oneself know how to find PHP not yet, also need PHP know how to find Nginx, this we do not need to worry, PHP-FPM has been defined in the configuration file from where to accept the PHP request, we can open the configuration file look (Apache is different as long as Apache bound PHP on the line)

#vi/usr/local/php/etc/php-fpm.conf
If you want to change port 9000 to another port, then two files will be replaced with one port
Finally reboot Nginx


#service nginx Restart build a test page plus vim/usr/share/nginx/html/a.php
<?php
Phpinfo ();
?>
Execute phpinfo ();d ate time zone incorrect workaround Vim/usr/local/php/etc/php.ini set to Date.timezone = Asia/shanghai
Reference http://wenku.baidu.com/view/570b78b765ce050876321377.html
If you're going to be in the Nginx, like Apache?

The code is as follows Copy Code

server {
Listen 80;
server_name localhost;
#charset Koi8-r;
#access_log/var/log/nginx/log/host.access.log Main;
Location/{
root/usr/share/nginx/html;
Index index.html index.htm;
}
#error_page 404/404.html;
# REDIRECT Server error pages to the static page/50x.html
#
Error_page 502 503 504/50x.html;
Location =/50x.html {
root/usr/share/nginx/html;
}
# Proxy The PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ php$ {
# Proxy_pass http://127.0.0.1;
#}
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
Location ~. php$ {
root HTML;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename/usr/share/nginx/html$fastcgi_script_name;
Include Fastcgi_params;
}
# Deny access to. htaccess files, if Apache ' s document Root
# concurs with Nginx ' s one
#location ~/.ht {
# Deny All;
#}
}

Copy the server and make a change.

Related Article

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.