LNMP就是Linux nginx mysql phpjavascript
1、mysqlphp
下載安裝mysql轉至 LAMP (點擊「LAMP」便可跳轉)css
也能夠從快照跳轉至mysql安裝okhtml
2、phpjava
下載同上,node
1.安裝mysql
cd /usr/local/src/
tar zxvf php-5.6.9.tar.gz
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd--with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --enable-zend-multibyte --disable-ipv6 --with-pear --with-curl --with-openssl
把lamp的錯誤解決方法yum安裝完以後,新的錯誤解決方法linux
錯誤1nginx
configure: error: no acceptable C compiler found in $PATH 配置:錯誤:不接受C編譯器中發現路徑
解決
yum install gcc -y
錯誤2web
configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/ 配置:錯誤:請從新安裝libcurl分佈- 一件容易的事。在< curl-dir > / h應該包括/卷/ 解決 yum -y install curl-devel
echo $?
make
echo $?
make install
echo $?
make install 以前,若是已經安裝過在php,一樣指定的目錄位/usr/local/php,能夠把原來的刪掉,or,挪個位置。
2.配置文件,啓動腳本
cp php.ini-production /usr/local/php/etc/php.ini
配置文件
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
啓動腳本
chmod 755 !$
執行權限
chkconfig --add php-fpm chkconfig php-fpm on
開機啓動
cd /usr/local/php/etc/ mv php-fpm.conf.default php-fpm.conf
配置文件
useradd -s /sbin/nologin -M php-fpm
用戶,編譯的時候指定的user group
service php-fpm start
啓動
拍攝快照:備註LNMP php安裝ok
php安裝成功
3、nginx
1.下載
cd /usr/local/src/
wget http://mirrors.sohu.com/nginx/nginx-1.9.8.tar.gz
2.安裝
tar zxvf nginx-1.9.8.tar.gz
./configure --prefix=/usr/local/nginx --with-pcre
pcre 正則
錯誤1
./configure: error: the HTTP rewrite module requires the PCRE library. 。/配置:錯誤:HTTP重寫模塊須要PCRE庫。 解決 yum -y install pcre-devel
echo $? make echo $? make install echo $?
3.啓動
/usr/local/nginx/sbin/nginx
shell腳本安裝
vim nginx_install.sh
#! /bin/bash cd /usr/local/src/ yum install wget -y wget http://mirrors.sohu.com/nginx/nginx-1.9.8.tar.gz tar zxvf nginx-1.9.8.tar.gz yum -y install pcre-devel yum install -y zlib-devel yum -y install gcc cd nginx-1.9.8 ./configure --prefix=/usr/local/nginx --with-pcre make && make install
nginx安裝ok
4、關聯php和nginx
php和nginx不能聯繫到一塊兒,須要手動修改配置文件。
1.nginx
vim /usr/local/nginx/conf/nginx.conf
找到 #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; #} 改成
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
2.防火牆
vim /etc/selinux/config 找到 SELINUX=enforcing 改成 SELINUX=disabled
setenforce 0
iptables -F
service iptables save
詳細說明見 LAMP 4、php 8-9小節
3.瀏覽器訪問
192.168.1.116
Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required. For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com. Thank you for using nginx.
4.測試解析php
vim /usr/local/nginx/html/info.php
<?php
phpinfo();
?>
http://192.168.1.116/info.php
php解析ok
5、nginx啓動腳本
nginx啓動重啓很是不方便,手動寫一個nginx啓動腳本。
1.啓動腳本
vim /etc/init.d/nginx
#!/bin/bash # chkconfig: - 30 21 # description: http service. # Source Function Library . /etc/init.d/functions # Nginx Settings NGINX_SBIN="/usr/local/nginx/sbin/nginx" NGINX_CONF="/usr/local/nginx/conf/nginx.conf" NGINX_PID="/usr/local/nginx/logs/nginx.pid" RETVAL=0 prog="Nginx" start() { echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL } reload(){ echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL } restart(){ stop start } configtest(){ $NGINX_SBIN -c $NGINX_CONF -t return 0 } case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1 esac exit $RETVAL
chmod 755 !$
chkconfig --add nginx
chkconfig nginx on
2.配置文件
默認的配置文件不完美,手動寫一個,
全局的配置,刪掉原來的東西
vim /usr/local/nginx/conf/nginx.conf
user nobody nobody; worker_processes 2; error_log /usr/local/nginx/logs/nginx_error.log crit; pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 6000; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 3526; 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; include vhosts/*.conf; }
虛擬主機的配置
cd /usr/local/nginx/conf/
mkdir vhosts
cd vhosts/
server { listen 80 default_server; server_name localhost; index index.html index.htm index.php; root /tmp/1233; }
##無論主機訪問什麼域名都會走這個配置,限制訪問403
mkdir /tmp/1233
/usr/local/nginx/sbin/nginx -t
檢查配置文件
/etc/init.d/nginx reload
從新加載
curl -x127.0.0.1:80 www.qq.com 測試默認虛擬主機配置,寫什麼域名都是403
vim vhosts2.conf
server { listen 80; server_name 111.com; index index.html index.htm index.php; root /data/www; location ~ \.php$ { include fastcgi_params; # fastcgi_pass unix:/tmp/php-fcgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name; } }
server_name 111.com 指定域名
root /data/www root的目錄
fastcgi_pass 127.0.0.1:9000;兩種形式sockt和ip+端口。若是502,那就是由於這個socket文件的權限不能讓nginx用戶讀到,辦法是在php-fpm.conf配置文件中指定一下socket文件的權限: listen.mode=644
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name; 也要指定路徑
/usr/local/nginx/sbin/nginx -t
/etc/init.d/nginx reload