linux 安装nginx php mysql 配置文件在哪_linux下 php+nginx+mysql安装配置
我主要是用來安裝php,以及nginx和php的交互。
一 安裝插件
可以選擇YUM安裝或者源碼編譯安裝gccgcc-c++zlib
pcre
pcre-devel
libevent
libevent-devel
libxml2
libxml2-devel
libmcrypt
libmcrypt-devel
curl-devel
libpng-devel
libtool-ltdl-devel
gd-devel
openssl
openssl-devel
ncurses-devel
cmake
mysql-devel
二 安裝mysql
tar -zxvf mysql-5.5.25.tar.gz
將mysql包解壓 然后放入你想要mysql的安裝位置 如本例中的/usr/local/webserver/mysql cmake命令需要這個路徑cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql \-DMYSQL_DATADIR=/user/local/webserver/mysql/data \-DSYSCONFDIR=/etc \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_INNOBASE_STORAGE_ENGINE=1\-DWITH_ARCHIVE_STORAGE_ENGINE=1\-DWITH_BLACKHOLE_STORAGE_ENGINE=1\-DWITH_FEDERATED_STORAGE_ENGINE=1\-DWITH_PARTITION_STORAGE_ENGINE=1\-DWITH_PERFSCHEMA_STORAGE_ENGINE=1\-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \-DMYSQL_TCP_PORT=3306\-DWITH_DEBUG=0\-DENABLED_LOCAL_INFILE=1回車執行,執行完成后繼續執行make && makeinstall#設置Mysql
#在support-files目錄中有五個配置信息文件(這里很重要,一定要根據自己的內存復制對應的cnf文件,否則mysql始終起不來):
#my-small.cnf (內存<=64M)
#my-medium.cnf (內存 128M)
#my-large.cnf (內存 512M)
#my-huge.cnf (內存 1G-2G)
#my-innodb-heavy-4G.cnf (內存 4GB)
cd/usr/local/webserver/mysqlcp ./support-files/my-huge.cnf /etc/my.cnf
vi/etc/my.cnf
#在 [mysqld] 段增加
datadir= /usr/local/webserver/mysql/datawait-timeout = 30max_connections= 512default-storage-engine =MyISAM
#在 [mysqld] 段修改
max_allowed_packet=16M//添加mysql運行的用戶和用戶組groupadd mysql
useradd-g mysql mysql -s /bin/false -d /home/mysql //沒有shell,不可本機登陸(安全起見)cd/usr/local/webserver/mysqlchown -R root .chown -R mysql datachgrp -R mysql .//生成新的mysql授權表//進入mysql安裝目錄下的腳本目錄 cd /usr/local/webserver/mysql/scripts//利用mysql_install_db腳本生成新的mysql授權表 ./mysql_install_db --basedir=/usr/local/webserver/mysql --datadir=/usr/local/webserver/mysql/data --user=mysql//mysql server在系統中的服務項設置//復制服務文件并修改 cd /usr/local/webserver/mysql/support-filescpmysql.server mysqld//修改mysqld basedir=/usr/local/webserver/mysql
datadir=/usr/local/webserver/mysql/datamv mysqld /etc/init.d/mysqldchmod755 /etc/init.d/mysqld
進行上述操作后 我們可以用 service mysqld start 來啟動mysql服務了//設置軟連接使mysql, mysqldump, mysqladmin這三個bin命令能在shell中直接運行sudoln -s /usr/local/webserver/mysql/bin/mysql /usr/binsudoln -s /usr/local/webserver/mysql/bin/mysqldump /usr/binsudoln -s /usr/local/webserver/mysql/bin/mysqladmin /usr/binrm -rf /etc/mysql/my.cnf 因為已經把此文件復制到/etc/my.cnf 如果不刪除的話,mysql啟動不起來。/etc/init.d/mysqld start//設置root密碼 mysqladmin -u root password "admin"//mysql數據庫中文亂碼解決 vi /etc/my.cnf//然后在[mysqld]配置選項下添加 character-set-server=utf8//然后進入mysql cd /usr/local/webserver/mysql/bin
mysql-u root -p
提示輸入密碼
mysql> show variables like '%character%';
三 安裝Nginx
#tar zxvf nginx-0.8.24.tar.gz
#cd nginx-0.8.24#./configure --prefix=/usr/local/nginx //此處在本環節只需指定一個路徑 #make && makeinstall#/usr/local/nginx/sbin/nginx //啟Nginx編寫服務腳本(服務腳本請勿復制 請在linux下寫入 不然回車換行符會引起異常)
vi/etc/init.d/nginx
把下列內容寫入文件并保存 #!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by gcec at 2009.10.22.
# it is v.0.0.1 version.
# if you find any errors on this scripts,please contact gcec cyz.
# and send mail to support at gcec dot cc.
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx #這里設置為你安裝nginx的執行文件位置
nginx_config=/usr/local/nginx/conf/nginx.conf #這里設置為你nginx的配置文件位置
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esacexit $RETVAL 保存之后 賦予文件權限
chmod 755 /etc/init.d/nginx
我們就可以通過service nginx start 來啟動服務了
四 安裝php
create user and group forfpm(fastcgi process manager)
groupadd fpm
useradd--shell /sbin/nologin -g fpm fpm
download, configure andinstall php5.3.3wget http://www.php.net/distributions/php-5.3.3.tar.gztar zxvf php-5.3.3.tar.gz
cd php-5.3.3
[直接復制]
./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=fpm --with-fpm-group=fpm --with-config-file-path=/usr/local/php/lib --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --without-pdo-sqlite --without-sqlite3 --without-sqlite --with-curl --enable-mbstring --with-mhash --with-mcrypt --with-openssl --with-gd --enable-sockets --with-gettext --with-zlib --enable-zip --enable-soap --with-xmlrpc --with-freetype-dir=/usr/local/freetype --enable-gd-native-ttf
--disable-fileinfo
中途錯誤需要yum install幾個依賴包[手敲版]
./configure --prefix=/usr/local/php \--enable-fpm \--with-fpm-user=fpm \--with-fpm-group=fpm \ --with-config-file-path=/usr/local/php/lib #這里是配置放php.ini的存放位置--with-mysql=mysqlnd \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--without-pdo-sqlite \--without-sqlite3 \--without-sqlite \--with-mysql-sock=/tmp/mysql.sock \--with-curl \--enable-mbstring \--with-mhash \--with-mcrypt \--with-openssl \--with-gd \--enable-sockets \--with-gettext \--with-zlib \--enable-zip\--enable-soap \--with-xmlrpc \
--with-freetype-dir=/usr/local/freetype \
--enable-gd-native-ttf \ --with-jpeg-dir=/usr/lib64 #64位系統lib64 32位系統lib32make && makeinstall
make出現錯誤virtual memory exhausted: Cannot allocate memory,在configure上加上–disable-fileinfo
如果出現mysql_config not found的錯誤
解決辦法: vi /etc/profile 在最后加入一行 export PATH="$PATH:/usr/local/mysql/bin" 這個是你的mysql安裝到的目錄
五 配置php
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
復制源碼包里的php.ini-development到/usr/local/php/lib vi php-fpm.conf
找到"listen=" 修改為 listen = /dev/shm/php-fpm.sock (要求php版本5.3以上 該方式為使用sock文件監聽)
cp /backup/php-5.3.3/php.ini-development /usr/local/php/lib/php.ini
啟動php
/usr/local/php/sbin/php-fpm 如果設置路徑正確,php.ini文件也存在,還無法加載php.ini的話 修改啟動命令 /usr/local/php/sbin/php-fpm -c /etc/php.ini編寫服務腳本(服務腳本請勿復制 請在linux下寫入 不然回車換行符會引起異常)
touch /etc/init.d/phpfpm
vim /etc/init.d/phpfpm
內容如下:
#!/bin/bash
start() {
/usr/local/php/sbin/php-fpm
/bin/echo 'starting php listener ---[ok]'
}
stop() {
/usr/bin/pkill php-fpm
/bin/echo 'stopping php listener ---[ok]'
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo 'usage:start/stop/restart'
exit 0
;;
esac
保存退出
然后 就能通過 service phpfpm start/stop/restart 來啟動監聽
六 配置Nginx
cat /usr/local/php/etc/php-fpm.conf
查看端口 為 127.0.0.1:9000
修改nginx配置文件 /usr/local/nginx/conf/nginx.conf# location / { //一定要注掉這部分,否則會不解析PHP文件,而會下載 了
# root html;
# index index.html index.htm;
#}
location~ \.php {
root www; #這是你網站的根目錄
fastcgi_pass 127.0.0.1:9000; #這里指定了fastcgi進程偵聽的端口,nginx就是通過這里與php交互的
#fastcgi_pass unix:/dev/shm/php-fpm.sock;
fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
#因為SCRIPT_FILENAME在配置中是寫死的并沒有隨著$doucument_root變化而變化,我們可以修改SCRIPT_FILENAME配置如下 #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;
} 重啟nginx服務
/usr/local/nginx/sbin/nginx -s reload
在/usr/local/nginx下創建www目錄
mkdir www
新建一個index.php文件
cd www
vim index.php
寫入
訪問服務器 如果起作用就說明配置成功
七 設置php nginx mysql 自啟動
我想在centos里不啟用圖形界面
那么選擇系統運行級別為2或者3的 推薦3在配置之前 我們先檢查下 /etc/init.d中有沒有我們mysql,php,nginx的服務腳本 如果沒有的話 先配置再做下列操作
如以上 mysqld , nginx, phpfpm 這3個腳本都編寫好 并且放入/etc/init.d下的話 我們來配置一下自啟動
我想通過一個服務來啟動這3個服務那么再寫一個腳本就可以了
注意:system類型的服務都可以用service來啟動,用chkconfig來add 和del
但是有些自己配置的服務在用chkconfig來配置到時候會提示: “service XX does not support chkconfig”
這一般都是script不符合格式造成的,解決如下,
在script開始加入兩行內容即可:
# chkconfig: - 85 15
# description: this is a World Wide Web server.
mv /etc/init.d/mysqld /etc/init.d/webapp-mysqldmv /etc/init.d/nginx /etc/init.d/webapp-nginxmv /etc/init.d/phpfpm /etc/init.d/webapp-phpfpmtouch /etc/init.d/webappvim /etc/init.d/webapp寫入以下腳本
#!/bin/bash
# chkconfig: - 85 15
# description: this is a World Wide Web server.
ACTION=$1
if [ "$ACTION" = "" ] || [ "$ACTION" = "start" ];then
#start php listeners
/sbin/service webapp-phpfpm start
#start nginx service
/sbin/service webapp-nginx start
#start mysql service
/sbin/service webapp-mysqld start
echo "web applications[mysql,nginx,php] is running now !"
elif [ "$ACTION" = "stop" ];then
/sbin/service webapp-phpfpm stop
/sbin/service webapp-nginx stop
/sbin/service webapp-mysqld stop
echo 'web application stopped'
else
echo "use start or stop or none after your service command"
fi
添加系統服務開機啟動
chkconfig --add webapp(注意在/etc/init.d下的服務腳本必須加入#chkconfig 和 #description的內容才能夠在這里支持chkconfig命令,以上已經提到過)
chkconfig --level 3 webapp on
這樣我們的lamp的架構就配置成功了
說明:
語法為:
chkconfig --list [name] 用來列表服務
chkconfig --add name 用來添加服務
chkconfig --del name 用來刪除服務
chkconfig [--level levels] name 改變啟動信息以及檢查特定服務的啟動狀態。
on 和 off 分別指服務在改變運行級時的啟動和停止。reset 指初始化服務信息。
對于 on 和 off 開關,系統默認只對運行級 3,4, 5有效,但是 reset 可以對所有運行級有效。
以上就介紹了linux下 php+nginx+mysql安裝配置,包括了mysql安裝方面的內容,希望對PHP教程有興趣的朋友有所幫助。
本文原創發布php中文網,轉載請注明出處,感謝您的尊重!
總結
以上是生活随笔為你收集整理的linux 安装nginx php mysql 配置文件在哪_linux下 php+nginx+mysql安装配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu18.04 安装 腾讯qq
- 下一篇: SAP RFC user 最小权限