Replacing the PHP version that is being used by Apache on a Linux Centos 7 server.
I am using a Linux Centos 7 server, where I have installed PHP 7.2.24, when I use the command: php --version it displays the correct PHP version:
Current PHP version
When I display PHP info, Apache is using PHP Version 5.6.40.
I have taken a look in the .conf file, located at: /etc/httpd/conf/httpd.conf which has the following lines in the file:
httpd.conf content
This lead me to opening /etc/httpd/conf/extra/httpd-phpmodules.conf, which has the following content:
phpmodules
My idea is to to edit the LoadModule line in /etc/httpd/conf/extra/httpd-phpmodules.conf to load the PHP 7 module. Is this the right thing to do?
The next challenge I face, is to track down the module name & path I have to replace it with.
When I run the command: yum list installed php, it displays the PHP packages, but it doesn't look anywhere near the module name or path that I can use. How can I track down the module name & path to replace in httpd-phpmodules.conf (if this is the correct location to replace it).
yumlist
How can I track down the module name
A method I use to easily search for files is ‘locate’.
sudo apt install mlocate -y ; sudo updatedb
Then, search for php:
locate php
Multiple entries will return.
Simply execute a valid looking php executable, and check if that is the version u want.
Related
I have a system build with Laravel 5.5 and it needs PHP version 7.
I have deployed the project to site ground server, updated PHP version using PHP version but when I ran php -v command via putty it is showing me PHP version 5. I don't know what going on.
I shall be thankful if someone tell me that what is the proper way of updating PHP version?
I have also tried AddHandler application/x-httpd-php70s .php in my .htaccess files but got nothing fruitful
You can change the PHP CLI version through SSH. After connecting through SSH type cd ~ and then find .bash_profile file. Open the .bash_profile file with nano or vi which you would like to use and enter this line:
alias php=/usr/local/php72/bin/php-cli
and save the file. After that run command:
source .bash_profile
And your PHP CLI version has been changed. To confirm the PHP version type php -v and it will show you the version which you just changed.
P.S: In my case, I want to change the PHP CLI version to PHP 7.2 so I use php72 in alias php=/usr/local/php72/bin/php-cli. You can change it to any other version which you need.
So there's no problem if you see PHP5 using command line and PHP7 using php file with phpinfo();. Your hosting provider allows you to choose from several PHP version. You can select PHP7 e.g. using .htaccess but it doesn't have to change PHP CLI version. So when you set PHP7 in .htaccess file it serves your website using PHP7, but CLI is still v5.
By the way, this type of question should be asked on superuser I think.
I have php of version 5.5.12 and wamp version 2.4.9 and PHP Extension Build as API20121212,TS,VC11 . I am using this dll 'php_mongo-1.5.5-5.5-vc11.dll' (renamed to php_mongo) but still when i restart my all services mongo db is not displaying on phpinfo().Any pointer where m i going wrong ?
first of all you have to download the latest mongo dll files from
https://s3.amazonaws.com/drivers.mongodb.org/php/index.html
unzip the downloaded file and you will see a bunch of files like this:
now it is time to decide which dll file you have to use.
open your phpinfo() and search for word compiler. you will see sth like this:
so now according to my compiler version (MSVC11) I have to choose file with vc11 word inside their name. according to my PHP version which is 5.5.12 I have to choose file with word 5.5 inside their name.
now search for word thread safety in your phpinfo
and if it was enabled, it means that you have to choose file that doesn't have word nts inside their name but if your thread safety was disabled then you need to choose file with word nts inside their name.
now according to your installation architecture you may choose files with x86_64 inside their name.
after choosing the appropriate dll file, rename it to php_mongo.dll and copy paste it to your php extensions directory which is mostly located at
C:\wamp\bin\php\php5.5.12\ext
now open your php.ini file and add this at the end of it.
extension=php_mongo.dll
according to http://php.net/manual/en/mongo.installation.php
for installing mongo on windows, you have to also include libsasl.dll in your system PATH.
libsasl.dll file is mostly located at
C:\wamp\bin\php\php5.5.12
add this path to your system PATH.
reboot your wamp, refresh your phpinfo page and you should see sth like this:
which means that you have installed mongo correctly. :)
I have never used MONGO, but I was interested to see if there where problems using it with WAMPServer so I did a quick install to prove it shoud work, and it does.
Here is a list of what I did, I hope it helps you work out what you may have done wrong.
First you have to download the Mongo Database manager itself and install it.
Download from https://www.mongodb.org/downloads
Updated Aug 2019:
Download from here now
So you can place the software yourself I would download the ZIP and NOT the .MSI this way you dont get your system messed with by the .msi developer and what they think should be done to your system and you are in complete control.
Download the 32bit or 64 bit version to match your OS and WampServer(32/64) version you are running.
Now the Install is just a case of extracting the files from the zip and placing them somewhere on your system. I suggest :-
Copy the bin folder from the extract to c:\wamp\bin\mongo\mongox.y.z ( x.y.z to match the version of mongo you downloaded).
Create a data folder under that folder, so c:\wamp\bin\mongo\mongox.y.z\data
Create a data folder for your first database under that folder, so \wamp\bin\mongo\mongox.y.z\data\db
Create a config file for mongo in c:\wamp\bin\mongo\mongox.y.z\mongod.cfg and add as a minimum these parameter :-
NOTE: these are just params that will get it running, NOT A DEFINITIVE SET OF PARAMETERS!
systemLog:
destination: file
path: "c:/wamp/logs/mongod.log"
logAppend: true
timeStampFormat: iso8601-local
net:
bindIp: 127.0.0.1
port: 27017
storage:
dbPath: "c:/wamp/bin/mongo/mongo2.6.6/data"
directoryPerDB: true
Now if you want to have mongodb running as a service create a command file like so in the C:\wamp\bin\mongo\mongox.y.z folder :-
Filename = install_service.cmd
mongod.exe --config "c:\wamp\bin\mongo\mongo2.6.6\mongod.cfg" --install --serviceName wampmongodb --serviceDisplayName wampmongodb
sc config wampmongodb start= demand
The space between start= and demand is required, not a typo
For completeness also create an uninstall file :-
Filename = uninstall_service.cmd
mongod.exe --remove --serviceName wampmongodb
Now create 2 command files to start and stop your mongodb instance
Filename = start_mongo.cmd
net start wampmongodb
Filename = stop_mongo.cmd
net stop wampmongodb
Now start a command window using (Run as Administrator) and use these command files to install and start your MONGODB Server
CD \wamp\bin\mongo\mongox.y.z
#Install MONGO as a service
install_service
#Start the service
start_mongo
Now check the c:\wamp\logs folder and make sure there are no errors reported in the mongod.log file
While still in the command window, check that mongo is running by trying a few simple commands
Use the instructions here http://docs.mongodb.org/manual/tutorial/getting-started/ to prove that it is all working.
NOW ADD THE PHP Extension
Download from 'http://pecl.php.net/package/mongo'
Select the version you want and click the Windows icon with the word DLL beside it, in the 'Downloads' column.
This will take you to the download page for that version of the MONGO PHP extension.
You should now select the download link that matches the version of the MONGO extension you want, and the matching (x86) for 32bit WAMPServer installs or (x64) for 64bit WAMPServer installs.
You must click the 'DLL' link otherwise you will get a unix/linux source code.
Remember you must match the 32 or 64 bit to the version of WAMPServer you downloaded
So if you are running Windows 64bit but installed WAMPServer 32bit you need the 32bit version of the MONGO extension.
Also remember that you need the Thread Safe version (TS) to run with WAMPServer's Apache configuration.
Extract the zip file, and copy php_mongo.dll to your PHP folder eg C:\wamp\bin\php\phpx.y.z\ext
Edit your php.ini file to add the new extension.
To use Mongo with your web server (Apache) use the wampmanager menus to edit php.ini i.e.
wampmanager -> PHP -> php.ini
and add this line after all the other extension lines
extension=php_mongo.dll
To use mongo with scripts run from the command line (PHP CLI) edit C:\wamp\bin\php\phpx.y.z\php.ini and add the extension line again in there.
Start Wampmanager. Or Restart the Apache service.
This should refresh WAMPServers config and pick up the new PHP extension, if not do this when wampmanager is running:-
wampmanager -> Apache -> Service -> Restart Service
Run localhost by :-
wampmanager -> localhost
and then click on the phpinfo() link on the homepage.
You should now see a section entitled 'mongo' with some configuration options listed. If you do the PHP MONGO extension is active.
IMPORTANT
If you are running Windows Server 2008 R2 or Windows 7 you may have to install this HotFix to resolve an issue with Memory Mapped Files.
Request it from here http://support.microsoft.com/kb/2731284/en-us. You have to ask for it, and then they send you an email telling you where it can be downloaded from.
The link they gave me was http://hotfixv4.microsoft.com/Windows 7/Windows Server2008 R2 SP1/sp2/Fix405791/7600/free/451412_intl_i386_zip.exe
However I did not need to install it to get to the stage where MONGO was installed and running simple tests from the command line AND through Apache and PHP.
If you still facing the problem follow bellow two rules:
Make sure you downloaded drivers from
http://pecl.php.net/package/mongo
Try version 1.5.1 drivers (When I
am writing this the latest driver version is 1.6.8 but 1.6.8 to 1.5.5 nothing is worked for me)
Have you entered the .dll in your php.ini file (properly)?
http://docs.mongodb.org/ecosystem/drivers/php/
Scott
Updates for PHP 7 version.
As per documentation we have to download mongodb-1.2. You can download it from here based on your PHP version.
I'm trying to install orocrm on centos server and it is asking for PHP 5.4 and ICU library 4.4. Although I updated PHP and restarted Apache my php version still shows PHP 5.3 if outputting phpinfo in a php page. But,if I use php -v command then it shows php 5.5
ini path is shown /usr/local/lib/php.ini if using php page but through command it shows /etc/php.ini
please help...
The PHP 5.4 you compiled is not getting picked up by Apache. Rather than figuring out how to point Apache to this installation, the easiest (and safer since you'll get security updates) is to use the IUS Community repository
I have a couple of thoughts. If you're on CentOS you're probably using YUM as your package manager. With it, you could remove the PHP's and add a new one (if you don't have active clients using it). You can search what PHP version yum has by doing one of these:
yum list
yum list installed
If it registers multiple versions, you can "yum remove $package".
If you're php -v showing version 5.5, then your path is set to include that. You can see that by typing $PATH from the command line when SSH'd in. In your ~/.bashrc (or ~/.profile) you can edit your $PATH by adding something like:
export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
EDIT: You should back up your PATH before writing a new one and after you edit it type "source ~/.bashrc" or "source ~/.profile" to make the command line see it.
You can also directly edit the php in the .bashrc to point to the correct version by setting up an alias (if you don't fix the root of the problem) like
alias php="/path/to/php"
You can see where your current php is by typing:
which php
Your PHP extension comes from the apache httpd.conf file. You can find it somewhere like /etc/apache2/httpd.conf. Search for "LoadModule" or "LoadModule php" and see which extension of PHP your apache is pointing to. It may still be pointing to an incorrect version.
To answer your question about ICU, it comes from the "intl" extension. With yum, this is probably called php-intl or php54-intl or php54w-intl. You can do something like "yum search intl" and it should give you the exact extension name.
I hope this helps!
I am attempting to configure PHP and Mongo DB to connect with one another and I'm having some troubles. Before I say the problem let me recap what I have so far.
I am using MAC OS X 10.6.8
I have mongo DB installed and working stand-alone.
I have enabled PHP on the default Mac OS Apache web server. It is working and the server recognizes PHP ( it is not allowing inline PHP scripts in HTML files...not sure if this an issue)
"Web sharing" works just fine.
I have installed pear via this url: curl -O http://pear.php.net/go-pear.phar
I have the pear folder and files accessible and have launched o-pear.php from a web browser.
I have gone through the step-by-step install process ( and removed any red displayed errors ).
Presumably Pear is now installed.
It says at the bottom of the install front end:
Note: To use PEAR without any problems you need to add your PEAR
Installation path (/Users/myname/Sites/PEAR) to your
include_path.
Using a .htaccess file or directly edit httpd.conf would be working
solutions for Apache running servers, too.
I am not sure what the code is I need to add for the httaccess rewrite.
As of this moment
Terminal does not recognize the pear command.
When I launch the pear "front end" from a web browser I get:
Fatal error: No PEAR.php in supplied PEAR directory: /Users/myname/Sites/PEAR in /Users/myname/Sites/index.php on line 24
Thank you.
That is all.
Create a new PHP file called phpinfo.php. Add the content <?php phpinfo(); ?> there. Run the script from within your webbrowser.
You should see a big page with PHP configuration information. Watch out for include_path. This is where your webserver/PHP module/process searches for include files.
You will also find Loaded Configuration File. This is the PHP configuration file being used. Open that file in any editor, and search for include_path again. Add /Users/myname/Sites/PEAR to the end of the include_path.
Restart your webserver. PEAR now should work.
If you need to install the MongoDB PHP extension, go for pecl install mongo from command line.
I am using MAMP and would like to use mongo with PHP. I am stuck because the version of MAMP I'm using is the latest version I can find, and it's running PHP 5.2.11. The only Mongo PHP install I can find for OSX is for PHP 5.3.
Is there any way to get mongo working with PHP using MAMP?
For MAMP 2.1.2 and PHP 5.4.10
Download MongoDB php driver .
copy mongo.so to
/Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/
and using temrinal
cd /Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/ && wget https://github.com/downloads/stennie/mongo-php-driver/mongo.so
open
/Applications/MAMP/bin/php/php5.4.10/conf/php.ini
Find ; Extensions
add
extension=mongo.so
Restart MAMP.
Above steps will install MongoDB driver 1.2.10.
To install latest Mongodb driver using PECL
install autoconf using homebrew or Mac Ports
brew install autoconf
Download php 5.4.10 source from php.net.
rename uncompressed php source folder from php-5.4.10 to php and paste it in this folder
/Applications/MAMP/bin/php/php5.4.10/include/
using the terminal open php folder and run ./configure
cd /Applications/MAMP/bin/php/php5.4.10/include/php/ && ./configure
Add MAMP bin to your ~/.bash_profile
echo "export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH" >> ~/.bash_profile
source ~/.bash_profile
install latest mongo
pecl install mongo
restart MAMP server :).
Here's a tutorial how to do it: http://www.davidgolding.net/mongodb/installing-mongodb-on-mamp-1-9-5.html
Post was removed so here's the tutorial:
Appsolute launched MAMP version 1.9.5 today, so I thought it’d be a great time to add MongoDB to it and improve my NoSQL skills.
Prepare MAMP for MongoDB files
Create a new folder at Applications/MAMP/db/mongo with three additional subfolders named bin, data, and tmp. Provide these folders with chmod 0755 access permissions. These folders will be the main runtime location for Mongo once MAMP gets it running.
Download MongoDB
Grab the latest Mac OS install package of MongoDB. My server setup called for OS X 64-bit, version 1.6.5. It’ll have a directory named bin. Drop the files from this folder into the /Applications/MAMP/db/mongo/bin folder you already created.
Download Mongo Driver for PHP
I’m running PHP 5.3 (why use MongoDB with any earlier version of PHP?), so I’ll need the mongo.so extension to get PHP and Mongo working together. This is available at the MongoDB GitHub repository, under the PHP 5.3 for Mac binary. After unpacking the downloaded file, place the mongo.so extension file in the /Applications/MAMP/bin/php5.3/lib/php/extensions folder.
Update: An alternative is to place the mongo.so file in the /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626 folder and avoid having to edit the php.ini file. It appears that MAMP 1.9.5 already has the extension=mongo.so line in the extensions block of the php.ini file, even though version 1.9.5 doesn’t come bundled with Mongo.
4. Create Startup Routines for MAMP
Lastly, you’ll need to create the startup routines so that MAMP will launch Mongo along with MySQL and Apache. Create a new file at /Applications/MAMP/bin/startMongo.sh and place in it the following code:
# /bin/sh
/Applications/MAMP/db/mongo/bin/mongod --dbpath /Applications/MAMP/db/mongo/data --logpath /Applications/MAMP/db/mongo/mongodb.log --pidfilepath /Applications/MAMP/db/mongo/tmp/mongo.pid --fork --logappend
When called, this script will launch Mongo using the MAMP-relative paths rather than Mongo’s system defaults.
Create another file at /Applications/MAMP/bin/stopMongo.sh and place the shutdown method:
# /bin/sh
/bin/kill `cat /Applications/MAMP/db/mongo/tmp/mongo.pid`
This works like the previous script, except it kills the mongo.pid process, effectively shutting down Mongo.
To have MAMP automatically call these Mongo startup scripts, open the /Applications/MAMP/bin/start.sh and /Applications/MAMP/bin/stop.sh files, and insert the following lines above the startMysql.sh lines, respectively:
1
/Applications/MAMP/bin/startMongo.sh
1
/Applications/MAMP/bin/stopMongo.sh
Now MAMP will automatically launch Mongo upon startup.
The only thing left to do is tell PHP to run the mongo.so extension. If you’re running MAMP Pro, edit the php.ini file by selecting File > Edit Template > PHP 5.3 php.ini, otherwise you’ll need to lookup the path the php.ini file from the MAMP startup screen, under “phpInfo” and “Loaded Configuration File.”
Insert the following line in the php.ini file/template, save the file, then restart MAMP.
1
extension="/Applications/MAMP/bin/php5.3/lib/php/extensions/mongo.so"
Mongo should now run in the background on MAMP, which you can connect with from PHP using the main connection routines listed on the PHP site. Welcome to NoSQL on MAMP!
MAMP is now at version 2.2, which comes with PHP v 5.5.3. I managed to get Mongodb working had to jump through a few hoops to get there.
Start with a clean install of MAMP 2.2, make sure that's working.
1. I made this the system version of PHP, (not sure if necessary at this stage).
Find out the default version of php you are using, with the terminal command
$ which php
/usr/bin/php
Then back this up
$ sudo mv /usr/bin/php /usr/bin/php.bak
Then create a symlink to the MAMP latest version of php
$ sudo ln -s /Applications/MAMP/bin/php/php5.5.3/bin/php /usr/bin/php
Check this has been updated
$ which php
/Applications/MAMP/bin/php/php5.5.3/bin/php
2. Installing Mongo
$ cd /Applications/MAMP/db
$ curl http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.4.6.tgz > mongodb.tgz
$ tar -zxvf mongodb.tgz
$ rm mongodb.tgz
$ mv mongodb* mongo
$ mkdir mongo/data/db
Test to make sure mongo is working
$ ./mongo/bin/mongod --dbpath /Applications/MAMP/db/mongo/data/db
Should output some code, ending in 'waiting for connections on port 27017' press Ctrl + C to quit for now.
3. Now we can create a script to start/stop mongod automatically from the MAMP GUI. This inspiration came from a previous answer, by Alexandru Rada, but didn't quite work how he explained - I think this is to do with being a newer MAMP version.
In /Applications/MAMP/bin create a file called startMongo.sh and insert the following
# /bin/sh
/Applications/MAMP/db/mongo/bin/mongod --dbpath /Applications/MAMP/db/mongo/data/db --logpath /Applications/MAMP/logs/mongodb.log --pidfilepath /Applications/MAMP/tmp/mongo/mongo.pid --fork --logappend
I also created the mongo tmp folder at /Applications/MAMP/tmp/mongo
In the same bin directory create a file called stopMongo.sh and insert the following:
# /bin/sh
/bin/kill `cat /Applications/MAMP/tmp/mongo/mongo.pid`
Make these files executable
$ chmod 775 /Applications/MAMP/bin/startMongo.sh /Applications/MAMP/bin/stopMongo.sh
Now update the startApache.sh and stopApache.sh scripts to include our new files respectively.
Use the Activity Monitor in /Applications/Utilities and search for mongod. When you now start MAMP you should see the process mongod is started. When you stop or quit MAMP you should see this process is automatically killed.
4. We still need to install the mongo-php driver, which is also a pain. To do this I added the MAMP bin directory to my bash $PATH variable. To do this I had to edit the hidden file ~/.profile - but be aware that your $PATH might be loaded from somewhere else.
export PATH=$PATH:/Applications/MAMP/bin/php/php5.5.3/bin:/Applications/MAMP/db/mongo/bin
Note that each element is separated by a :. Quit terminal and re-open, then $ echo $PATH to check your new directories have been added to the path. You could also try $ which pecl or $ which mongod.
We still need some extras from PHP php.net download the same php stable version and unzip it. Create the folder 'include' at /Applications/MAMP/bin/php/php5.5.3/include . Drag the unzipped stable version of php to the include folder, and rename it to just 'php'.
$ cd /Applications/MAMP/bin/php/php5.5.3/include/php
$ ./configure
Now at last, we can hopefully run
$ sudo pecl install mongo
5. Now we just need to update our php config file to add the mongo.so extension.
Open /Applications/MAMP/bin/php/php5.5.3/conf/php.ini in a text editor, under the 'extensions' section, add in
extension=mongo.so
Quit and re-open MAMP!
Mac OS X 10.6 Snow Leopard (with the newest updates) has PHP 5.3 installed along with Apache.
You can enable the installed Apache in System Preferences, Sharing, Web Sharing (there is a help icon (?) which shows you details on using the system's web server).
See also this StackOverflow question:
Easiest way to activate PHP and MySQL on Mac OS 10.6 (Snow Leopard)?
Here's the way I did it and it was fairly simple.
First, read what Mongo says # http://www.mongodb.org/display/DOCS/PHP+Language+Center
When you run sudo pecl install mongo it's going to install it for the standard OSX PHP installation to use, so if for some reason you're using the built-in Apache installation.
Like you, I like using MAMP. I didn't want to go through figuring how to download Mongo into MAMP, so I just creating a symbolic link in the MAMP PHP Extensions folder and put the extension line in the MAMP php.ini. Restarted MAMP Apache and everything worked beautifully!
A couple things to note, after installing Mongo, note the extensions folder it installed it into then check MAMP php.ini to see where it has its extensions set to be. You'll notice the ending is very similar.
For MAMP PRO 2.0.5
You may compile your own mongo.so (http://m-schmidt.eu/2011/11/06/develop-mongodb-web-apps-with-mamp-under-mac-os-x/) or download compiled (http://www.davidgolding.net/mongodb/installing-mongodb-on-mamp-1-9-5.html).
I'd like compile.
After steps mongo.so don't include to php configuration, because in MAMP PRO php.ini placed in
/Applications/MAMP PRO/MAMP PRO.app/Contents/Resources
I using php5.3.6.ini file for my configuration.