更新系統軟體
yum update
安裝 nginx
安裝nginx源
yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安裝nginx
yum install nginx
啟動nginx
systemctl start nginx.service
安裝 MySQL 8
安裝mysql源
yum localinstall http://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
安裝 mysql
yum install mysql-community-server
啟動mysql
systemctl start mysqld.service
獲取mysql預設生成的密碼(圖中紅框處就是密碼)
grep 'temporary password' /var/log/mysqld.log
將預設密碼換成自己的密碼
mysql -uroot -p
Enter password 後面輸入上一步獲取到的密碼(輸入內容不會顯示在命令列中)
更換密碼(密碼需要足夠複雜)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPasdfs4!';
退出mysql並試用新密碼
mysql> quit;
mysql -uroot -p
輸入新密碼後登入成功說明密碼修改成功
新增一個可遠端訪問的賬戶,方便本地使用
建立一個 test 使用者
CREATE USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY 'u123&&456JE$';
編譯安裝 php
下載最新版 php7 原始碼包
cd /root & wget -O php7.tar.gz https://www.php.net/distributions/php-7.3.6.tar.gz
解壓原始碼包
tar -xvf php7.tar.gz
進入解壓目錄
cd php-7.3.6
安裝php依賴包
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
編譯配置,這裡如果上一步的某些依賴包沒有安裝好,就會遇到很多configure error,安裝上相關軟體開發包即可
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
錯誤
解決方法
cd /root
wget https://libzip.org/download/libzip-1.5.2.tar.gz
tar -zxf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ..
如果報這個錯,需要先安裝 cmake
yum -y install cmake
再次執行 cmake ..
提示 cmake 版本過低
解除安裝原本的 cmake
yum remove cmake
重新安裝 cmake
cd /root
wget https://cmake.org/files/v3.11/cmake-3.11.4.tar.gz
tar xzvf cmake-3.11.4.tar.gz
cd cmake-3.11.4
yum install -y gcc-c++
./bootstrap
出現以下提示說明執行成功
gmake
gmake install
cd /root
cd libzip-1.5.2
cd build
/usr/local/bin/cmake ..
出現以下提示,說明安裝成功
make && make install
出現以下提示,說明安裝成功
再次編譯 PHP
cd /root/php-7.3.6
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
如果報這個錯
# 新增搜尋路徑到配置檔案
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
# 更新配置\
ldconfig -v
安裝成功後如下
再次編譯安裝 php
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
出現如下提示,說明命令執行成功
編譯與安裝
make && make install
耐心等待編譯安裝完成
如果碰到以上報錯,說明伺服器記憶體不足,可以增加伺服器配置或者配置虛擬記憶體
dd if=/dev/zero of=/swap bs=1024 count=1M
mkswap /swap
swapon /swap
echo "/swap swap swap sw 0 0" >> /etc/fstab
再次執行 make && make install
耐心等待編譯安裝成功
新增 PHP 命令到環境變數
vim /etc/profile
在末尾加入
PATH=$PATH:/usr/local/php/bin
export PATH
要使改動立即生效執行
source /etc/profile
檢視環境變數
echo $PATH
檢視php版本
php -v
配置php-fpm
cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
啟動php-fpm
/etc/init.d/php-fpm start
到這裡 PHP 在 Linux 環境下的基礎執行環境就已經搭建完成,後續有其他軟體如:Redis
、Supervisor
等需要用到時會另開一篇部落格
本作品採用《CC 協議》,轉載必須註明作者和本文連結