背景
公司要新建幾個專案,故而需要部署新的服務,作為許久沒有搭過環境的我來說,記錄總結一下。
感謝下面幾篇博文帶給我的幫助:
LNMP環境搭建
Linux配置PHP全域性環境變數
手工搭建環境
nginx安裝
安裝nginx依賴包
yum -y install pcre pcre-develnginx的各種模組中需要使用gzip壓縮:
yum -y install zlib zlib-devel
安全套接字層密碼庫:
yum -y install openssl openssl-devel
下載nginx包並解壓(到/usr/local/src目錄中)
cd /usr/local/srcwget nginx.org/download/nginx-1.1.10.tar...
tar -zxvf nginx-1.1.10.tar.gz
編譯安裝
cd nginx-1.1.10./configure –prefix=/usr/local/nginx
make
make install
建立並設定nginx執行賬戶
groupadd nginxuseradd -M -g nginx -s /sbin/nologin nginx
cd /usr/local/nginx/conf
vim nginx.conf,設定user引數如下:
user nginx nginx
/usr/local/nginx/sbin/nginx -t
啟動nginx
/usr/local/nginx/sbin/nginx
mysql安裝
使用 yum 命令安裝 MySQL,安裝前我們需要先去官網下載 Yum 資源包
wget repo.mysql.com/mysql-community-rele...rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
yum install mysql-server
許可權設定
chown mysql:mysql -R /var/lib/mysql初始化MySQL
mysqld –initialize啟動 MySQL
service mysqld start檢視 MySQL 執行狀態
service mysqld status驗證mysql 安裝成功,檢視版本號
mysqladmin –version修改mysql root的密碼
mysqladmin -u root password “密碼”
安裝PHP
安裝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下載PHP壓縮包
wget www.php.net/distributions/php-7.2....tar -zxvf php-7.2.17.tar.gz
編譯安裝
cd php-7.2.0./configure –prefix=/usr/local/php –disable-fileinfo –enable-fpm –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-openssl –with-zlib –with-curl –enable-ftp –with-gd –with-xmlrpc –with-jpeg-dir –with-png-dir –with-freetype-dir –enable-gd-native-ttf –enable-mbstring –with-mcrypt=/usr/local/libmcrypt –enable-zip –enable-mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-mysql-sock=/var/lib/mysql/mysql.sock –without-pear –enable-bcmath
make && make install
將php包解壓目錄中的配置檔案放置到正確位置(configure命令中的–with-config-file-path設定的位置)
cp php.ini-development /etc/php.ini建立並設定php-fpm執行賬號
groupadd www-datauseradd -M -g www-data -s /sbin/nologin www-data
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
cd php-fpm.d
cp www.conf.default www.conf(否則include匹配不到檔案)
vim www.conf
搜尋“user”設定執行賬號:
user=www-data
group=www-data
配置nginx支援php
vim /usr/local/nginx/conf/nginx.conf
修改完成之後記得重啟nginx服務:
service nginx start
設定php-fpm為系統服務
vim /etc/systemd/system/php-fpm.service檔案內容:
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
PrivateTmp=True
[Install]
WantedBy=multi-user.target
設定php-fpm服務開機自啟動
systemctl enable php-fpm.service啟動php-fpm
systemctl start php-fpm.service
檢視是否啟動成功
ps aux | grep php-fpm寫phpinfo()測試
至此完結
本作品採用《CC 協議》,轉載必須註明作者和本文連結