操作系統(tǒng):CentOS 7
YUM安裝Mysql
- 添加mysql YUM源
# wget https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm
# rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
- 安裝mysql
# yum -y install mysql-community-server
- 啟動mysql并添加開機啟動
# systemctl start mysqld
# systemctl enable mysqld
- 登錄mysql并修改密碼
默認設(shè)置了‘root'@'localhost'的登錄密碼,把它找出來
# grep 'temporary password' /var/log/mysqld.log
2017-04-25T12:43:52.287512Z 1 [Note] A temporary password is generated for root@localhost: J:!kujwh1o9y
所以默認的臨時密碼為J:!kujwh1o9y
> mysql -uroot -p
> ALTER USER 'root'@'localhost' IDENTIFIED BY 'XXXX';
安裝Nginx
1.先安裝pcre
# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
# tar -zxf pcre-8.41.tar.gz && cd pcre-8.41 && ./configure --prefix=/usr/local/pcre && make && make install
- 創(chuàng)建用戶www
# groupadd www
# useradd -g www www -s /sbin/nologin -M
- 下載nginx安裝包
- 解壓并安裝
# tar -zxf nginx-1.12.2.tar.gz && cd nginx-1.12.2
# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-http_dav_module --with-pcre=/root/pcre-8.41
# make && make install
PS:這里的--with-pcre是pcre源碼的目錄每币,不是安裝目錄
4.啟動nginx
# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
# nginx
安裝php
1.安裝依賴包
依賴包列表
mysql-devel
openssl-devel
swig
libjpeg-turbo
libjpeg-turbo-devel
libpng
libpng-devel
freetype
freetype-devel
libxml2
libxml2-devel
zlib
zlib-devel
libcurl
libcurl-devel
m4
autoconf
openldap
openldap-devel
# yum -y install mysql-devel openssl-devel swig libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel libcurl libcurl-devel m4 autoconf openldap openldap-devel
- 下載并安裝
# wget http://cn2.php.net/distributions/php-5.6.35.tar.gz && tar -zxf php-5.6.35.tar.gz && cd php-5.6.35
# ./configure --prefix=/usr/local/php-fastcgi --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --with-libxml-dir --with-curl --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --with-openssl --enable-mbstring --with-gd --enable-gd-native-ttf --with-freetype-dir=/usr/lib64 --with-gettext=/usr/lib64 --enable-sockets --with-xmlrpc --enable-zip --enable-soap --disable-debug --enable-opcache --with-config-file-path=/usr/local/php-fastcgi/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www
# make && make install
- 安裝pdo-plugin
# cd ./ext/pdo_mysql
# /usr/local/php-fastcgi/bin/phpize
# ./configure --with-php-config=/usr/local/php-fastcgi/bin/php-config && make && make install
- 拷貝php.ini文件
# cp /root/php-5.6.35/php.ini-production /usr/local/php-fastcgi/etc/php.ini
- 拷貝php-fpm文件
# cp /usr/local/php-fastcgi/etc/php-fpm.conf.default /usr/local/php-fastcgi/etc/php-fpm.conf
- 把php-fpm做成服務(wù),并開機啟動
# cp /root/php-5.6.35/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# systemctl enable php-fpm
- 啟動php
# /etc/init.d/php-fpm start
修改nginx.conf
在index中加入index.php
location / {
root html;
index index.html index.htm index.php;
}
去掉php-fastcgi這部分注釋乙漓,并將/scriptsdocument_root$fastcgi_script_name
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
重啟nginx
到此LNMP環(huán)境搭建成功
測試
在/usr/local/nginx/html下新建文件phpinfo.php
vim phpinfo.php
<?php
phpinfo();
?>
在瀏覽器中打開IP/phpinfo.php