I've installed "PHP PECL EXTENSION/MODULE ON UBUNTU". At the end, I was asked to add some configuration lines in the a file called php_ini that can be found in this path:
/etc/php5/apache2/php.ini
However, after making my changes, I can't save the file because the file is read-only.
What the appropriate action to save my changes. I don't really why the file is read-only, I don't know if there is some thing I need to do. I'm new in Ubuntu/php
Thanks for helping.
For accessing the system files you need root permission.So you would need to use sudo command.it would be like sudo vim /etc/php5/apache2/php.ini(if u are using vim editor) as user2075215 mentioned in comment.
Use command:
"sudo gedit /etc/php5/apache2/php.ini"
It will open text editor, change your settings and save with ctrl+s and close the editor.
All changes will be saved.
Since I am a beginner in Terminal, I used cd multiple times to get to the location of my php.ini file.
cd etc
cd php
cd 7.0
.
.
.
Then I did
$ sudo xdg-open php.ini
and the file popped up and I am able save edits now.
Related
Is there any way to modify the php.ini file in Mac OSX.. I'm using XAMPP and i need to change the upload-tmp-dir path. Whenever I try to edit and save the file, it shows some error that I am not authorised to do so.
Please help!
You can update using editor in terminal and use sudo command to open it as superuser, see here.
sudo vim php.ini
or
sudo emacs php.ini
Your choice
What if you try to copy php.ini file to your Desktop, make changes, save it, and replace back?
1.open php.ini with superuser
sudo vim php.ini
2.press i to change somthing
3.press Esc and :wq to save and exit
4.restart your web server
Maybe step 4 is the reason "But my uploads are still not working.. ".
Does anyone know how to edit the mail setting in the php.ini file by using Vagrant.
so I would ssh in terminal like so:
cd myapp
vagrant ssh
then what>?
Depending on your box, it might be
sudo nano /etc/php5/apache2/php.ini
then adopt you changes and restart with
sudo service apache2 restart
Without knowing what specific setting you want and what you want it changed to, you could try adding a shell script to the end of your Vagrantfile (in the "Local Scripts" area) to do a search and replace on the ini file.
#!/usr/bin/env bash
sed -i.bak s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT_WITH/g /etc/php5/apache2/php.ini
Failing that, you can use ini_set in your project (preferably in a bootstrap) to change mail settings on a per-project basis.
In my case where I'm using scotchbox on vagrant, changing the php.ini file won't reflect changes in phpinfo() function output so I changed /etc/php5/apache2/conf.d/user.ini file which could be a bare file or a file with few lines declaring php error display, I add my configurations here e.g. upload_max_filesize = 64MSave the change and issue sudo service apache2 restart. Viewed the phpinfo page and I can see the updated filesize.
I have both ~/.bash_profile & ~/.profile files.
~/.bash_profile contains one line:
export PATH=/Applications/mamp/bin/php5.5.3/bin:$PATH
~/.profile contains three lines:
# MacPorts Installer addition on 2014-02-02_at_20:54:53: adding an appropriate PATH variable for use with MacPorts.
export PATH=/Applications/MAMP/bin/php5.5.3/bin/:/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
As you can see I am trying to get my default PHP PATH to use MAMPs PHP because I have mcrypt installed on it. For some reason when I type whereis PHP I get the native route: /usr/bin/php, and when I echo $PATH I get:
/Applications/mamp/bin/php5.5.3/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Somewhere I have another file thats really controlling my PATH and I have no clue where it is. What else could be controlling my PATH route?
NOTE: I have Homebrew, MacPorts, Xcode, and Xcode Command-Line Tools installed.
What you're seeing is coming from the system-wide /etc/paths file. It is the source of the base $PATH environment variable before ~/.profile, ~/.bash_profile and others get involved. If you're in a Terminal window, you can edit it with the following command:
sudo open -t /etc/paths
By default it contains the following paths:
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
I wouldn't recommend editing this file, however, because it is system-wide and will affect every user on the system.
If you want complete control over $PATH, so as to affect only your own account you're probably better off just not including $PATH in your .profile's export PATH lines. For example (but not this):
export PATH=/Applications/mamp/bin/php5.5.3/bin:/opt/local/bin:/opt/local/sbin
Are you sure .profile is being loaded? Try a test and add an echo line to it:
echo "test: .profile has loaded"
Now open a new terminal window, do you see your echo? I suspect not as I don't think OSX loads .profile by default, at least today.
If you really want to use .profile you can ask .bash_profile to load it:
if [ -f ~/.profile ]; then
source ~/.profile
fi
Hope this helps.
Edit:
Looks like .profile is loaded, if no .bash_profile or .bash_login exist as suggested in this answer
I'm running PHP with MAMP on OSX 10.5.8
So if I want to run a script from console I always need to write
/applications/mamp/bin/php5.3/bin/php path/to/script
which is annoying. Is there a way to change the default path to php so that I can write
php path/to/script
and still uses MAMPs PHP version?
Create a file called .bash_profile on your home directory (if you don't have this file already), and add this to the file:
export PATH=/Applications/mamp/bin/php5.3/bin:$PATH
Then quit and relaunch Terminal.app
Use latest MAMP version of PHP
you need to edit .bash_profile
open -a TextEdit ~/.bash_profile
if you cannot find bash_profile under your home directory then create .bash_profile:
touch ~/.bash_profile
Use latest MAMP version of PHP
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH
(Run source ~/.bash_profile after making your changes to make sure they take effect.)
source: How to override the path of PHP to use the MAMP path?
The easiest way would be to rewrite the alias. Just copy/paste the cmd bellow into terminal for temporary use or write it into .bash_profile to make it permanent.
For MAMP
$ alias php=/applications/mamp/bin/php5.3/bin/php
For XAMPP
$ alias php=/Applications/XAMPP/bin/php
For AMPPS
$ alias php=/Applications/AMPPS/php-5.6/bin/php
Run php via our new alias
$ php -v
vi ~/.bash_profile
//add
export PATH=/path/to/php/bin:$PATH
source ~/.bash_profile
In addition to bfvarettos great answer: since .bash_profile executes at login, you will need to restart your system for the changes to take effect.
I'm not sure if this is specific to MAMP 3.0 or not but you need to do the following path for MAMP 3.0. Make sure you change the PHP version to the version you are using for your server.
Again this goes in ~/.bash_profile
export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH
I would like to use MAMP's version of PHP instead of the default installed on my mac. I tried using
ln -s /Applications/MAMP/bin/php5.3/bin/php php
but I get a "File exists" error. What's the best way to work around this so I can just type php instead of the full path?
I have created a symlink at the original php location.
1. Locate your osx php version with:
which php
The result should be:
/opt/local/bin/php
2. Backup (move) your original php binary:
sudo mv /opt/local/bin/php /opt/local/bin/php.bak
3. Create the symlink:
sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /opt/local/bin/php
4. Run your new php version:
php -v
PS:
In order for this to work on El-Capitan
Reboot your Mac to RecoveryMode (hold Cmd+R on boot)
Open Terminal and enter: csrutil disable
Reboot
either : sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /opt/local/bin/php
or sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /usr/bin/php
Reboot again to RecoveryMode and re-enable security: csrutil enable
I would not recommend trying to modify the default version of PHP that is called on the command line. Doing so may break other parts of your system as well as provide you with problems in the future, should you decide to upgrade your OS.
There is an alternative that may meet your needs. You can create an alias to your copy of MAMP's php 5.3. In my case I named the alias phpmamp. Open your terminal and type:
alias phpmamp='/Applications/MAMP/bin/php5.3/bin/php'
Now, typing phpmamp at the command line will launch the MAMP php interperter. Verify this by typing:
phpmamp --help
You will most likely want to store this, and any other alias, in a ~/.bash_profile This will allow the aliases to persist across reboots. Otherwise, the alias should only last for the particular terminal session you are in. More information about creating a .bash_profile file can be found here:
http://www.redfinsolutions.com/redfin-blog/creating-bashprofile-your-mac
I prefer not to tamper with the current files, so I just prepend the MAMP PHP bin folder to the $PATH env variable.
You can edit ~/.bash_profile and add the the following line to the top
export PATH="/Applications/MAMP/bin/php/php5.6.1/bin:$PATH"
Just change the PHP version to the current version you are using.
Don't forget to do source ~/.bash_profile after you edit the file.
I wasn't pleased with the results / solutions I've found on the net so far, because the php.ini configs weren't loaded properly in all cases and on all systems, espacially when you need modules like ioncube and others (it's even more confusing on MAMP Pro). That's why I've created my own php version aliases (with configs), so I've come up with the following solution, as example (based on MAMP Pro, remember to adjust the php.ini paths to your needs):
Edit your .bash_profile
vim ~/.bash_profile
And add the following entries:
alias php55="/Applications/MAMP/bin/php/php5.5.26/bin/php -c '/Library/Application Support/appsolute/MAMP PRO/conf/php5.5.26.ini'"
alias php56="/Applications/MAMP/bin/php/php5.6.10/bin/php -c '/Library/Application Support/appsolute/MAMP PRO/conf/php5.6.10.ini'"
alias php56cgi="/Applications/MAMP/bin/php/php5.6.10/bin/php-cgi -c '/Library/Application Support/appsolute/MAMP PRO/conf/php5.6.10.ini'"
Re-Initialize the .bash_profile in the current terminal session (otherwise you won't see any changes, unless you restart the terminal):
source ~/.bash_profile
If you have some additional modules installed, then you can test it with php56 -v and you should get a output of the ioncube, etc. modules. Otherwise test it with php56 -i | grep "yourModuleNameOrSomethingElse"
Now you are able to easily use one of the php versions like "php56" in your terminal with all configs loaded. So it's perfect for testing and building your applications through all iterations of versions including the right php.ini configs through the terminal.
For normal MAMP Users, the configs should be located in /Applications/MAMP/conf/ I think. Happy programming.
2021 - For those using ohmyzsh, the file to edit is:
/Users/your_user/.zshrc
so, you can edit this file and add the path:
export PATH=/Applications/MAMP/bin/php/php8.0.0/bin:$PATH
Works Perfectly with Big Sur
The latest version of MAMP (Version 5+) offers an easy way to make the MAMP PHP version available to the command line. Just select "PHP" in the the side bar menu and check "Make this version available on the command line". Easy peasy! :)
screenshot
If your terminal is using zsh (oh-my-zosh) as shown in the attachment.
check image
Do the following.
Mac Big Sur uses "zsh" Oh-my-zosh for the terminal. so, I did the following.
open terminal.
check if you have .zshrc file in your profile path (/Users/yourProfileName)
if you don't have .zshrc file, create one using (~ touch .zshrc) command.
add these lines:
export MAMP_PHP=/Applications/MAMP/bin/php/php7.4.12/bin
export PATH="$MAMP_PHP:$PATH"
save the file. close the terminal and reopen it. Now run "which php".
let me know if you need help.
For Mac OS Catalina. Find directory /Users/<user_name>/.zprofile
and add (for example)
# MAMP PRO PHP
export PATH="/Applications/MAMP/bin/php/php7.4.2/bin:$PATH"
after reboot, in terminal
which php
new php version /Applications/MAMP/bin/php/php7.4.2/bin/php
Well, the 'file exists' error is probably because you attempted to create a sym-link with the name of a file that was already there. I assume you were in the directory containing the php version you were trying to replace or that this was a second attempt and you did not first remove the existing sym-link. I agree with the others with regard to not "replacing/modifying" the default version of php.
Based on the second part of the question, the best way to get around having to type the full path, the answers suggesting an alias are right on point with that. When multiple versions are involved though, that means having to call something other than php to run the version you want to run.
I have a script that lets me "select" the version of php that I would like to work with which then creates a sym-link to that version and lets me simply enter 'php' as my command when I want to use it. I wrote a blog about it here where you can get the script. Based on the answer given by #ioCron I may need to revisit my script to account for the different config folders associated with each version.
Well none of this was working for me with OSX10.12.5
i have mac ports php70 installed at /opt/local/bin
which php showed:
/usr/bin/php
I set up the aliases and local paths etc, which mostly worked for me, but other programs were failing (like composer) so the solution for me was to prepend:
/opt/local/bin
/opt/local/sbin
to the file /etc/paths
then it all worked a charm!