linux下 php+nginx+mysql安装配置
来源:互联网 发布:ios 沙盒存储数据 编辑:程序博客网 时间:2024/06/10 01:38
我主要是用来安装php,以及nginx和php的交互。原文:http://www.cnblogs.com/lost-1987/articles/2642979.html
一 安装插件
可以选择YUM安装或者源码编译安装gccgcc-c++zlibpcrepcre-devellibeventlibevent-devellibxml2 libxml2-devellibmcrypt libmcrypt-develcurl-devellibpng-devellibtool-ltdl-develgd-developenssl openssl-develncurses-develcmakemysql-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 && make install#设置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 mysqluseradd -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-filescp mysql.server mysqld//修改mysqldbasedir=/usr/local/webserver/mysqldatadir=/usr/local/webserver/mysql/datamv mysqld /etc/init.d/mysqldchmod 755 /etc/init.d/mysqld进行上述操作后 我们可以用 service mysqld start 来启动mysql服务了//设置软连接使mysql, mysqldump, mysqladmin这三个bin命令能在shell中直接运行sudo ln -s /usr/local/webserver/mysql/bin/mysql /usr/binsudo ln -s /usr/local/webserver/mysql/bin/mysqldump /usr/binsudo ln -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//然后进入mysqlcd /usr/local/webserver/mysql/binmysql -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 && make install#/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 esac exit $RETVAL保存之后 赋予文件权限chmod 755 /etc/init.d/nginx 我们就可以通过service nginx start 来启动服务了
四 安装php
create user and group for fpm(fastcgi process manager)groupadd fpmuseradd --shell /sbin/nologin -g fpm fpmdownload, configure and install php5.3.3wget http://www.php.net/distributions/php-5.3.3.tar.gztar zxvf php-5.3.3.tar.gzcd 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位系统lib32 make && make install 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/libvi 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/phpfpmvim /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 wwwvim index.php写入<?php echo phpinfo();?>访问服务器 如果起作用就说明配置成功
七 设置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的架构就配置成功了
说明:
- linux下nginx+mysql+php安装配置
- linux下 php+nginx+mysql安装配置
- Linux下安装配置nginx+php+mysql环境
- ubuntu下nginx+php+mysql安装配置
- ubuntu下nginx+php+mysql安装配置
- Linux下Nginx+PHP+MySQL配置(图)
- Linux下Nginx+PHP+MySQL配置
- linux nginx+apache+php+mysql 安装配置
- linux nginx+apache+php+mysql 安装配置
- Linux下Nginx+PHP+Mysql安装,Nginx配置文件支持PHP
- Linux下nginx,apache,memcached,php,mysql的安装和配置
- Linux下安装nginx, php, php-fpm并配置
- Linux下安装配置Nginx以及安装PHP
- Linux下Apache+mysql+php安装配置
- CentOS5下安装配置nginx+fastcgi php+mysql
- ubuntu下nginx+php+mysql+memcached+mango的安装配置
- ubuntu下nginx+Mysql+php的安装和配置
- ubuntu下nginx+Mysql+php的安装和配置
- 数独算法
- Ubuntu12.04 修改ip、mac和dns
- 1002_写出这个数 (20)
- 【数值分析】复化积分公式
- three.js 源码注释(七十四)extras/geometries/ExtrudeGeometry.js
- linux下 php+nginx+mysql安装配置
- Parsing Data for android-21 failed Unsupported major.minor version 51.0问题
- CSS+DIV总结
- 基于JAVA Socket的简单实时通信
- Frozen UI中提取的半像素边框
- gdb 远程调试android进程
- Android—改变LinearLayout背景颜色
- "忘记密码"功能过程及其实现细节
- Cocos2d-x游戏开发——屏幕触摸事件