系統(tǒng)平臺 | ip | 安裝的服務 |
---|---|---|
centos/redhat | 192.168.136.145 | httpd-2.4/mysql-5.7/php/php-mysql |
httpd >mysql >php
注意php要求httpd使用prefock MPM安裝統(tǒng)一采用lamp方式安裝
#redhat源 [root@clq ~]# cat /etc/yum.repos.d/CentOS-Stream- CentOS-Stream-AppStream.repo CentOS-Stream-HighAvailability.repo CentOS-Stream-BaseOS.repo CentOS-Stream-Media.repo CentOS-Stream-Debuginfo.repo CentOS-Stream-PowerTools.repo CentOS-Stream-Extras.repo CentOS-Stream-RealTime.repo #安裝epel源 [root@clq ~]# yum -y install epel-release #查看包組 [root@clq ~]# yum grouplist #安裝包組 [root@clq ~]# dnf -y groups mark install "Development Tools" #創(chuàng)建apache用戶 [root@clq ~]# useradd -r -M -s /sbin/nologin apache #安裝依賴包(openssl-devel:加密傳輸模塊) [root@cb ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make #下載安裝apr和apr-util和httpd [root@cb ~]# cd /usr/src/ #利用wget下載三包 略 #tar解壓包 略 #進入apr包進行修改 [root@cb apr-1.7.0]# vim configure cfgfile="${ofile}T" trap "$RM \"$cfgfile\";exit 1" 1 2 15 $RM "$cfgfile" #此行刪掉或注釋 #apr編譯三步 ./configure --prefix=/usr/local/apr make make install #apr-util編譯三步 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make make install #httpd編譯三步 ./configure --prefix=/usr/local/apache \ --sysconfdir=/etc/httpd24 \ --enable-so \ --enable-ssl \ --enable-cgi \ --enable-rewrite \ --with-zlib \ --with-pcre \ --with-apr=/usr/local/apr \ --with-apr-util=/usr/local/apr-util/ \ --enable-modules=most \ --enable-mpms-shared=all \ --with-mpm=prefork make make install #安裝完配置 環(huán)境變量:echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh 讀取:source /etc/profile.d/httpd.sh 頭文件映射:ln -s /usr/local/apache/include /usr/include/httpd 幫助文檔:vim /etc/man_db.conf 22 MANDATORY_MANPATH /usr/local/share/man 23 MANDATORY_MANPATH /usr/local/apache/man #取消ServerName前面的注釋(警告信息無關緊要) [root@cb src]# vim /etc/httpd24/httpd.conf ServerName #啟動apache [root@cb src]# systemctl stop firewalld [root@cb src]# systemctl disbles firewalld [root@cb src]# /usr/local/apache/bin/apachectl start [root@cb src]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:* #注意刪掉系統(tǒng)本身的apache #編寫service文件實現(xiàn)開機自啟 #編寫httpd.service文件: vim /etc/systemd/system/httpd.service 文件內(nèi)倆個具體的路徑: .配置文件路徑:/etc/httpd24/httpd.conf .程序文件路徑:/usr/local/apache/bin/httpd #系統(tǒng)加載文件:systemctl daemon-reload #啟動systemctl start httpd #自啟動systemctl enable httpd
[root@clq ~]# vim /etc/systemd/system httpd.service [root@clq system]# cat httpd.service [Unit] Description=Start httpd [Service] Type=simple EnvironmentFile=/etc/httpd24/httpd.conf ExecStart=/usr/local/apache/bin/httpd -k start -DFOREGROUND ExecReload=/usr/local/apache/bin/httpd -k graceful ExecStop=/bin/kill -WINCH ${MAINPID} [Install] WantedBy=multi-user.target
#安裝依賴包(cmake:編譯自動配置工具) dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel #創(chuàng)建用戶 useradd -r -M -s /sbin/nologin mysql #下載mysql5.7.31包 #解壓放到/usr/local下 #改名字方便操作 cd /usr/local mv mysql5.7.31 mysql #改屬主 chown -R mysql.mysql mysql/ #環(huán)境變量 echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh source /etc/profile.d/mysql.sh #頭文件映射 ln -s /usr/local/mysql/include /usr/include/mysql #庫文件 vim /etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib ldconfig #重新讀取一下 #幫助文檔 vim /etc/man_db.conf 23 MANDATORY_MANPATH /usr/local/apache/man 24 MANDATORY_MANPATH /usr/local/mysql/man #創(chuàng)建數(shù)據(jù)目錄 mkdir /opt/data chown -R mysql.mysql /opt/data #初始化 mysqld --initialize --user=mysql --datadir=/opt/data #編寫配置文件 cat >/etc/my.cnf EOF [mysqld] basedir = /usr/local/mysql #安裝目錄 datadir = /opt/data #數(shù)據(jù)目錄 socket = /tmp/mysql.sock #套接字 user = mysql #用戶 port = 3306 #端口號 pid-file = /opt/data/mysql.pid #進程號文件 skip-name-resolve #跳過域名解析 EOF 退出 #編寫腳本 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld vim /etc/init.d/mysqld datadir=/opt/data basedir=/usr/local/mysql #啟動mysql service mysqld start ss -antl #安裝libncurses.so.5包 yum whatprovides libncurses.so.5 yum -y install ncurses-compat-libs #修改mysql密碼 set password=password('Centos8.0!') #確保開機自啟 chkconfig --add mysqld chkconfig mysqld on chkconfig --list
#centos8可yum安裝php,php是一門語言,安裝7.2版本以上即可 yum -y install php*
#php配置 vim /etc/php-fpm.d/www.conf 38 ;listen = /run/php-fpm/www.sock #取消注釋 39 listen = 127.0.0.1:9000 #添加此行 65 listen.allowed_clients = 127.0.0.1 mkdir -p /data/php #創(chuàng)建php目錄 chown -R apache.apache /data/ #改變屬主 vim /data/php/index.php #編寫index.php文件 ?php phpinfo(); ?> #重新啟動systemctl restart php-fpm.service
centos8之前版本 //配置yum源 [root@localhost ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm [root@localhost ~]# rpm -Uvh remi-release-7.rpm [root@localhost ~]# yum makecache --enablerepo=remi-php74 //安裝依賴包 [root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php72-php-mysqlnd 安裝過程略.... //下載php [root@localhost ~]# cd /usr/src/ [root@localhost src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz 下載過程略.... //編譯安裝php [root@localhost src]# tar xf php-7.2.8.tar.xz [root@localhost src]# cd php-7.2.8 [root@localhost php-7.2.8]# ./configure --prefix=/usr/local/php7 \ --with-config-file-path=/etc \ --enable-fpm \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-soap \ --with-openssl \ --enable-bcmath \ --with-iconv \ --with-bz2 \ --enable-calendar \ --with-curl \ --enable-exif \ --enable-ftp \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-zlib-dir \ --with-freetype-dir \ --with-gettext \ --enable-json \ --enable-mbstring \ --enable-pdo \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-readline \ --enable-shmop \ --enable-simplexml \ --enable-sockets \ --enable-zip \ --enable-mysqlnd-compression-support \ --with-pear \ --enable-pcntl \ --enable-posix [root@localhost php-7.2.8]# make -j $(cat /proc/cpuinfo |grep processor|wc -l) 編譯過程略 [root@localhost php-7.2.8]# make install 安裝過程略 //安裝后配置 [root@localhost ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh [root@localhost ~]# source /etc/profile.d/php7.sh //安裝后配置 [root@localhost ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh [root@localhost ~]# source /etc/profile.d/php7.sh [root@localhost php-7.2.8]# which php /usr/local/php7/bin/php [root@localhost php-7.2.8]# php -v PHP 7.2.8 (cli) (built: Aug 16 2018 13:27:30) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies //配置php-fpm [root@localhost php-7.2.8]# cp php.ini-production /etc/php.ini [root@localhost php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@localhost php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm [root@localhost php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf [root@localhost php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf //編輯php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf): //配置fpm的相關選項為你所需要的值: [root@localhost ~]# vim /usr/local/php7/etc/php-fpm.conf ..... ..... pm.max_children = 50 ;最多同時提供50個進程提供50個并發(fā)服務 pm.start_servers = 5 ;啟動時啟動5個進程 pm.min_spare_servers = 2 ;最小空閑進程數(shù) pm.max_spare_servers = 8 ;最大空閑進程數(shù) [root@localhost ~]# tail /usr/local/php7/etc/php-fpm.conf ; file. ; Relative path can also be used. They will be prefixed by: ; - the global prefix if it's been set (-p argument) ; - /usr/local/php7 otherwise include=/usr/local/php7/etc/php-fpm.d/*.conf pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 2 pm.max_spare_servers = 8 //啟動php-fpm [root@localhost ~]# service php-fpm start Starting php-fpm done //默認情況下,fpm監(jiān)聽在127.0.0.1的9000端口,也可以使用如下命令驗證其是否已經(jīng)監(jiān)聽在相應的套接字 [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:9000 *:* LISTEN 0 128 :::80 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 80 :::3306 :::* [root@localhost ~]# ps -ef|grep php root 81070 1 0 14:13 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf) nobody 81071 81070 0 14:13 ? 00:00:00 php-fpm: pool www nobody 81072 81070 0 14:13 ? 00:00:00 php-fpm: pool www nobody 81073 81070 0 14:13 ? 00:00:00 php-fpm: pool www nobody 81074 81070 0 14:13 ? 00:00:00 php-fpm: pool www nobody 81075 81070 0 14:13 ? 00:00:00 php-fpm: pool www root 81079 83354 0 14:15 pts/1 00:00:00 grep --color=auto php
apache 2.4以后有一個針對FastCGI的實現(xiàn),模塊為mod_proxy_fcgi.so,它其實是作為mod_proxy.so模塊的擴展,因此,這倆個模塊都要加載,編輯httpd.conf文件,取消兩行注釋
vim /etc/httpd24/httpd.conf LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so 或者sed修改 sed -i '/proxy_module/s/#//g' /etc/httpd24/httpd.conf sed -i '/proxy_fcgi_module/s/#//g' /etc/httpd24/httpd.conf
apache yum安裝網(wǎng)頁的文件路徑:/var/www/html
apache 源碼安裝網(wǎng)頁的文件路徑:/usr/local/apache/htdocs
配置虛擬主機
在需要使用fcgi的虛擬主機添加倆行:
ProxyRequests Off #關閉正向代理 ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/網(wǎng)頁目錄/redhat.com/$1 #以上設置是表示把.php結尾的文件發(fā)送到php-fpm進程,php-fpm至少需要知道運行的目錄和URL,fcgi后面指名了這倆個參數(shù),其它參數(shù)被mod——proxy_fcgi.so進行了封裝,不需要手動指定。 #redhat是域名 #$1表示匹配所有以.php結尾的httpd請求
/etc/httpd24/httpd.conf #主配置文件 [root@clq ] vim /etc/httpd24/httpd.conf #進入主配置文件添加一個虛擬主機配置文件 [root@clq ]vim /etc/httpd24/extra/vhosts.conf #編輯虛擬主機配置文件 VirtualHost *:80> DocumentRoot "/data/php/" #文件存放路徑 ServerName www.clq.com #域名 DirectoryIndex index.php ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/php/$1 Directory "/data/php/"> Options none AllowOverride none Require all granted /Directory> /VirtualHost> [root@clq] vim /etc/httpd24/httpd.conf 203 ServerName 0.0.0.0.com:80 #修改 261 DirectoryIndex index.php index.html #中間加index.php 399 AddType application/x-httpd-php .php #添加此行 400 AddType application/x-httpd-php-source .phps #添加此行 488 # 489 Include /etc/httpd24/httpd/extra/vhosts.conf #添加此條 #重啟 systemctl restart httpd
下載地址:https://wordpress.org/download/#download-install
#解壓該包 [root@clq ~]# unzip wordpress-5.7.2.zip #解壓的包全部放到/data/php下 [root@clq ~]# mv wordpress/* /data/php/
再次訪問:
#數(shù)據(jù)庫權限 mysql> grant all on *.* to root@'192.168.136.219' identified by 'huawei@123'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) #創(chuàng)建數(shù)據(jù)庫wordpress mysql> create database wordpress;
以上就是企業(yè)使用LAMP源碼安裝教程的詳細內(nèi)容,更多關于企業(yè)用LAMP源碼安裝的資料請關注腳本之家其它相關文章!