centos搭建LNMP

转载者语:

转载于:http://www.osyunwei.com/archives/2353.html

原文标题:CentOS 6.2yum安装配置lnmp服务器(Nginx+PHP+MySQL)

本人以CentOS6.5亲测成功.

以下是原文.

————————————————————————————————————————————

准备篇:

yum install make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd  kernel keyutils  patch  perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch freetype-devel

1、配置防火墙,开启80端口、3306端口
vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许80端口通过防火墙)
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT(允许3306端口通过防火墙)
特别提示:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的22端口这条规则的下面
添加好之后防火墙规则如下所示:

继续阅读“centos搭建LNMP”

centos7编译安装php时: error: mcrypt.h not found. Please reinstall libmcrypt

这种情况一般是没有安装 libmcrypt-devel

centos7默认yum源没有libmcrypt-devel这个包,所以只能借助第三方源或者编译安装,这里用的是第三方源

下载并安装EPEL

# wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -ivh epel-release-latest-7.noarch.rpm
# yum repolist ##检查是否已添加至源列表

安装好第三方yum源后,

yum install libmcrypt-devel

在centos7上搭建Apache+mariadb+php7

  • 安装mariadb

# yum install mariadb-server mariadb

啟動及設定開機自動執行 MariaDB:

# systemctl start mariadb
# systemctl enable mariadb

安装Apache

# yum install httpd

跟著回答 “y” 後便會完成安裝, 然後輸入以下指令啟動及設定 Apache 開機自動執行:

# systemctl start httpd
# systemctl enable httpd

安裝 PHP 7

下载php7包到/usr/local/src/ 目录并解压

安装扩展包

# yum install gcc libxml2-devel pkgconfig openssl-devel bzip2-devel libpng-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel httpd-devel

进入php7解压包

# ./configure \
–prefix=/usr/local/php7/usr \
–with-config-file-path=/usr/local/php7/usr/etc \
–enable-mbstring \
–enable-zip \
–enable-bcmath \
–enable-pcntl \
–enable-ftp \
–enable-exif \
–enable-calendar \
–enable-sysvmsg \
–enable-sysvsem \
–enable-sysvshm \
–enable-wddx \
–with-curl \
–with-mcrypt \
–with-iconv \
–with-gmp \
–with-pspell \
–with-gd \
–with-jpeg-dir=/usr \
–with-png-dir=/usr \
–with-zlib-dir=/usr \
–with-xpm-dir=/usr \
–with-freetype-dir=/usr \
–enable-gd-native-ttf \
–enable-gd-jis-conv \
–with-openssl \
–with-pdo-mysql=/usr \
–with-gettext=/usr \
–with-zlib=/usr \
–with-bz2=/usr \
–with-recode=/usr \
–with-mysqli=/usr/bin/mysql_config \
–with-apxs2

然后

#make

#make test

#make install

复制 php.ini-development 文件到 /usr/local/lib 保存为 php.ini

编辑Apache配置文件 /etc/httpd/conf/httpd.conf  加入以下内容

LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

保存后重启Apache