自動目錄
OS
CentOS Linux release 7.3.1611 (Core)
安裝apache
# yum install httpd
開啟防火牆 Selinux
# firewall-cmd --zone=public --add-port=80/tcp --permanent
# firewall-cmd --reload
開啟SELINUX
# setsebool httpd_can_network_connect on
# setsebool httpd_can_network_connect_db on
# setsebool httpd_can_sendmail on
# chcon -t httpd_sys_rw_content_t /path/to/upload
要讓httpd讀取的目錄,例如網頁目錄 (預設的/var/www/html已設定)
# chcon -R -t httpd_sys_content_t /path/to/html
安裝PHP7[1]
如果你已有安裝其他版本的PHP,請先移除它們
# yum remove php*
# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# yum install php70w php70w-opcache
# yum install php70w-mysqlnd php70w-mbstring php70w-gd
# yum install php70w-pecl-imagick
=== 111.10.6 更新,因為此時的php版本已經到7.4.x[2] =====
# yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
# yum -y install yum-utils
# yum-config-manager --enable remi-php74
主要使用 remi來更新
# yum update
# yum install php php-cli
# php -v
PHP 7.4.32 (cli) (built: Sep 28 2022 09:09:55) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
設定 vi /etc/php.ini
; 時區 date.timezone = "Asia/Taipei" ; Session 時間改一天 session.gc_maxlifetime = 86400 ; 記憶體,預設128M memory_limit = 1024M ; 上傳大小限制和時間 post_max_size = 20M upload_max_filesize = 20M max_input_time = 120 default_socket_timeout = 600
安裝mariadb10.9
建立 yum repository
# vim /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.9/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
# yum install MariaDB-server MariaDB-client
安裝 phpmyadmin
到官網 https://www.phpmyadmin.net/ 找尋下載連結
# wget https://files.phpmyadmin.net/phpMyAdmin/5.2.0/phpMyAdmin-5.2.0-all-languages.zip
# unzip phpMyAdmin-5.2.0-all-languages.zip
修改設定檔
# mv config.sample.inc.php config.inc.php
# vi config.inc.php
去 [3] phpMyAdmin blowfish secret generator 取得secret,這個頁面只要點開就會隨機產生一組,只要貼上即可
$cfg['blowfish_secret'] = 'l54xE78nRD;7Fiz{K85X5e{U9iwm7k;X';
建立暫存目錄以提升速度
# chmod 777 tmp
# chcon -t httpd_sys_rw_content_t tmp
開啟頁面,警告消失。
啟動
# systemctl enable httpd
# systemctl enable mariadb
# systemctl start mariadb
# systemctl start httpd
你的檔案放在 /var/www/html中
開你的網頁 http://x.x.x.x/ 來測試能不能看到歡迎畫面,我發現這頁還是responsive web design。
如果出現forbidden代表selinux或檔案權限問題,如果等很久沒頁面是防火牆問題。
其他的問題原因太複雜得CASE by CASE
參考資料
[1] https://webtatic.com/packages/php70/
[2] https://computingforgeeks.com/how-to-install-php-7-4-on-centos-7/
[3] https://phpsolved.com/phpmyadmin-blowfish-secret-generator