1024programmer Nginx CentOS6.2 system yum way to install and configure LNMP environment

CentOS6.2 system yum way to install and configure LNMP environment

1. Configure the firewall, open 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 through the firewall)
-A INPUT -m state –state NEW
-m tcp -p tcp –dport 3306 -j ACCEPT (allow port 3306 through the firewall)
Special reminder: Many netizens add these two rules to the last line of the firewall configuration, causing the firewall to fail to start. The correct one should be added below the default port 22 rule
After adding, the firewall rules are as follows:
#################################################### #######
# 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 #Finally restart the firewall to make the configuration take effect

2. Close SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #Comment out
#SELINUXTYPE=targeted #Comment out
SELINUX=disabled
#increase
:wq save, close
shutdown -r now
#Restart the system

3. Configure CentOS 6.2 third-party yum source (the default standard source of CentOS does not have nginx package)
yum install
wget #Install download tool wget
wget
http://www.atomicorp.com/installers/atomic #Download atomic yum source
sh ./atomic
#install
yum check-update
#Update yum package
#################################################### ##############################
Installation articles:

1. Install nginx
yum install
nginx #Install nginx, according to the prompt, enter Y to install successfully
service nginx
start #start
chkconfig nginx
on #Set to start at boot
/etc/init.d/nginx
restart #restart
rm -rf
/usr/share/nginx/html/* #Delete ngin default test page

2. Install MySQL
1. Install mysql

yum install mysql mysql-server
#Ask if you want to install, enter Y to install automatically until the installation is complete
/etc/init.d/mysqld
start #Start MySQL
chkconfig mysqld
on #Set to start at 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, just overwrite it directly)
shutdown -r now
#Restart the system

2. Set a password for the root account
mysql_secure_installation
  Enter, enter Y
according to the prompt
  Enter the password twice and press Enter
  Enter Y all the way according to the prompt
  Last occurrence: Thanks for using
MySQL!
  MySql password setting is complete, restart MySQL:
/etc/init.d/mysqld stop
#stop
/etc/init.d/mysqld start
#start
service mysqld
restart #restart

3. Install PHP
1. Install PHP
yum install php
#Enter Y according to the prompt until the installation is complete
2. Install PHP components to make PHP support
MySQL and PHP support FastCGI mode
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
libmcrypt-devel
php-fpm
#Enter Y and enter according to the prompt
/etc/init.d/mysqld restart
#Restart MySql
/etc/init.d/nginx
restart #Restart nginx
/etc/rc.d/init.d/php-fpm
start #Start php-fpm
chkconfig php-fpm on
#Set boot start
#################################################### ##############################
Configuration

1. Configure nginx to support php
  cp /etc/nginx/nginx.conf
/etc/nginx/nginx.confbak #Backup the original configuration file
vi /etc/nginx/nginx.conf
#edit
user nginx
nginx; #Modify the nginx running account to: nginx user of the nginx group
:wq!
#Save and exit

cp /etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/default.confbak #Backup the original configuration file
vi /etc/nginx/conf.d/default.conf #Edit

index index.php index.html index.htm;
#Increase index.php

# 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
$document_root$fastcgi_script_name;
include
fastcgi_params;
}
# Cancel FastCGI
Note the location of the server part, and pay attention to the parameters of the fastcgi_param line, change it to $document_root$fastcgi_script_name, or use an absolute path

Two, configure php

vi /etc/php.ini #Edit

date.timezOne= PRC #in line 946
Remove the previous semicolon and change it to date.timezOne= PRC

disable_functionOns=
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
#On line 386, list the functions that PHP can disable. If some programs need to use this function, you can delete and cancel the disable.
expose_php = Off
#In line 432, prohibit the display of php version information
magic_quotes_gpc = On #at line 745
Turn on magic_quotes_gpc to prevent SQL injection
open_basedir = .:/tmp/
#In line 380, the setting indicates that access to the current directory (that is, the directory where the PHP script file is located) and the /tmp/ directory is allowed, which can prevent the php Trojan from crossing sites. If there is a problem with the installation program after changing it, you can log out
This line, or directly write the program directory path /var/www/html/www.osyunwei.com/:/tmp/
:wq! #Save and exit

3. Configure php-fpm

cp
/etc/php-fpm.d/www.conf
/etc/php-fpm.d/www.confbak #Backup the original configuration file
vi
/etc/php-fpm.d/www.conf #Edit
user = nginx
#Modify the user as nginx
group = nginx
#Modify the group to nginx

/etc/init.d/mysqld restart #Restart MySql
/etc/init.d/nginx
restart #Restart nginx
/etc/rc.d/init.d/php-fpm
restart #Restart php-fpm
#################################################### ##############################
Test articles
cd
/usr/share/nginx/html/ #Enter the root directory of the nginx default website
  vi index.php
#New index.php file

<?php
phpinfo();
?>
:wq! #save

chown nginx.nginx /usr/share/nginx/html/ -R #Set directory owner

chmod 700 /usr/share/nginx/html/ -R
#Set directory permissions

Enter the server IP address in the client browser, you can see the relevant configuration information!
##################################################### #############################

Remark

The default site directory of nginx is: /usr/share/nginx/html/

Permission setting: chown nginx.nginx /usr/share/nginx/html/ -R

The MySQL database directory is: /var/lib/mysql

Permission setting: chown mysql.mysql -R /var/lib/mysql



��

chown nginx.nginx /usr/share/nginx/html/ -R #Set directory owner

chmod 700 /usr/share/nginx/html/ -R
#Set directory permissions

Enter the server IP address in the client browser, you can see the relevant configuration information!
##################################################### #############################

Remark

The default site directory of nginx is: /usr/share/nginx/html/

Permission setting: chown nginx.nginx /usr/share/nginx/html/ -R

The MySQL database directory is: /var/lib/mysql

Permission setting: chown mysql.mysql -R /var/lib/mysql


This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/centos6-2-system-yum-way-to-install-and-configure-lnmp-environment/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索