您好,登錄后才能下訂單哦!
源碼安裝配置LNMP
更新時間:2016-08-02
系統(tǒng)環(huán)境:CentOS 6.5
軟件環(huán)境:nginx 1.8.1、mysql 5.6.22、php 5.6.19
本機IP :192.168.1.88、192.168.1.36
關(guān)閉防火墻和安全機制
#service iptables stop
#setenforce 0
#getenforce
【nginx】
1. 創(chuàng)建用戶
#groupadd nginx
#useradd -M -s /sbin/nologin nginx -g nginx
2. 編譯安裝
#yum -y install pcre-devel zlib-devel gcc 3. 創(chuàng)建軟連接
# tar zvxf nginx-1.8.1.tar.gz -C /usr/src/
# cd /usr/src/nginx-1.8.1/
# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_flv_module --with-http_gzip_static_module
#make && make install
#ln -s /usr/local/nginx/sbin/* /usr/local/sbin/ 4.檢查配置文件
# nginx -t 5. 啟動nginx服務
#nginx
#netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 17295/nginx
瀏覽器訪問本機IP
nginx配置優(yōu)化
worker_processes auto //nginx要開啟的進程數(shù),一般等于cpu的總核數(shù) (設置為“auto”將嘗試自動檢測它)
worker_rlimit_nofile 102400 //這個指令是指當一個nginx進程打開的最多文件描述符數(shù)目,理論值應該是最多打開文件數(shù)(ulimit -n)與nginx進程數(shù)相除,但是nginx分配請求并不是那么均勻,所以最好與ulimit -n的值保持一致。
worker_connections 5000 //每個進程允許的最多連接數(shù),理論上每臺nginx服務器的最大連接數(shù)為worker_processes*worker_connections。
keepalive_timeout 60 //keepalive超時時間
access_log /var/log/nginx/access.log //設置nginx是否將存儲訪問日志
error_log /var/log/nginx/error.log //告訴nginx只能記錄嚴重的錯誤
【mysql】
1.創(chuàng)建用戶
2.編譯安裝
#useradd mysql
# yum -y install ncurses ncurses-devel gcc libtool gcc-c++ make cmake
#tar zvxf mysql-5.6.22.tar.gz -C /usr/src #cd /usr/src/mysql-5.6.22/
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DMYSQL_USER=mysql
#make && make install
3. 更改屬主屬組
#chown -R mysql:mysql /usr/local/mysql/ 初始化:
#/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 拷貝文件:
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
添加啟動mysqld服務:
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# service mysqld start
Starting MySQL.. [確定]
軟連接:
[root@localhost ~]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
4. 設置mysql密碼
修改密碼報錯:
#mysqladmin -uroot password 'newpass' 進數(shù)據(jù)庫更改密碼:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
1.service mysqld stop
2. mysqld_safe --skip-grant-tables &
3. mysql -uroot -p 回車進入
>use mysql;
> update user set password=PASSWORD("newpass")where user="root";
> flush privileges; 更新權(quán)限
> quit 退出4.service mysqld restart
5. mysql -uroot -pnewpass 進入
【PHP】
1. 編譯安裝
# yum -y install openssl openssl-devel libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel libmcrypt-devel 報錯:
# tar zvxf php-5.6.19.tar.gz -C /usr/src
# cd /usr/src/php-5.6.19/
# ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5 --enable-fpm --with-fpm-user=php --with-fpm-group=php --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache
繼續(xù)編譯安裝:
1. configure: error: mcrypt.h not found. Please reinstall libmcrypt.
#tar zvxf libmcrypt-2.5.7.tar.gz -C /usr/src/
#cd /usr/src/libmcrypt-2.5.7/
#./configure --prefix=/usr/local/libmcrypt && make && make install
2. configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
#vim /etc/ld.so.conf.d/local.conf
/usr/local/lib
#
添加該行
# ldconfig
//
使之生效
# make && make install
2. 配置php-fpm模塊
[root@localhost php-5.6.19]# cp php.ini-development /usr/local/php5/php.ini [root@localhost ~]# cd /usr/local/php5/etc/
[root@localhost etc]# ls
pear.conf php-fpm.conf.default
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# useradd -M -s /sbin/nologin php
編輯配置文件
# vim php-fpm.conf
25 pid = run/php-fpm.pid
131 user = php
132 group =php
236 pm.max_children = 50
241 pm.start_servers = 20
246 pm.min_spare_servers = 5
251 pm.max_spare_servers = 35
啟動php-fpm
[root@localhost etc]# /usr/local/php5/sbin/php-fpm [root@localhost etc]# netstat -anpt | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 45716/php-fpm
3.將php-fpm模塊加入nginx配置文件
#vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.baidu.com;
charset utf-8;
access_log logs/host.access.log main;
location / {
root html/baidu;
index index.html index.htm index.php;
}
location ~ \.php$ {
root html/baidu;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
重啟nginx
[root@localhost etc]# killall nginx
[root@localhost etc]# netstat -anpt | grep nginx
[root@localhost etc]# nginx
[root@localhost etc]# netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 45787/nginx
4. 測試
域名映射
# vim /etc/hosts
192.168.1.36 www.baidu.com
創(chuàng)建網(wǎng)頁目錄
測試
#mkdir /usr/local/nginx/html/baidu
# echo Baidu > /usr/local/nginx/html/baidu/index.html
# elinks --dump 192.168.1.36
Baidu
測試nginx和PHP連通性
[root@localhost baidu]# pwd
/usr/local/nginx/html/baidu
[root@localhost baidu]# cat 2.php
<?php
phpinfo();
?>
測試數(shù)據(jù)庫和PHP連通性
#vim /usr/local/nginx/html/baidu/test.php <?php
$link=mysql_connect('localhost','root','123456'); //連接mysql數(shù)據(jù)庫
if($link) echo "<h2>恭喜你,大功告成!!</h2>"; //連接成功則返回信息
mysql_close(); //關(guān)閉數(shù)據(jù)庫連接
?>
[root@localhost html]# elinks --dump192.168.1.36/test.php
恭喜你,大功告成??!
在網(wǎng)上查詢的,未實驗過。
mysql_connect這個模塊將在未來棄用,請你使用mysqli或者PDO來替代。 解決方法1:
禁止PHP報錯
display_errors = On
改為
display_errors = Off
鑒于這個服務器都是給用戶用的,有時候他們需要報錯,不能這做,讓他們改程序吧,看方案2.
解決方法2:
常用的php語法連接MySQL如下
<?php
$link
= mysql_connect('localhost', 'user', 'password');
mysql_select_db('dbname', $link);
改成mysqi
<?php
$link
= mysqli_connect('localhost', 'user', 'password', 'dbname');
常用mysql建表SQL如下
<?php
//
老的
mysql_query('CREATE TEMPORARY TABLE `table`', $link);
//
新的
mysqli_query($link, 'CREATE TEMPORARY TABLE `table`');
解決方法三:
在php程序代碼里面設置報警級別
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
有不對請指出,多多指教。qq:2632886623
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。