LNMP的搭建php
1、Linux(centos 7.3.1611)html
趁着學生證尚未過時,買了一年的阿里雲服務器。mysql
2、Nginx(nginx-1.14.2)nginx
1.下載nginx:wget https://nginx.org/download/nginx-1.14.2.tar.gzc++
2.安裝nginx所需環境sql
yum install -y gcc-c++數據庫
yum install -y pcre pcre-develvim
yum install -y zlib zlib-develcentos
yum install -y openssl openssl-develapi
3.解壓下好的nginx-1.14.2.tar.gz文件,而且進入解壓出來的nginx-1.14.2文件夾。
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure //使用默認配置
4.編譯安裝
make
make install
whereis nginx //查看安裝到哪兒去了
5.進入/user/local/nginx/sbin
./nginx //開啓nginx
./nginx -s quit //關閉nginx
./nginx -s reload //重啓nginx
ps aux|grep nginx //查看nginx進程
6.在阿里雲管理控制檯->雲服務器ECS->網絡和安全->安全組->配置規則->添加安全組規則根據需求添加。
7.在瀏覽器輸入雲服務器公網IP
以上,Nginx安裝完成。
3、MySQL(mysql-8.0.15)
1.下載mysql發行包
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
2.安裝mysql發行包
yum localinstall mysql80-community-release-el7-1.noarch.rpm
3.驗證安裝
yum repolist enabled | grep ‘mysql.*-community.*’
4.安裝mysql
Yum install -y mysql-community-server
5.檢查已安裝的軟件包
rpm -qa | grep -i ‘mysql.*8.*’
6.啓動mysql服務
systemctl start mysqld //開啓mysql服務
systemctl stop mysqld //中止mysql服務
systemctl restart mysqld //重啓mysql服務
systemctl status mysqld //查看服務狀態
7.查看mysql臨時密碼
grep ‘temporary password’ /var/log/mysqld.log
8.使用臨時密碼登陸mysql而且修改密碼
mysql -u root -p
alter user ‘root’@’localhost’ identified by ‘新密碼’;
如此,MySQL安裝完畢。
4、PHP(php-7.3.2)
1.wget http://cn2.php.net/get/php-7.3.2.tar.gz/from/this/mirror
2.tar zxvf mirror //解壓鏡像,進入解壓出來的php-7.3.2文件夾
3.使用yum安裝php所需依賴
yum -y install libcurl-devel
yum -y install libXpm-devel
yum -y install libxml2-devel
yum -y install php-mbstring
yum -y install libjpeg-devel
yum -y install libpng-devel
yum -y install freetype-devel
yum -y install mysql-devel
yum -y install libzip-devel //版本太低解決方案:http://www.kwx.gd/PHPEnvironment/CetnOS-libzip.html
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h //安裝完新版本後的必要操做
4.配置安裝php
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-mysqli --with-mysql-sock --with-pdo-mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-zlib-dir=/usr/local/zlib --with-libzip=/usr/local/libzip --with-pcre-dir --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-ctype
make
make install
5.複製php配置文件到安裝目錄
cp php.ini-production /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php.ini //display_errors = On,顯示錯誤信息
6.複製啓動腳本
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
7.修改php-fpm配置文件
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf //去掉 pid = run/php-fpm.pid 前面的分號
8.配置www.conf
cd php-fpm.d
cp www.conf.default www.conf
vim www.conf //此處能夠修改user和group
9.啓動php
/etc/init.d/php-fpm start //啓動
/etc/init.d/php-fpm stop //中止
/etc/init.d/php-fpm restart //重啓
ps -ef | grep php //查看php啓動狀態
10.配置nginx.conf
vim /usr/local/nginx/conf/nginx.conf
11./usr/local/nginx/html中建立index.php,重啓php和nginx。
鏈接數據庫後的效果:
5、補充:遠程鏈接阿里雲MySQL8.0
1.mysql設置
見http://www.javashuo.com/article/p-nawdlcsf-bb.html
2.阿里雲添加一個端口