Apache + Nginx + MySql + PHP configuration introduction. For more information, see
1. Enable sshd after installing the system and disable the firewall (otherwise, the external link cannot access apache). disable the security system SELinux (otherwise, a 403 page access error is reported)
It takes effect permanently after restart
Chkconfig sshd on (enable sshd)
Chkconfig iptables off (disable firewall)
Modify selinux = disabled in the/etc/SELINUX/config file (disable SELinux)
Takes effect immediately and becomes invalid after restart
# Service sshd start (enable sshd)
# Service iptables stop (disable firewall)
# Setenforce 0 (disable SELinux)
2. mysql + apache is installed in centos6 by default. You can use rpm-q mysql or httpd to check whether mysql and apache are installed by default.
Set chkconfig to boot (chkconfig -- list is to list the current state. If mysqld and httpd are not listed in the list, use chkconfig -- add mysqld and httpd)
Next, chkconfig httpd on and chkconfig mysqld on will take effect permanently only after restart. If it takes effect immediately, use service httpd start service mysqld start.
3. Modify the apache configuration file, such as changing the website document directory or pointing different domain names to different folders or open ports. The default configuration file is httpd. conf in the/etc/httpd/conf folder.
1) modify the document Directory of the website and modify DocumentRoot "/var/www" <Directory "/var/www"> under httpd. conf. The directories are the same.
2 ). different domain names direct to different directories in httpd. conf lookup # Inculde/etc/httpd/conf/httpd-vhosts.conf remove the previous # if this sentence does not exist just added and create the httpd-vhosts.conf file (or directly in/etc/httpd/conf. d directory to create a httpd-vhosts.conf because http. conf already # Inculde/etc/httpd/conf. d /*. conf)
# Ensure that Apache in listening to port 80 that httpd. conf file to have the following sentence can also be placed in the httpd-vhosts.conf
Listen 80 modify the httpd-vhost.conf file format as follows
# Listen to all IP addresses of a VM
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 commands here </VirtualHost> <VirtualHost *: 80> DocumentRoot/var/www/ ServerName www.a.com # You can add other commands here Errorlog "logs/a. log" CustomLog "logs/B. log" common </VirtualHost> |
You can change the/etc/hosts file on an external computer, for example, change the C: WindowsSystem32driversetchosts file on a windows platform (assume 192.168.0.110 is the server we deployed)
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
Enter www.example.com on the external computer and jump to the/var/www/directory.
Enter www.a.com on the external computer and select the/var/www/a directory.
Enter www. B .com on the external computer and select the/var/www/directory.
Why does input www. B .com pick the/var/www/directory, because the server cannot find the virtual host name in the httpd-vhosts.conf, just pick the first virtual directory of port 80 by default
3). Open different ports for the website first in the httpd. conf or httpd-vhosts.conf (it is recommended to write here) Add the port to listen
Listen 8080 // added fracture to be opened
Then the httpd-vhost.conf is added in the same format as port 80
Reference http://blog.csdn.net/edisonlg/article/details/7217153
4. install the php initial system without yum install php.
The php configuration file is php. ini. You can use find/-name php. ini in the location of/etc/php. ini.
Now we need apache to support (BIND) the php script language.
Add the following two lines to the configuration file httpd. conf of apache under # AddType application/x-tar. tgz:
AddType application/x-httpd-php. php
AddType application/x-httpd-php-source. phps
DirectoryIndex index.html. var index. php // Add the index when accessing the directory. php can be changed to/etc/httpd/conf. php. conf. (We recommend that you use/etc/httpd/conf/httpd. conf already has Include conf. d /*. conf)
In php. conf, we can see the code of Apache binding PHP script language, so the above httpd-vhosts.conf file can be written directly in the/etc/httpd/conf. d directory.
Modify the php configuration file php. ini and open the mysql extension to remove it; extension = mysql. so semicolon
Restart apache to perform service httpd restart.
5. Install phpMyAdmin
1) download the latest phpMyAdmin package from the official website.
2) decompress the package tar zxvf phpMyAdmin-2.113-all-languages.tar.gz
(3) Music phpMyAdmin-2.113-all-languages/var/www/phpMyAdmin
4) The phpMyAdmin configuration file is in the/phpMyAdmin/libraies/config. default. php file (if the configuration is configured with config. ini. php In the root directory, the installation is abnormal)
After the installation is complete, you can log on through the web page, but the default mysql password is empty. If phpMyAdmin does not allow empty password login, you can change the mysql password or change the phpMyAdmin configuration file to allow empty password login.
Open the configuration file and find
$ Cfg ['servers'] [$ I] ['nopassword'] = false
$ Cfg ['servers'] [$ I] ['allownopassword'] = false
Change the values of false to true.
$ Cfg ['servers'] [$ I] ['auth _ type'] = 'cooker ';
Is the default value.
$ Cfg ['servers'] [$ I] ['auth _ type'] = 'config ';
In config mode, the user and password parameters are required. Therefore, you do not need to enter the user name and password to log on to PhpMyAdmin, which is less secure and suitable for multi-user testing and development.
$ Cfg ['servers'] [$ I] ['user'] = 'root ';
$ Cfg ['servers'] [$ I] ['Password'] = '';
6. Install the PHP extension module
In linux, the PHP extension installation module, for example, if phpMyAdmin is enabled, will prompt that the PHP extension mbstring is not found, and now you seem to be using the multi-byte character set. PhpMyAdmin without the mbstring extension cannot correctly split the string and may produce unexpected results.
In php. ini plus extension = mbstring. so restart apache (httpd) and run find/-name mysql. so the directory for storing the module is usually/usr/lib/php/modules/mysql. for this location, check whether the/usr/lib/php/modules/directory contains mbstring. so
It is shown that yum install php-mbstring is not so well installed, and then restart apache (httpd). The error prompt is "no ".
7. Install Nginx + PHP (source code installation required)
1) install Nginx
If apache is installed in centos by default, use yum remove httpd and then install ngnix. Because the yum source does not contain ngnix
Yum installation instructions are provided on the official website:
The 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 deployments 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 also source code installation, but you need to install the dependency package (a bit of trouble)
The Nginx configuration file is in/etc/nginx. conf
However, the final part of the file is Include/etc/nginx/conf. d/*. conf that contains other files;
Then # service nginx start # chkconfig nginx on
2) install PHP
However, if you install PHP directly using yum
By default, Nginx and PHP do not have a sense of either of them. Many friends have built Apache + PHP before. After compiling Apache + PHP, the module File is generated, nginx + PHP requires PHP to generate executable files. Therefore, you must use fastcgi technology to integrate Nginx with PHP. You only need to enable FastCGI for installation. This time we install PHP not only use FastCGI, but also use the PHP-FPM such a stuff, PHP-FPM said White is a management FastCGI a manager, it as a PHP plug-in pure in, install PHP in the form of a patch to install the PHP-FPM to php to use the PHP-FPM, and PHP to be consistent with the PHP-FPM version, this is necessary, remember!
So PHP to install the source code when the PHP-FRM option with that unzip the PHP source package after
Install gcc first. This is a compiler yum install gcc-c ++ (libmcrypt is required)
. /Configure -- prefix =/usr/local/php -- with-gd -- enable-mbstring -- with-mysql -- with-mysqli -- with-jpeg-dir -- with-zlib --- openssl -- with-mcrypt -- enable-fastcgi -- enable-fpm
The following error occurs during this process:
A) error: xml2-config not found. Please check your libxml2 installation.
Because php5 requires libxml2 to support rpm-qa | grep libxml2
Just install libxml2-dev, yum install libxml2-devel
B) if an openssl error occurs, yum install openssl-devel
C) configure: error: Invalid Lib. h not found. Solution: yum install libjpeg-devel
D) configure: error: png. h not found solution: yum install libpng-devel
E) configure: error: mcrypt. h not found. Please reinstall libmcrypt.
Solution: The yum Code cannot be installed. Therefore, Baidu must search the libmcrypt source code.
Download the page http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/ (this may be different from the php version)
Libmcrypt. /configure (here it cannot be -- prefix to specify the installation path or the following installation will still fail) may report check .... no ignore these checking for g77... no fastcgi warning, but No error occurs, for example, configure: error: no F77 compiler found.
Next, # make install
Go to the php Directory and continue. /configure -- prefix =/usr/local/php -- with-gd -- enable-mbstring -- with-mysql -- with-mysqli -- with-jpeg-dir -- with-zlib --- openssl -- with-mcrypt -- enable-fastcgi -- enable-fpm
The installation of php will encounter errors can refer to the http://www.cnblogs.com/1110111abc/articles/2528102.html
Next
# 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 // otherwise the following startup php-fpm will report an error and cannot find the php-fpm.conf File
Next we will start PHP-FPM
#/Usr/local/php/sbin/php-fpm-c/usr/local/php/etc/php. ini // If the-c parameter is not added, specify its php. ini parameter (it must not be modified later. INI file) (lsof-I: 9000 can be used to view port 9000 Usage Details) it is not feasible to add start to the end of the online statement (maybe in earlier versions)
Vim/etc/rc. local
Add the following statement at the end of the file:
/Usr/local/php/sbin/php-fpm-c/usr/local/php/etc/php. ini here, the service you want to start must be written as an absolute path !! Otherwise, the service cannot be started !!
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
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 knows how to find PHP, but it still does not work. You also need PHP to know how to find Nginx. We don't need to worry about this, the PHP-FPM has defined in the configuration file where to accept PHP requests, and we can open the configuration file to see (Apache is different as long as Apache is bound to PHP)
# Vi/usr/local/php/etc/php-fpm.conf
If you want to change port 9000 to another port, change the port number of the two files
Restart Nginx
# Create a test page with vim/usr/share/nginx/html/a. php
<? Php
Phpinfo ();
?>
Run phpinfo (); incorrect date time zone solution vim/usr/local/php/etc/php. ini is set to date. timezone = Asia/Shanghai
Success as reference http://wenku.baidu.com/view/570b78b765ce050876321377.html
If you want to open a port on Nginx or something 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 500 502 503 x.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 Fig: 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 modify it.