Centos下搭建LNMP環境

2021-08-11 04:07:47 字數 3317 閱讀 5635

1.安裝nginx

關於nginx的安裝請參考

2.安裝二進位製包mysql

useradd mysql -m -s /sbin/nologin

tar zxvf mysql-5.5.32-linux2.6-x86_64.tar.gz

mv mysql-5.5.32-linux2.6-x86_64 /usr/local/

ln -s /usr/local/mysql-5.5.32 /usr/local/mysql

chown -r mysql.mysql mysql-5.5.32/

scripts/mysql_install_db --basedir=/usr/local/mysql-5.5.32/ \

--datadir=/usr/local/mysql-5.5.32/data --user=mysql

cp support-files/mysql.server /etc/init.d/mysqld

chmod u+x /etc/init.d/mysqld

chkconfig mysqld on

chkconfig --list mysqld

cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf

service mysqld start

3.原始碼安裝php

yum install zlib libxml2 libjpeg freetype libpng gd \

curl zlib-devel libxml2-devel libjpeg-devel freetype-devel \

libpng-devel gd-devel curl-devel libxslt libxslt-devel -y

tar zxvf libiconv-1.14.tar.gz

tar zxvf libmcrypt-2.5.8.tar.gz

tar zxvf mhash-0.9.9.9.tar.gz

tar zxvf mcrypt-2.6.8.tar.gz

#install libiconv

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv-1.14

make && make install

cd ../libmcrypt-2.5.8

./configure

make && make install

sleep 2

/sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install

make

make install

#install mhash

cd ../../mhash-0.9.9.9

./configure

make

make install

#install mcrypt

cd ../mcrypt-2.6.8

/sbin/ldconfig

./configure ld_library_path=/usr/local/lib

make

make install

#install php

tar zxf php-5.3.27.tar.gz

cd php-5.3.27

./configure --prefix=/usr/local/php-5.3.27 \

--with-mysql=/usr/local/mysql \

--with-iconv-dir=/usr/local/libiconv \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir=/usr \

--enable-xml \

--disable-rpath \

--enable-safe-mode \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--with-curl \

--enable-mbregex \

--enable-fpm \

--enable-mbstring \

--with-mcrypt \

--with-gd \

--enable-gd-native-ttf \

--with-openssl \

--with-mhash \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--enable-zip \

--enable-soap \

--enable-short-tags \

--enable-zend-multibyte \

--enable-static \

--with-xsl \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--with-libevent-dir \

--enable-ftp \

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/

make

make install

cp php.ini-production /usr/local/php-5.3.27/lib/php/php.ini

配置/usr/local/php-5.3.27/etc/php-fpm.conf配置檔案

/usr/local/php-5.3.27/sbin/php-fpm 啟動php-fpm

netstat -tlunp|grep php-fpm

4.配置服務開機自啟動

cat >> /etc/rc.local <5.nginx整合php

在nginx.conf中新增以下字段

location ~ .*\.(php|php5)?$

index 新增index.php

6.php測試連線mysql

<?php

$link_id=mysql_connect('localhost','root','haha123') or mysql_error();

if($link_id)else

?>

CentOS 環境下 搭建 LNMP環境

關掉防火牆,避免實驗中出現伺服器無法訪問的情況 chkconfig iptables off安裝lnmp環境所需的開發包和庫檔案 yum y install ntp make openssl openssl devel pcre pcre devel libpng libpng devel libj...

centos搭建LNMP環境

一 lnmp介紹 二 nginx安裝 5 通過chkconfig設定開機啟動 sudo chkconfig nginx on 4 檢視nginx版本 root izrj98p4hhys0y9fdxmcy4z yanmin nginx v nginx version nginx 1.12.1 三 my...

CentOS搭建LNMP環境

1 檢視環境 1 root localhost cat etc redhat release2 關掉防火牆 1 開機禁用 2 root localhost chkconfig iptables off 3 centos7 systemctl disable firewalld4or 56 即時生效,...