linux下nginx+php+mysql環境搭建
++++++++++++++++++++++++++++++++++++++++++++++
linux下nginx+php+mysql環境搭建
++++++++++++++++++++++++++++++++++++++++++++++
作業系統 : [CentOS6.0]
伺服器 : [nginx-1.1.8]
PHP : [php-5.2.6]
資料庫 : [mysql-5.1.59]
++++++++++++++++++++++++++++++++++++++++++++++
準備安裝軟體(download)
1>[nginx-1.1.8]
http://nginx.org/download/nginx-1.1.8.tar.gz
2>[php-5.2.6]
http://museum.php.net/php5/php-5.2.6.tar.gz
3>[php-5.2.6-fpm-0.5.8.diff.gz]
http://php-fpm.org/downloads/php-5.2.6-fpm-0.5.8.diff.gz
4>[mysql-5.1.59]
http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.59.tar.gz
5>[libxml2-2.6.30]
http://download.chinaunix.net/down.php?id=28491&ResourceID=6095&site=1
6>[libmcrypt-2.5.8]
http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
7>[zlib-1.2.3]
http://sourceforge.net/projects/libpng/files/zlib/1.2.3/zlib-1.2.3.tar.gz/download
8>[libpng-1.2.31]
http://files.directadmin.com/services/custombuild/libpng-1.2.31.tar.gz
9>[jpegsrc.v6b]
http://download.chinaunix.net/down.php?id=10021&ResourceID=5095&site=1
10>[freetype-2.3.5]
http://nongnu.askapache.com/freetype/freetype-2.3.5.tar.gz
11>[autoconf-2.61]
http://ftp.gnu.org/gnu/autoconf/autoconf-2.61.tar.gz
12>[gd-2.0.35]
http://code.google.com/p/google-desktop-for-linux-mirror/downloads/detail?name=gd-2.0.35.tar.gz&can=2&q=
13>[ncurses-5.6]
http://ftp.gnu.org/gnu/ncurses/ncurses-5.6.tar.gz
14>[pcre-8.10]
http://sourceforge.net/projects/pcre/files/pcre/8.10/pcre-8.10.tar.gz/download
15>[openssl-1.0.0e]
http://www.openssl.org/source/openssl-1.0.0e.tar.gz
+++++++++++++++++++++++++++++++++++++++++++++
1>【安裝gcc, gcc-c++】
[html] view plaincopy
-
yum install gcc
-
yum install gcc-c++
2>【開放80、3306、22埠】
[html] view plaincopy
-
#關閉防火牆
-
service iptables stop
-
vi /etc/sysconfig/iptables
-
#新增
-
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-
#重啟防火牆
-
service iptables restart
3>【建立lamp/src目錄, 將原始碼包上傳】
4>【安裝libxml2】
[html] view plaincopy
-
tar -zxvf libxml2-2.6.30.tar.gz
-
cd libxml2-2.6.30
-
./configure –prefix=/usr/local/libxml2/
-
make
-
make install
5>【安裝libmcrypt】
[html] view plaincopy
-
tar -zxvf libmcrypt-2.5.8.tar.gz
-
cd libmcrypt-2.5.8
-
./configure –prefix=/usr/local/libmcrypt/ –enable-ltdl-install
-
make
-
make install
6>【安裝libxml2-devel】
[html] view plaincopy
-
yum install libxml2-devel
7>【安裝zlib】
[html] view plaincopy
-
tar -zxvf zlib-1.2.3.tar.gz
-
cd zlib-1.2.3
-
./configure
-
make
-
make install
8>【安裝libpng】
[html] view plaincopy
-
tar -zxvf libpng-1.2.31.tar.gz
-
cd libpng-1.2.31
-
./configure –prefix=/usr/local/libpng/
-
make
-
make install
9>【安裝jpegsrc.v6b】
[html] view plaincopy
-
mkdir /usr/local/jpeg6
-
mkdir /usr/local/jpeg6/bin
-
mkdir /usr/local/jpeg6/lib
-
mkdir /usr/local/jpeg6/include
-
mkdir -p /usr/local/jpeg6/man/man1
-
-
tar -zxvf jpegsrc.v6b.tar.gz
-
cd jpeg-6b
-
./configure –prefix=/usr/local/jpeg6/ –enable-shared –enable-static
-
make
-
make install
10>【安裝freetype】
[html] view plaincopy
-
tar -zxvf freetype-2.3.5.tar.gz
-
cd freetype-2.3.5
-
./configure –prefix=/usr/local/freetype/
-
make
-
make install
11>【安裝autoconf】
[html] view plaincopy
-
tar -zxvf autoconf-2.61.tar.gz
-
cd autoconf-2.61
-
./configure
-
make
-
make install
12>【安裝gd】
[html] view plaincopy
-
tar -zxvf gd-2.0.35.tar.gz
-
cd gd-2.0.35
-
./configure –prefix=/usr/local/gd2/ –with-jpeg=/usr/local/jpeg6/ –with-freetype=/usr/local/freetype/
-
make
-
make install
13>【pcre-8.10】
[html] view plaincopy
-
tar -zxvf pcre-8.10.tar.gz
-
cd pcre-8.10
-
./configure
-
make
-
make install
14>【安裝openssl】
[html] view plaincopy
-
tar -zxvf openssl-1.0.0e.tar.gz
-
cd openssl-1.0.0e
-
./config –prefix=/usr/local/openssl
-
make
-
make install
15>【安裝nginx】
[html] view plaincopy
-
groupadd www
-
useradd -g www www
-
tar -zxvf nginx-1.1.8.tar.gz
-
cd nginx-1.1.8
-
./configure –user=www –group=www –prefix=/usr/local/nginx –with-openssl=/lamp/src/openssl-1.0.0e –with-http_stub_status_module –with-http_ssl_module
-
make
-
make install
16>【安裝ncurses】
[html] view plaincopy
-
tar -zxvf ncurses-5.6.tar.gz
-
cd ncurses-5.6
-
./configure –with-shared –without-debug –without-ada –enable-overwrite
-
make
-
make install
17>【安裝mysql】
[html] view plaincopy
-
groupadd mysql
-
useradd -g mysql mysql
-
tar -zxvf mysql-5.1.59.tar.gz
-
cd mysql-5.1.59
-
./configure –prefix=/usr/local/mysql/ –with-extra-charsets=all
-
make
-
make install
-
-
cp support-files/my-medium.cnf /etc/my.cnf
-
/usr/local/mysql/bin/mysql_install_db –user=mysql
-
chown -R root /usr/local/mysql
-
chown -R mysql /usr/local/mysql/var
-
chgrp -R mysql /usr/local/mysql
-
-
/usr/local/mysql/bin/mysqld_safe –user=mysql &
-
cp /lamp/src/mysql-5.1.59/support-files/mysql.server /etc/rc.d/init.d/mysqld
-
chown root.root /etc/rc.d/init.d/mysqld
-
chmod 755 /etc/rc.d/init.d/mysqld
-
chkconfig –add mysqld
-
chkconfig –list mysqld
-
chkconfig –levels 245 mysqld off
-
-
#配置mysql
-
cd /usr/local/mysql
-
#簡單的測試
-
bin/mysqladmin version
-
#檢視所有mysql引數
-
bin/mysqladmin Variables
-
#沒有密碼可以直接登入本機伺服器
-
bin/mysql -uroot
-
DELETE FROM mysql.user WHERE Host=`localhost` AND User=“;
-
FLUSH PRIVILEGES;
-
#設定root密碼為123456
-
SET PASSWORD FOR `root`@`localhost` = PASSWORD(`123456`);
-
#配置可遠端連線mysql
-
use mysql
-
SELECT user,password,host FROM user;
-
DELETE FROM user WHERE host=`localhsot.localdomain`
-
DELETE FROM user WHERE host=`127.0.0.1`;
-
UPDATE user SET host=`%` WHERE user=`root`;
-
#重啟mysql
-
service mysqld restart
18>【安裝php】
[html] view plaincopy
-
tar -zxvf php-5.2.6.tar.gz
-
gzip -cd php-5.2.6-fpm-0.5.8.diff.gz | patch -d php-5.2.6 -p1
-
-
cd php-5.2.6
-
./configure –prefix=/usr/local/php/ –with-config-file-path=/usr/local/php/etc/ –with-mysql=/usr/local/mysql/ –with-libxml-dir=/usr/local/libxml2/ –with-jpeg-dir=/usr/local/jpeg6/ –with-freetype-dir=/usr/local/freetype/ –with-gd=/usr/local/gd2/ –with-mcrypt=/usr/local/libmcrypt/ –with-mysqli=/usr/local/mysql/bin/mysql_config –enable-soap –enable-mbstring=all –enable-sockets –enable-fastcgi –enable-fpm
-
make
-
make install
-
cp php.ini-dist /usr/local/php/etc/php.ini
-
#修改php-fpm.conf
-
vi /usr/local/php/etc/php-fpm.conf
-
#查詢63,66行將註釋去掉
-
<value name=“user”>nobody</value>
-
<value name=“group”>nobody</value>
-
#啟動php
-
/usr/local/php/sbin/php-fpm start
19>【nginx配置】
[html] view plaincopy
-
vi /usr/local/nginx/conf/nginx.conf
-
#在server下找到location / 修改解析PHP檔案存放的路徑, 修改為:
-
location / {
-
root /var/www/html;
-
index index.html index.htm index.php;
-
}
-
#root表示虛擬目錄設定為/var/www/html,增加預設解析index.php
-
#在server下找到location ~ /.php$ 修改php直譯器FastCGI配置,修改為:
-
location ~ .php$ {
-
root /var/www/html;
-
fastcgi_pass 127.0.0.1:9000;
-
fastcgi_index index.php;
-
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
-
include fastcgi_params;
-
}
-
#將nginx新增到自啟動中
-
echo “/usr/local/nginx/sbin/nginx” >> /etc/rc.d/rc.local
-
#將php新增到自啟動中
-
echo “/usr/local/php/sbin/php-fpm start” >> /etc/rc.d/rc.local
20>【nginx虛擬主機配置】
vi /usr/local/nginx/conf/nginx.conf
#在http最後一行加入
include /usr/local/nginx/conf/vhost/dev_localhost.config;
#不帶url重寫
[html] view plaincopy
-
server {
-
listen 80 default;
-
server_name dev.localhost;
-
access_log logs/dev.access.log;
-
-
-
root /var/www/html/dev;
-
-
-
server_name_in_redirect off;
-
-
-
location / {
-
index index.html index.php;
-
}
-
-
-
location ~ .php$ {
-
fastcgi_pass 127.0.0.1:9000;
-
fastcgi_index index.php;
-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
-
include fastcgi_params;
-
}
-
}
#帶url重寫(zend framework)
[html] view plaincopy
-
server {
-
listen 80;
-
server_name dev.localhost;
-
access_log logs/dev.access.log;
-
-
root /var/www/html/dev/code/html;
-
location / {
-
index index.html index.php;
-
-
-
if (-e $request_filename ) {
-
break;
-
}
-
-
if ( $request_filename ~* .(js|ico|gif|jpg|jpeg|xml|swf|txt|png|css|html|htm)$ ) {
-
return 404;
-
}
-
-
rewrite .* index.php;
-
}
-
location ~ .*.php$ {
-
include fastcgi_params;
-
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
-
#fastcgi_param REQUEST_URI $document_uri?$query_string;
-
fastcgi_read_timeout 120;
-
fastcgi_pass 127.0.0.1:9000;
-
fastcgi_index index.php;
-
}
-
}
[html] view plaincopy
-
#重啟nginx
-
/usr/local/nginx/sbin/nginx -s reload
-
#重啟php
-
/usr/local/php/sbin/php-fpm restart
相關文章
- mac下搭建nginx+php+mysqlMacNginxPHPMySql
- linux下搭建wails開發環境。LinuxAI開發環境
- Linux伺服器下Java環境搭建Linux伺服器Java
- Linux搭建Java環境LinuxJava
- Linux 下 Go 環境搭建以及 Gin 安裝LinuxGo
- Linux下搭建Go語言開發環境LinuxGo開發環境
- Linux下環境搭建(二)——jenkins+gitlab配置LinuxJenkinsGitlab
- linux(統信)下搭建electron開發環境Linux開發環境
- Linux下搭建FFmpeg開發除錯環境Linux除錯
- Windows環境下的Nginx環境搭建WindowsNginx
- window環境下testlink環境搭建(xammp)
- Linux下信用盤SGWIN程式搭建PHP+Nginx環境搭建LinuxPHPNginx
- Linux(二十)搭建JavaEE環境LinuxJava
- Linux學習環境搭建Linux
- Linux系統環境搭建Linux
- Linux搭建開發環境Linux開發環境
- Linux 環境下搭建Hadoop叢集(全分佈)LinuxHadoop
- 以太坊-Win環境下remix環境搭建REM
- (一)Linux環境的學習環境的搭建Linux
- Windows 下搭建 lnmp 環境WindowsLNMP
- Centos下搭建golang環境CentOSGolang
- docker下LNMP環境搭建DockerLNMP
- mac 下搭建flutter環境MacFlutter
- windows下搭建lisp環境WindowsLisp
- Python 開發環境搭建(03):Linux 下 eclipse 安裝Python開發環境LinuxEclipse
- linux環境下vscode 中C/C++編譯及除錯環境的搭建LinuxVSCodeC++編譯除錯
- Kali Linux的Pwn環境搭建Linux
- linux開發環境搭建(ubuntu)Linux開發環境Ubuntu
- ubuntu環境下搭建以太坊開發環境Ubuntu開發環境
- Linux 環境下 PHP 專案基礎執行環境搭建(PHP 7.3.6 + MySQL 8.0.16 + Nginx)LinuxPHPMySqlNginx
- Windows下搭建ESP-IDF環境搭建Windows
- linux下使用vscode和makefile搭建C++開發環境LinuxVSCodeC++開發環境
- linux下配置java環境LinuxJava
- MAC環境下PHP開發除錯環境搭建MacPHP除錯
- Ubuntu下Java環境的搭建UbuntuJava
- 快速搭建 Linux(LNMP + Linux 安裝 + 環境配置)LinuxLNMP
- Linux/Go環境搭建, HelloWorld執行LinuxGo
- Linux搭建PHP+MySQL+Apache環境LinuxPHPMySqlApache
- Linux下-LNMP環境搭建部落格網站(全過程)LinuxLNMP網站