centos6.4 +nginx+mysql+php+phpmyadmin

  • 2020-05-24 06:36:58
  • OfStack

This article illustrates the integration process of centos6.4 +nginx+mysql+php+phpmyadmin by example. I will share it with you for your reference as follows:

The machine was installed for many times and repeated work was done for many times. Finally, the experience of installing CentOS was summarized as follows:

Note: many of the problems are not problems. Please turn off selinux first! setenforce 0, or you'll die a horrible death!

1. Update the source first

Enable domestic source: 163 or sohu

163: http: / / mirrors. 163. com /. help/centos html

If you want to use the new software, it is recommended to use the REPL and remi sources


#remi The source of the 
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
#Fedora REPL The source of the 
rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-remi

Then yum update upgrades the system

Here's how to install the software we need, such as nginx+php+ php-fpm +mysql+vsftpd

Let's start configuring:

1. Set the system time


cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
date # View system time 
*/30 * * * * /usr/sbin/ntpdate time.nist.gov
crontab -e

Add this line: */30 * * * */ usr/sbin/ntpdate time.nist.gov

2. Update the system


yum update

3. Install Nginx:

Niginx official update source increase: vim/etc/yum repos. d/nginx repo

Add the following


[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
yum install nginx

Optimize Nginx configuration:


# According to the CPU The core processes And decide 
worker_processes 6;
worker_cpu_affinity 000001 000010 000100 001000 010000 100000 ;<br><br>
# To enable the epoll
worker_rlimit_nofile 51200;
events {
  worker_connections 51200;
  use epoll;
}

# Parameter adjustment 
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
keepalive_timeout 50;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;

#fastcgi To optimize the 
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;

# open gzip And optimize the 
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;

Setup startup:


service nginx start
chkconfig nginx on
# The installation php . php-fpm
yum install php php-fpm php-bcmatch php-gd php-mbstring php-mcrypt php-mysql

Configure the PHP script to run:


cp/etc/nginx/conf.d/default.conf etc/nginx/conf.d/default.confbak
vim /etc/nginx/conf.d/default.conf

Set the default directory of the website: # here php-fpm USES the mode of listening port. It is better to use unix socket for the same machine


# Remove the comment below 
location ~ \.php$ {
  root /home/www;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  include fastcgi_params;
}
# Pay attention to the fastcgi_param The parameter , Instead of $document_root$fastcgi_script_name, Or use absolute paths 

4. vsftpd configuration

Configure iptables, vi /etc/sysconfig/iptables, copy --dport 22, paste to port 21. Save and restart service iptables restart.


yum install vsftpd ftp
touch /var/log/vsftpd.log
service vsftpd start
chkconfig vsftpd on
vim /etc/vsftpd/vsftpd.conf
# Modify the relevant parameters as follows: 
# Set not to allow anonymous access 
anonymous_enable=NO
# Make it accessible to local users. Note: if a virtual host user is used, set as in the project NO The case where all virtual users will not be able to access. 
local_enable=YES
# The user cannot leave the home directory , And document it 
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
# set vsftpd The service log saves the path. Note that this file does not exist by default. You have to do it manually touch Come out  , The previous step has been created 
xferlog_file=/var/log/vsftpd.log
# Allows the use of ASCII Mode upload and download 
ascii_upload_enable=YES
ascii_download_enable=YES
#PAM Authentication file name. PAM Based on the /etc/pam.d/vsftpd authentication 
pam_service_name=vsftpd
# These are about Vsftpd The importance of virtual user support CentOS FTP Service configuration project. The default vsftpd.conf These Settings are not included in the. You need to manually add them RHEL/CentOS FTP Service configuration. 
# Set to enable the virtual user function. 
guest_enable=YES
# Specify the host user for the virtual user. -RHEL/CentOS There are already built-in ones ftp The user 
guest_username=ftp
# Set up the virtual user individual vsftp the RHEL/CentOS FTP Service file location path. Storing virtual user personalities CentOS FTP Service file ( Profile name = Virtual username ) user_config_dir=/etc/vsftpd/vuser_conf
touch /etc/vsftpd/chroot_list
echo ftp >> /etc/vsftpd/chroot_list
yum install db4 db4-utils
vim /etc/vsftpd/vuser_passwd.txt

Add the corresponding user information, in which the odd number of your new user account, even number of password, no space

username1
password1
username2
password2

Save file exit and generate user authenticated db file


db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db
vim /etc/pam.d/vsftpd

Comment everything with #, then add the following two lines:


cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
date # View system time 
*/30 * * * * /usr/sbin/ntpdate time.nist.gov
crontab -e

0

Save to exit. Create the virtual user's ftp service folder, as well as the account user profile added in the previous article


cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
date # View system time 
*/30 * * * * /usr/sbin/ntpdate time.nist.gov
crontab -e

1

Fill in the following:


cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
date # View system time 
*/30 * * * * /usr/sbin/ntpdate time.nist.gov
crontab -e

2

Save the content and exit. Create the user root directory set in the configuration file above and set permissions for it


mkdir /home/www/ftp
chmod 777 /home/www/ftp
service vsftpd restart

ok

Sometimes, you can connect to ftp, but you can't list the directory. This is a port problem of iptable. Open PASV can, vim etc/vsftpd/vsftpd conf


cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
date # View system time 
*/30 * * * * /usr/sbin/ntpdate time.nist.gov
crontab -e

4

And then add these two ports to iptables, again, yy1 line 22, p1, change 22 to 9000:9020;

It could be the shutdown of selinux,


cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
date # View system time 
*/30 * * * * /usr/sbin/ntpdate time.nist.gov
crontab -e

5

5. Install Mysql5. 6


cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
date # View system time 
*/30 * * * * /usr/sbin/ntpdate time.nist.gov
crontab -e

6

Remember to run after the installation is complete


cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
date # View system time 
*/30 * * * * /usr/sbin/ntpdate time.nist.gov
crontab -e

7

When remote connection is made, mysql3306 port shall be added to iptables. Similarly, use the previous method to copy 1 sentence 22, change it to 3306, and restart iptables.

Configure mysql remote connection: the command line logs in with root


mysql -uroot -p
use mysql;
update user set host = '%' where user = 'root';

Other possible jobs:

Install phpMyAdmin

google phpMyAdmin find the address in sourceforge and then go down to wget in the root of the website.

Unzip, rename directory, go to directory,


cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
date # View system time 
*/30 * * * * /usr/sbin/ntpdate time.nist.gov
crontab -e

9

Restart nginx

Note that you have to change it one more time. When the browser enters the phpmyadmin address, the following error may appear:

Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.

Need to be/var lib php/session nginx instead of owners


chown -R nginx:nginx /var/lib/php/session

It should be accessible now...

Configure the mysql remote connection

Because of administration needs, we need remote connection 1 under mysql for administration. After installing phpmyadmin, you can choose to create a new user at the user's site and set the host to ip or any host you want to connect to

Auto mount hard disk:

Since there is an external hard disk, you have to configure boot mount automatically. vim /etc/fstab


/dev/sdc /mnt/data auto defaults 0 0

centos network configuration:

IP setting: /etc/sysconfig/ network-scripts/ifcfg-eth0

Gateway Settings: /etc/sysconfig/network

DNS Settings: /etc/ resolv.conf

Restart the network:


service network restart

Close the SELiinux

In the following work, I found many inconvenient places, for example, ftp could not upload, ssh could not connect remotely, so I closed SELinux and ran the following command:


yum update

3

This allows you to turn off SELinux and add boot to boot.

I hope this article has helped you with your CentOS server configuration.


Related articles: