Have you tried running latest Apache 2.4 with PHP 7.0 on CentOS 6? Last time i ran into trouble when a customer asked me to update Apache from 2.2.X to 2.4.X running on CentOS 6 with addition of keeping the PHP operational. I’ve checked third party repositories for Apache 2.4 RPMs so i would not have to bother with building it myself and found it quickly. I’ve also found different PHP versions in the same repositories and thought to myself “there, there, i’m almost done!”.
But things got complicated and none of the PHP versions available would run with Apache 2.4.X i’ve installed. Been searching the web for over an hour, testing it out without success and that’s why i’ve decided to write a post on Running latest Apache 2.4 with PHP 7.0 on CentOS 6 to help my readers get by this faster than me 🙂
Procedure: First we need to build latest Apache 2.4 RPMs, once that done we can install Apache 2.4 and last but not least we can compile PHP 7.0 and make it work with our Apache instance. Environment: I’m working on up2date fresh CentOS release 6.7 (Final) minimal installation with SELinux and IPTables enabled and running.
Running latest Apache 2.4 with PHP 7.0 on CentOS 6
1. Download and Install RPMForge Repository
RPMForge repository is required to download and install all of the dependencies we need to build Apache 2.4 RPMs.
Firstly allow access to this machine on port 80 TCP by adding the following line to /etc/sysconfig/iptables and reloading iptables service:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
Now we can start Apache for the first time.
[root@localhost apache24]# /etc/init.d/httpd start
Starting httpd: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[ OK ]
We can see that Apache start produced a warning since “ServerName” directive is not set, but Apache 2.4.20 started up successfully and is running.
[root@localhost apache24]# /etc/init.d/httpd status
httpd (pid 14317) is running...
We are one step closer to running the latest Apache 2.4 with PHP 7.0 on CentOS 6 🙂 ..continuing with PHP 7.0 installation.
8. Download and Unpack PHP 7
Download the latest version of PHP 7 and unpack it.
[root@localhost apache24]# cd ..
[root@localhost ~]# mkdir php7
[root@localhost ~]# cd php7
[root@localhost php7]# wget -O php-7.0.5.tar.gz http://de1.php.net/get/php-7.0.5.tar.gz/from/this/mirror
[root@localhost php7]# tar -xvzf php-7.0.5.tar.gz
9. Copy php.ini, Configure, Make and Install PHP
Move to the unpacked PHP directory, copy php.ini-production to /usr/local/lib directory and run configure on extracted php.
Once configure is done “make test” (not obligatory) and “make install”. Note that both these actions might take a while…
[root@localhost php7]# make test
[root@localhost php7]# make install
10. AddHandler for .php Files
We need to instruct PHP to handle files with .php extension and pass them to PHP interpreter. We can achieve this by adding two lines to global Apache config file with the commands below:
Create a new file in /var/www/html directory called info.php and add the following contents in it:
<?php
phpinfo();
?>
12. Restart Apache
We need to restart or reload Apache for configuration changes to become active.
[root@localhost php-7.0.5]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[ OK ]
13. Browse PHP Info File
To confirm everything works as expected open up the following URL in your browser: http://ip_address/info.php
Hopefully your server is in the same network and you will be able to access it. Change the ip_address with IP address of your server and PHP info page should open up holding all of the PHP information:
I have the following php. However when I see the index.php I get the following error message.
Strict standards: Non-static method Page::getInstanceByName() should not be called statically in /var/www/webworks/index.php on line 12
I am hoping someone can tell me how to fix the problem.
Thanks in advance.
index.php
// { common variables and functions
include_once('ww.incs/common.php');
$page=isset($_REQUEST['page'])?$_REQUEST['page']:'';
$id=isset($_REQUEST['id'])?(int)$_REQUEST['id']:0;...// { get current page idif(!$id){if($page){// load by name
$r=Page::getInstanceByName($page);if($r && isset($r->id))$id=$r->id;}if(!$id){// else load by special
$special=1;if(!$page){
$r=Page::getInstanceBySpecial($special);if($r && isset($r->id))$id=$r->id;}}}// { load page dataif($id){
$PAGEDATA=(isset($r)&& $r)?$r :Page::getInstance($id);}else{
echo '404 thing goes here';exit;}......
classPage{static $instances = array();static $instancesByName = array();static $instancesBySpecial = array();function __construct($v,$byField=0,$fromRow=0,$pvq=0){# byField: 0=ID; 1=Name; 3=specialif(!$byField && is_numeric($v)){// by ID
$r=$fromRow?$fromRow:($v?dbRow("select * from pages where id=$v limit 1"):array());}elseif($byField ==1){// by name
$name=strtolower(str_replace('-','_',$v));
$fname='page_by_name_'.md5($name);
$r=dbRow("select * from pages where name like '".addslashes($name)."' limit 1");}elseif($byField ==3&& is_numeric($v)){// by special
$fname='page_by_special_'.$v;
$r=dbRow("select * from pages where special&$v limit 1");}elsereturnfalse;if(!count($r ||!is_array($r)))returnfalse;if(!isset($r['id']))$r['id']=0;if(!isset($r['type']))$r['type']=0;if(!isset($r['special']))$r['special']=0;if(!isset($r['name']))$r['name']='NO NAME SUPPLIED';foreach($r as $k=>$v) $this->{$k}=$v;
$this->urlname=$r['name'];
$this->dbVals=$r;self::$instances[$this->id]=& $this;self::$instancesByName[preg_replace('/[^a-z0-9]/','-',strtolower($this->urlname))]=& $this;self::$instancesBySpecial[$this->special]=& $this;if(!$this->vars)$this->vars='{}';
$this->vars=json_decode($this->vars);}function getInstance($id=0,$fromRow=false,$pvq=false){if(!is_numeric($id))returnfalse;if(!@array_key_exists($id,self::$instances))self::$instances[$id]=newPage($id,0,$fromRow,$pvq);returnself::$instances[$id];}function getInstanceByName($name=''){
$name=strtolower($name);
$nameIndex=preg_replace('#[^a-z0-9/]#','-',$name);if(@array_key_exists($nameIndex,self::$instancesByName))returnself::$instancesByName[$nameIndex];self::$instancesByName[$nameIndex]=newPage($name,1);returnself::$instancesByName[$nameIndex];}function getInstanceBySpecial($sp=0){if(!is_numeric($sp))returnfalse;if(!@array_key_exists($sp,$instancesBySpecial)) $instancesBySpecial[$sp]=newPage($sp,3);return $instancesBySpecial[$sp];}
Also note that you are doing way too much work in the constructor, especially all that querying shouldn't be in there. All your constructor is supposed to do is set the object into a valid state. If you have to have data from outside the class to do that consider injecting it instead of pulling it. Also note that constructors cannot return anything. They will always return void so all these return false statements do nothing but end the construction.
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).