Build an LNMP server under CentOS and take notes after practicing.
Preparation
Configure the firewall and open port 80 and 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 /etc/init.d/iptables restart #Finally restart the firewall to make the configuration take effect If that fails, you can use:
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT Close SELINUX
vi /etc/selinux/config #SELINUX=enforcing #Comment out #SELINUXTYPE=targeted #Comment out SELINUX=disabled #Increase :wq #Save and exit shutdown -r now #Restart the system Install third-party yum source
wget http://www.atomicorp.com/installers/atomic #download sh ./atomic #Install yum check-update #Update yum source
Installation
Install nginx
yum remove httpd* php* #Delete the software package that comes with the system yum install nginx #Install nginx Enter y according to the prompt to install chkconfig nginx on #Set nginx to start at boot service nginx start #Start nginx
InstallMySQL
- InstallMySQL
yum install mysql mysql-server #Enter Y to automatically install until the installation is completed /etc/init.d/mysqld start #StartMySQL 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 by default under the /etc directory, just overwrite it directly)
- Set password for root account
mysql_secure_installation
Enter Y according to the prompts, enter the password twice, press Enter, enter Y all the way according to the prompts, and finally appear: Thanks for using MySQL!
MySql password setting is completed, restart MySQL:
/etc/init.d/mysqld restart #restart /etc/init.d/mysqld stop #stop /etc/init.d/mysqld start #start up
Install PHP5
- Install PHP5
yum install php php-fpm #Enter Y according to the prompts until the installation is completed
- Install PHP components so that PHP5 supports 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 above installation package to install, enter Y according to the prompts and press Enter chkconfig php-fpm on #Set php-fpm to start at boot /etc/init.d/php-fpm start #Start php-fpm
Configuration
- Configure nginx to support php
cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak #Back up 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 #Back up the original configuration file vi /etc/nginx/conf.d/default.conf #edit index index.php index.html index.htm; #Add index.php # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { roothtml; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } #Uncomment the location of the FastCGI 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
service nginx restart #Restart nginx
- php configuration
vi /etc/php.ini #edit date.timezone = PRC #Remove the semicolon in front 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,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_getgrna m,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 can be disabled in PHP. If some programs need to use this function, it can be deleted and undisabled. expose_php = Off #Suppress display of php version information short_open_tag = ON #Support php short tags open_basedir = website root directory:/tmp/ #Setting means allowing access to the current directory (that is, the directory where the PHP script file is located) and the /tmp/ directory; the colon is the separator. :wq! #Save and exit
Some tutorials in the open_basedir configuration option will be configured asopen_basedir=.:/tmp/, where '.' represents the current directory. This method does not seem to work under nginx+phpfastcgi.
- 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 #Modify user to nginx group=nginx #Modify the group to nginx :wq #Save and exit
Test article
cd /usr/share/nginx/html vi index.php #Add the following code phpinfo(); ?> :wq! #Save and exit chown nginx.nginx /usr/share/nginx/html -R #Set permissions service nginx restart #Restart nginx service php-fpm restart #restartphp-fpm
Enter the server IP address in the client browser and you can see the relevant configuration information! It means lnmp configuration is successful!
At this point, the CnetOS 6.5 installation and configuration LNMP (Nginx+PHP+MySQL) tutorial is completed.
This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)". Please keep the following tags for sharing and interpretation:
Original author:Jake Tao,source:"CentOS 6.5 installation and configuration LNMP server (Nginx+PHP+MySQL)"
Comment list (1)
[…] I am in June 2016. The default is RHEL7. Please modify the following slightly according to your own situation. If it is a RHEL6 version, you can refer to my previous article: "CentOS 6.5 Installation and Configuration LNMP Server (Nginx+PHP+MySQL)" […]