I am trying to get an old Laravel 4.1.x app up and running again so that it can be modernized. This requires an environment with PHP 5.6 and the Mcrypt extension. I have installed Homestead 9.0.3 (the latest stable version). Within the VM, I have set the PHP version to 5.6
sudo update-alternatives --config php
I have then installed the php-mcrypt extension
sudo apt-get install php5.6-mcrypt
I am now able to create a new Laravel 4.1.x project, which is a process that requires Mcrypt to complete, so we're certainly getting somewhere:
composer create-project laravel/laravel="4.1.*" myAppName
However, when I browse to the webpage for myAppName, I see the message:
Mcrypt PHP extension required.
I have also tried steps that are usually recommended for this problem, ie:
sudo ln -s /etc/php/5.6/conf.d/mcrypt.ini /etc/php/5.6/mods-available/mcrypt.ini
sudo phpenmod mcrypt
sudo service php5.6-fpm restart
But I still get the same message in the browser.
What step have I missed?
With homestead v9 you should be up and running with php5.6 out of the box as stated in
here, but unfortunately it is not your case, and I understand that...
Old packages were not installed by default (php5.6-mcrypt), as you mentioned and they should be added by hand via:
sudo apt-get install php5.6-mcrypt
After that all packages are ready, up and working, especially php5.6-mcrypt.
The root of your problem is in multiple site definitions under your homestead.yaml.
Most probably some of them are overlapping and your nginx is referring to the wrong resource/site_definition, and wrong paths.
Therefore you might think some strange php versions or routes are run/executed.
You can verify that, by deleting some/all of them, leaving the only one important for you - in (/etc/nginx/sites-enabled/...).
Of course please do that inside the container and issue sudo service nginx restart, afterwards...
All of your problems should be gone after that.
If something goes wrong. You could easily recover your current installation to current state using vagrant destroy and vagrant up afterwards, cause all is saved in Homestead.yaml.
In my installation Homestead v9 is running with php5.6 on laravel 4.1 without any problems...
Hope it helps #jsm...
Because all the PHP versions installed on homestead you need to set the PHP version for a site in the Homestead.yaml.
First check what version the server is running with phpinfo();
Check the file /etc/nginx/sites-enabled/homestead.test and look for this line:
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
If you didn't set the php version on the sites list, this file will be pointing to the php7.3.sock.
In this case the version 5.6 has mcrypt installed, but 7.3 don't.
You can just replace the line
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
for
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
and then reload nginx with sudo nginx -s reload.
Or set the php version on Homestead.yaml:
sites:
- map: homestead.test
to: /home/vagrant/code/public
php: "5.6"
And then run vagrant provision, it will change the nginx configuration for PHP 5.6.
Related
The Short Version
Laravel application on Homestead is using PHP 8.x as seen in phpinfo(), yet php -v is stating the server is using 7.1 (which is what I want). How is this possible? How do I tell the Laravel application to use 7.1 not 8.x?
The Long Version
I have an older Laravel application (5.8) that I need to upgrade to 8.0. I may be using Shift to do this but I have never done an upgrade manually so I thought I should do that at least once.
So I upgraded Homestead to current (12.x), and everything continued to run fine.
Then I tried to upgrade my PHP version from 7.1 to 8.0 using sudo update-alternatives --config php and chose PHP. Then I verified with php -v that it switched to that version. As expected, I began getting deprecation errors in browser. Knowing I would have to spend some time resolving those I switched back to 7.1... but the errors remained!
I restarted PHP, I restarted the server, I reloaded and reprovisioned the server, I destroyed and reprovisioned the server and absolutely nothing is resolving this issue. I even specified php: "7.1" in the Homestead.yaml file and re-provisioned to no avail.
At this point it seems that the upgrading of Homestead itself is somehow telling PHP to ignore the version I'm specifying it to use. So I know I could downgrade, I suppose, but that isn't really a solution but a band aid. And I'm not certain that will actually work either.
I've tried the Answers in this StackOverflows Change Laravel Homestead v7.0.1 with php 7.2 to php 7.1 including php71.
OS: Windows 10
Homestead: 12.x
This person has an identical problem and resolved it with Docker somehow but I don't understand how to translate that to Homestead.
There is PHP-CLI and PHP-web. PHP-CLI version is what is reported when using php -v but PHP-CLI is what NGinx is using, hence getting 8.0 when using phpinfo() in ~/public/index.php
To resolve the issue I manually updated /etc/nginx/sites-enabled/mysite and edited line below location where it says fastcgi_pass unix:/var/run/php/php8.0-fpm.sock; to say fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; and then I restarted PHP with sudo systemctl restart nginx.
I need to run composer on my ddev project and don't have it on my Windows machine. For example, the project requires a composer install before startup. How can I use composer in this environment, especially on Windows?
Updated 2018-11-15 to show native ddev support (ddev composer command)
There are several ways to run composer for your project.
ddev v1.4.0 now has the ddev composer and ddev composer create commands. These run composer inside the container, so you're guaranteed to get composer behavior that matches the in-container hosting environment. (This matters most for Windows users.)
ddev composer require swiftmailer/swiftmailer
ddev composer update
ddev composer install
ddev composer create drupal-composer/drupal-project:8.x-dev --stability dev
Note that ddev composer create is not exactly the same as composer create-project so you don't have to understand complexities of the underlying filesystem. There are drupal and TYPO3 ddev composer create examples in the docs.
Nothing here prevents you from using any composer technique that you're comfortable with, but this is a great way to get predictable on-linux in-container composer builds. It should be hugely important for people using Windows OS, where composer is less available and has some unpredictable behavior.
Install on the host the old fashioned way: If composer is installed on your computer/host, just composer install. However, that only works on macOS and Linux, and only works if you have the right versions of php related components. It does not work well at all on Windows (NTFS) because the symlinks composer creates are not compatible with usage inside the (Linux) web container. (Composer is not hard to install on Windows: Use chocolatey and choco install -y composer. You'll want to enable the gd and curl extensions in c:\tools\php72\php.ini)
All the normal composer behavior has always been installed inside your web container, so you can use that whether or not you have composer on your host computer. For example: ddev exec composer install -d /var/www/html will do a composer install in the root of your repository, exactly the same as ddev composer install. You can also do ddev ssh and operate on the command line in the container.
Try this hooks approach to running composer install inside the container (on the mounted partition) every time your project starts:
hooks:
post-start:
- exec: composer install -d /var/www/html
For some older ideas on composer patterns (mostly obsoleted by ddev composer, See
How to: Use "composer create-project" and DDEV to start a new Drupal 8 site when Composer isn't installed on the host machine and
How to: Set up a D8/Composer site on Pantheon without CircleCI, custom upstreams
To expand on the accepted answer, DDEV now has a composer-specific hook.
hooks:
post-start:
- composer: install -d /var/www/html
The reason for using this instead of exec, I assume, is that there are also pre-composer and post-composer hooks, so maybe this also executes those hooks. I'm not sure of that or the actual difference, though.
I loaded up Laravel/Lumen on the new Homestead php7 box and encountered this error:
FatalThrowableError in MemcachedConnector.php line 51:
Fatal error: Class 'Memcached' not found
Doing a phpinfo(); shows there is no memcached extension, but sudo service memcached status says memcached is running. It seems there is a php7 branch for memcached here: https://github.com/php-memcached-dev/php-memcached/tree/php7
Can anyone guide me on how to get it working in the new php7 Homestead VM?
EDIT: I just saw on the homestead install documentation that it says "Memcached (PHP 5.x Only)". Question still remains on how to get it working.
The work on php-memcached for PHP7 is not yet complete, not all tests pass; You can use everything but JSON serialization, I think.
There is no pecl support for PHP7, so right now you need to install extensions manually, like this:
git clone https://github.com/php-memcached-dev/php-memcached
cd php-memcached
git checkout php7
phpize
./configure
make
sudo make install
You must make sure that phpize is the PHP7 version. Additionally, if the php in your PATH is not PHP7, then the php-config in your PATH is not either, in this case you must pass --with-php-config=/absolute/path/to/php7-config to ./configure.
I have the same problem, but on Windows when using XAMPP. It seems memcached works for now with PHP 5+ only.
The problem for Windows users is to find the right .dll file named
php_memcache.dll (x86/x64 platforms).
I've spent hours looking for a solution, but nothing found. The very fresh description how to use memcached is here:
HOW TO: Install Memcache on XAMPP (Windows 7/8/10)
We still have to wait for PHP7+ implementation.
I am trying to make a laravel and stucked when migration. when i enter php artisan migrate in terminal, showing PDOException error. attaching my screenshot of terminal and phpinfo.
What i sthis issue, How can i solve this,
I am using Xampp.
Anybody please help me.
Thanks
Try re-installing Xampp? You could use Laravel homestead for a virtual machine, it makes sure you have the proper PHP version and the required dependencies needed to install and avoids having to run Xampp or MAMP or WAMP or any of the amps.
It looks like Xampp cannot find: /usr/lib/php5/20121212/php_pdo_mysql.dll, so make sure that file exists.
You may need to re-install PHP PDO on your machine, refer to: http://php.net/manual/en/pdo.installation.php
Also per PHP docs:
PDO and all the major drivers ship with PHP as shared extensions, and
simply need to be activated by editing the php.ini file:
extension=php_pdo.dll
Please check you have installed more than one php version in your system, one is running for web server and another for php CLI, using PHP_INFO for web and php --ini in commandline, if different version found then upgrade or downgrade means make it one version configuration, and make sure PDO is enable in your system.
From php5.6 to php7.0:
Apache:
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
CLI:
sudo update-alternatives --set php /usr/bin/php7.0
From php7.0 to php5.6:
Apache:
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
CLI:
sudo update-alternatives --set php /usr/bin/php5.6
I've been following this tutorial to try to install the PHP MongoDB extension but unfortunately haven't been able to get it working.
http://www.marcwitteveen.com/tech/mac/installing-mongodb-on-a-mac-so-you-can-access-it-with-php/
I can access the collections in the terminal, the database is properly installed but I didn't manage to get the extension working.
I have the following problem:
Sinan-MBP:mongo-php-driver-master Sinan$ cd
Sinan-MBP:~ Sinan$ sudo pecl install mongo
pecl/mongo is already installed and is the same as the released version 1.4.1
install failed
I've been trying several times so that's probably why I get this message. However, even after adding "extension=mongo.so" to the php.ini, I can't use MongoDB in my PHP code.
Thank you for your help.
This is likely a case of modifying the wrong php.ini for the environment, or PHP not being able to find the mongo.so in its directory. If you have separate php.ini files for CLI and web environments, PECL might have installed the compiled extension to a different directory.
If you run through the installation docs, there are instructions for grepping extension_dir from php -i and ensuring that mongo.so is present in that directory. If your web environment has a separate php.ini file, then grepping output from php -i likely won't help. You may need to view phpinfo(); output through your web server and check for the extension directory there.
One additional test that PECL installation succeeded would be attempting to view reflection information for one of the driver classes from the CLI environment. You can do so with php --rc MongoClient, which should print info on the methods of the MongoClient class.
I don't know why it was not working but I found a workaround late last night.
I uninstalled the php extension and then installed it again and made sure the extension was loaded in the php.ini
sudo pecl uninstall mongo
sudo pecl install mongo