下文給大家?guī)碛嘘P(guān)LAMP環(huán)境如何搭建安裝(centos6.9+apache2.4+MySQL5.7+php7.1)內(nèi)容,相信大家一定看過類似的文章。我們給大家?guī)淼挠泻尾煌??一起來看看正文部分吧,相信看完LAMP環(huán)境如何搭建安裝(centos6.9+apache2.4+mysql5.7+php7.1)你一定會有所收獲。
目前創(chuàng)新互聯(lián)建站已為成百上千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站改版維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、宿城網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
安裝前準(zhǔn)備
(本文永久地址:http://woymk.blog.51cto.com/10000269/1914539)
CentOS 6.9 64位 最小化安裝
yum install -y make gcc gcc-c++ perl zlib-devel libaio libpng libpng-devel libjpeg-devel pcre-devel
yum install -y libXpm-devel openssl openssl-devel libxml2-devel bzip2-devel.x86_64 libjpeg-turbo-devel
yum install -y freetype freetype-devel libtool cmake ncurses-devel bison re2c curl-devel wget
rpm -ivh "http://mirrors.sohu.com/fedora-epel/epel-release-latest-6.noarch.rpm"
yum install -y libmcrypt-devel re2c
一、安裝MySql
1.編譯安裝
下載軟件包
cd /usr/local/src/
wget http://mirrors.sohu.com/mysql/MySQL-5.7/http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.17.tar.gz
解壓
tar zxvf mysql-boost-5.7.17.tar.gz
編譯&安裝
cd mysql-5.7.17
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_BOOST=./boost/boost_1_59_0/
make && make install
注意:如果編譯出錯,執(zhí)行如下操作,然后重新配置。
make clean
rm CMakeCache.txt
2.二進(jìn)制包安裝
若編譯過程較慢,可以下載編譯好的二進(jìn)制包直接安裝
cd /usr/local/src/
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
tar zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
移至/usr/local/mysql目錄
mv mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql
3.建立mysql用戶
useradd -s /sbin/nologin mysql
初始化數(shù)據(jù)庫,創(chuàng)建系統(tǒng)自帶的數(shù)據(jù)庫和表
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
cd /usr/local/mysql
bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql
(5.7初始化方式已經(jīng)變更,直接使用mysqld命令初始化,5.6之前版本初始化執(zhí)行下面這句:
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql)
結(jié)束后會生成一個密碼,記下來
初始化時會出現(xiàn)如下警告:
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated.
Please use --explicit_defaults_for_timestamp server option (see
documentation for more details).
要想取消該警告,在啟動mysql時,my.cnf中加入
[mysqld]
explicit_defaults_for_timestamp=true
添加服務(wù),拷貝服務(wù)腳本到init.d目錄,并設(shè)置開機(jī)啟動
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
vi /etc/init.d/mysqld
修改datadir
basedir=/usr/local/mysql
datadir=/data/mysql
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
修改密碼
/usr/local/mysql/bin/mysqladmin -uroot -p'剛才記下的密碼' password "新密碼"
5.6之前版本修改密碼執(zhí)行下面這句:
/usr/local/mysql/bin/mysqladmin -uroot password "新密碼"
二、安裝apache2.4
下載源碼:
cd /usr/local/src
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.25.tar.gz
wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz
wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
tar zxvf /usr/local/src/httpd-2.4.25.tar.gz
tar zxvf /usr/local/src/apr-1.5.2.tar.gz
tar zxvf /usr/local/src/apr-util-1.5.4.tar.gz
mv /usr/local/src/apr-1.5.2 /usr/local/src/httpd-2.4.25/srclib/apr
mv /usr/local/src/apr-util-1.5.4 /usr/local/src/httpd-2.4.25/srclib/apr-util
cd /usr/local/src/httpd-2.4.25
./configure \--prefix=/usr/local/apache2 \--with-included-apr \--enable-so \--enable-deflate=shared \--enable-expires=shared \--enable-rewrite=shared
make && make install
cd /usr/local/apache2/
vi conf/httpd.conf
找到
#ServerName www.example.com:80
改成
ServerName localhost:80
檢查配置文件語法
bin/apachectl -t
配置啟動腳本
cp /usr/local/src/httpd-2.4.25/build/rpm/httpd.init /etc/init.d/httpd
注意文件中有三處主要的地方需要修改下的:
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache2/logs/${prog}.pid}
CONFFILE=/usr/local/apache2/conf/httpd.conf
請根據(jù)自己的實(shí)際情況更改相應(yīng)的路徑!
然后運(yùn)行如下命令:
chmod +x /etc/init.d/httpd
chkconfig --add httpd
chkconfig httpd on
/etc/init.d/httpd start
netstat -lnp |grep httpd
三、php安裝
cd /usr/local/src
wget http://mirrors.sohu.com/php/php-7.1.3.tar.gz
tar zxvf php-7.1.3.tar.gz
cd php-7.1.3
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
--with-mysql-sock=/tmp/mysql.sock \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-bz2 \
--with-openssl \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-sockets \
--enable-exif \
--disable-ipv6
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
四、apache結(jié)合php
vi /usr/local/apache2/conf/httpd.conf
找到
#ServerName www.example.com:80
改成
ServerName localhost:80
找到:
AddType application/x-gzip .gz .tgz
在該行下面添加:
AddType application/x-httpd-php .php
找到:
DirectoryIndex index.html
將該行改為:
DirectoryIndex index.html index.htm index.php
/usr/local/apache2/bin/apachectl -t
service httpd restart
測試解析php
vi /usr/local/apache2/htdocs/1.php
寫入:
echo "php解析正常";
echo phpinfo();
?>
保存后,繼續(xù)測試:
curl localhost/1.php
查看結(jié)果已經(jīng)可以成功解析。
對于上文關(guān)于LAMP環(huán)境如何搭建安裝(centos6.9+apache2.4+mysql5.7+php7.1),大家覺得是自己想要的嗎?如果想要了解更多相關(guān),可以繼續(xù)關(guān)注我們的行業(yè)資訊板塊。