Establish LNMP Environment
Chapter 2LNMPEnvironment Construction
Unlike LAMP, N in LNMP indicates Nginx (similar to a web service software in Apache. Currently, this type of environment has many applications. Nginx was designed to provide a fast, efficient, and concurrent web service software. Nginx is superior to Apache in processing static pages. However, Nginx does not have much advantage over Apache in Processing dynamic pages. However, many fans are still keen on Nginx. As Nginx technology matures, it is becoming increasingly popular in the web service software field.
[MySQL installation]
1. Download mysql to/usr/local/src/
Cd/usr/local/src/
Wget http://syslab.comsenz.com/downloads/linux/mysql-5.0.86-linux-i686-icc-glibc23.tar.gz
2. Extract
Tar zxvf/usr/local/src/mysql-5.0.86-linux-i686-icc-glibc23.tar.gz
3. Move the extracted data to/usr/local/mysql.
Music mysql-5.0.86-linux-i686-ii-glibc23/usr/local/mysql
4. Create a mysql user
Useradd mysql
5. initialize the database
Cd/usr/local/mysql
Mkdir/data/mysql; chown-R mysql: mysql/data/mysql
./Scripts/mysql_install_db -- user = mysql -- datadir =/data/mysql
-- User defines the owner of the database, -- datadir defines where the database is installed, and it is recommended to put it in a large space partition, this directory needs to be created by yourself.
6. Copy the configuration file
Cp support-files/my-large.cnf/etc/my. cnf
7. Copy the startup script file and modify its attributes.
Cp support-files/mysql. server/etc/init. d/mysqld
Chmod 755/etc/init. d/mysqld
8. Modify the Startup Script
Vim/etc/init. d/mysqld
You need to modify datadir =/data/mysql (the directory defined during database initialization)
9. Add the startup script to the system service items, set the startup to start mysql
Chkconfig -- add mysqld
Chkconfig mysqld on
Service mysqld start
If the log cannot be started, go to/data/mysql/to view the error log. The log format is host name. err.
【PhpInstallation]
Here, we must first declare that php installation for Nginx is different from php installation for apache, because php In Nginx is combined with nginx in fastcgi mode, it can be understood that nginx acts as the proxy for php fastcgi, while apache calls php as its own module.
Useradd www
Cd/usr/local/src/
Wget http://syslab.comsenz.com/downloads/linux/php-5.2.10.tar.gz
Wget http://syslab.comsenz.com/downloads/linux/php-5.2.10-fpm-0.5.13.diff.gz
The second package php-5.2.10-fpm-0.5.13.diff.gz is used to patch php. By default, php cannot compile fastcgi.
Tar zxvf php-5.2.10.tar.gz
Gzip-cd php-5.2.10-fpm-0.5.13.diff.gz | patch-d php-5.2.10-p1
Cd php-5.2.10
. /Configure -- prefix =/usr/local/php -- with-config-file-path =/usr/local/php/etc -- with-mysql =/usr/local/mysql -- with-mysql-sock =/tmp -- with-libxml-dir -- with-gd -- with-jpeg-dir -- with-png-dir -- with-freetype-dir -- with-iconv -dir -- with-zlib-dir -- with-mcrypt =/usr/local/libmcrypt -- enable-soap -- enable-gd-native-ttf -- enable-ftp -- enable-mbstring -- enable-exif -- enable-zend-multibyte -- disable-ipv6 -- enable-fastcgi -- enable-fpm
Make & make install
Mkdir/usr/local/php/etc
Cp php. ini-dist/usr/local/php/etc/php. ini
Vim/usr/local/php/etc/php-fpm.conf
// Tmp/php-fcgi.sock This line needs to be changed. After this is modified, you need to pay attention to this path When configuring nginx.
Modify the user and group name to "www"
Change the comment to the following:
Unix user of processes
Www
Unix group of processes
Www
/Usr/local/php/sbin/php-fpm start
For more information about how to install php extension modules, see:
Install mysql5.1.57 + php5.2.17 (FastCGI) + nginx1.0.1 High-Performance Web server in CentOS 5.5
【NginxInstallation and configuration]
1. nginxSource code Installation
cd /usr/local/src/wget http://syslab.comsenz.com/downloads/linux/nginx-0.9.6.tar.gztar zxvf nginx-0.9.6.tar.gzcd nginx-0.9.6./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/var/nginx.pid --lock-path=/usr/local/nginx/var/nginx.lock --http-client-body-temp-path=/dev/shm/nginx_temp/client_body --http-proxy-temp-path=/dev/shm/nginx_temp/proxy --http-fastcgi-temp-path=/dev/shm/nginx_temp/fastcgi --user=www --group=www --with-cpu-opt=pentium4F --without-select_module --without-poll_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --without-http_ssi_module --without-http_userid_module --without-http_geo_module --without-http_memcached_module --without-http_map_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-pcremake && make installmkdir /dev/shm/nginx_temp
Some nginx versions cannot be compiled due to pcre. You need to modify -- with-pcre =/usr/local/src/pcre-7.8. The pcresource code package pcre-7.8.tar.gz has been downloaded, and decompress to/usr/local/src/pcre-7.8, do not need to compile pcre
2.WriteNginxAnd add the startup script to the system service.
Vi/etc/init. d/nginx write the following content:
#!/bin/bash# chkconfig: - 30 21# description: http service.# Source Function Library. /etc/init.d/functions# Nginx SettingsNGINX_SBIN="/usr/local/nginx/sbin/nginx"NGINX_CONF="/usr/local/nginx/conf/nginx.conf"NGINX_PID="/usr/local/nginx/var/nginx.pid"RETVAL=0prog="Nginx"start() {echo -n $"Starting $prog: "mkdir -p /dev/shm/nginx_tempdaemon $NGINX_SBIN -c $NGINX_CONFRETVAL=$?echoreturn $RETVAL}stop() {echo -n $"Stopping $prog: "killproc -p $NGINX_PID $NGINX_SBIN -TERMrm -rf /dev/shm/nginx_tempRETVAL=$?echoreturn $RETVAL}reload(){echo -n $"Reloading $prog: "killproc -p $NGINX_PID $NGINX_SBIN -HUPRETVAL=$?echoreturn $RETVAL}restart(){stopstart}configtest(){$NGINX_SBIN -c $NGINX_CONF -treturn 0}case "$1" instart)start;;stop)stop;;reload)reload;;restart)restart;;configtest)configtest;;*)echo $"Usage: $0 {start|stop|reload|restart|configtest}"RETVAL=1esacexit $RETVAL
After saving, change the/etc/init. d/nginx permission.
Chmod 755/etc/init. d/nginx
Chkconfig -- add nginx
Chkconfig nginx on
3. nginxConfiguration
Vim/usr/local/nginx/conf/nginx. conf
Clear the original file and paste the following content:
user www www;worker_processes 2;error_log /usr/local/nginx/logs/nginx_error.log crit;pid /usr/local/nginx/var/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.worker_rlimit_nofile 51200;events{use epoll;worker_connections 6000;}http{include mime.types;default_type application/octet-stream;server_names_hash_bucket_size 2048;server_names_hash_max_size 4096;log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local] ''$host "$request_uri" $status ''"$http_referer" "$http_user_agent"';sendfile on;tcp_nopush on;keepalive_timeout 30;client_header_timeout 3m;client_body_timeout 3m;send_timeout 3m;connection_pool_size 256;client_header_buffer_size 1k;large_client_header_buffers 8 4k;request_pool_size 4k;output_buffers 4 32k;postpone_output 1460;client_max_body_size 10m;client_body_buffer_size 256k;client_body_temp_path /usr/local/nginx/client_body_temp;proxy_temp_path /usr/local/nginx/proxy_temp;fastcgi_temp_path /usr/local/nginx/fastcgi_temp;fastcgi_intercept_errors on;tcp_nodelay on;gzip on;gzip_min_length 1k;gzip_buffers 4 8k;gzip_comp_level 5;gzip_http_version 1.1;gzip_types text/plain application/x-javascript text/css text/htm application/xml;server{listen 80;server_name www.example.com;index index.html index.htm index.php;root /data/www;location ~ \.php$ {include fastcgi_params;fastcgi_pass unix:/ php-fcgi.sock;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;}}
You can start nginx after saving it. It is best to check whether any problem exists before restarting.
/Usr/local/nginx/sbin/nginx-t if "syntax is OK and nginx are displayed. conf was tested successfully "indicates that the configuration is correct. Otherwise, you must modify the configuration as prompted.
Service nginx start
If it cannot be started, go to the/usr/local/nginx/logs/directory to view the nginx_error.log log file. If you do not have this log file, it is likely that the directory does not have the write permission. Please execute
Chmod + w/usr/local/nginx/logs/
Service nginx restart
【
Test Parsing
Php
File]
Vim/data/www/1.php
Write the following content:
Phpinfo ();
?>
Then set the hosts file and access www.92csz.com/1.php to see if this page can be parsed.