Solution to the problem that mac cannot be used after upgrading php: 1. Set the time zone of php.ini; 2. Find ";date.timezone=" and change it to "date.timezone = Asia/Shanghai"; 3. Start the myql service; 4. Configure rewrite.
The operating environment of this tutorial: macOS10.12.5 system, PHP version 8.1, macbook pro 2020 computer.
What should I do if my mac cannot be used after upgrading php?
Solution to the problem that the PHP environment cannot be used after upgrading the mac system
I upgraded the mac system, but the PHP environment cannot be used:
sudo apachectl start
Access localhost and show that it works. . Okay, apache can be used.
I can’t access localhost/abs (phpmyadmin’s renamed directory), what should I do?
When accessing the previous project localhost/ddz, it shows “not found”. It should be an apache upgrade. The previous The settings have been reset.
http://www.cnblogs.com/wanggs/p/5042206.html
http://blog.chinaunix.net/uid-1861701-id-86891.html
After upgrading the mac system, the configuration of mac's own php apache mysql is reset:
1. Change the configuration of apache's httpd.conf to point to the custom website root directory
sudo vi /etc/apache2/httpd.conf
Find the #LoadModule php5_module libexec/apache2/libphp5.so item, remove the # number from its header
Find the DocumentRoot "/Library/WebServer/Documents" and change it to DocumentRoot "/Users/zhangwei/wwwroot "
Find Directory"/Library/WebServer/Documents" and change it to Directory "/Users/zhangwei/wwwroot"
sudo apachectl restart
At this point, you can access the previous php project, but localhost/abs (phpmyadmin access address) can be opened, but cannot enter mysql
1. Set the time zone of php.ini
sudo cp /etc/php.ini.default /etc/php.ini chmod -R 775 /etc/php.ini vi /etc/php.ini
2. Find; date.timezone = change to date.timezone = Asia/Shanghai
sudo apachectl restart
3. Start the myql service:
Find mysql in the system preferences, click Start MYSQL Server, or use the command line to start:
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
OK, mysql is done.
rewrite is not configured, so the thinkphp framework project cannot access
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so Remove the preceding
#Allowoverride None and change None to All
sudo apachectl restart
#Save, exit and restart apache. The PHP environment should be ready to use. [Recommended learning: "PHP Video Tutorial"]
If the above does not solve the problem, please see the detailed steps below:
1. Start Apache
1. The Mac OS However, in the new version of Mac OS X, Apple has canceled the graphical interface for this sharing function and can only be enabled from the command line.
Enter the command in the terminal to start Apache: sudo apachectl start
Shut down Apache: sudo apachectl stop
Restart Apache: sudo apachectl restart
Check the Apache version: httpd -v
After enabling Apache, Accessing http://localhost or http://127.0.0.1 in the browser means it is running normally.
2. Root directory
1. By default, there are two directories in OS X that can directly run your Web program. One is the system-level Web root directory and the other is the user-level root directory. Remember Just download it.
Note: The following haibor is the user name and needs to be modified according to the actual situation.
The Apache system-level root directory and corresponding URL are:
/Library/WebServer/Documents/ http://localhost
The user-level root directory and corresponding URL are:
~/Sites http://localhost/~haibor/
~/Sites is the "site" directory under your user directory. In OS X, this directory may not exist, so you need to create one manually. Directory with the same name.
The establishment method is very simple, run it directly in the terminal: sudo mkdir ~/Sites
2. After creating the "site" folder, check /etc / Is there a file "haibor.conf" under the folder:
/etc/apache2/users/
If not, then you need to create one and name it "haibor.conf", you can Use one of the two editors vi or nano to create it.
sudo vi /etc/apache2/users/haibor.conf
After creation, write the following lines to the above conf file:
<Directory "/Users/haibor/Sites/"> Options Indexes MultiViews AllowOverride All Order allow,deny Allow from all </Directory>
3. After saving the file, give it the corresponding permissions: sudo chmod 755 /etc/apache2/users/haibor.conf
Next, restart Apache. To make the configuration file take effect: sudo apachectl restart
After that, you can access your user-level directory web page through the browser. You can check any web page and test it. . The root directory address is:
http://localhost/~haibor/
You can also change the root directory, but remember to set it for the new folder. The folder needs to have execution permission x. Set it to 755. OK: mkdir /Users/user/workspace chmod 755 /User/user/workspace
Replace /Library/WebServer/Documents/ in the /etc/apache2/httpd.conf file with your own path, such as /User/user/workspace
Restart Apache: apachectl restart, visit again localhost displays the contents of the changed file.
END
3. Start PHP
1. PHP version 5.4.30 has been integrated into OS X Mavericks and needs to be started manually. You can use vi or nano editor to open the following file: sudo nano /etc/apache2/httpd.conf
Then press ctl W to search for "php", The first matching line should be the following code:
LoadModule php5_module libexec/apache2/libphp5.so
Please remove the # in front of this code and save the file.
Next, restart Apache again: sudo apachectl restart
Now PHP should have started working, you can start in the user-level root directory (~/ Sites/) put a PHP test file, the code is as follows:
END
4. Install MySQL
1 OS X Mavericks Mysql is not integrated and needs to be installed manually.
You can click http://dev.mysql.com/downloads/mysql/ to download the MySQL installation package from the official website.
Please download Mac OS X 10.7 (x86, 64-bit), DMG Archive (if there is a newer version, you can download it).
After downloading the DMG, double-click and you will extract three files and a RedMe.txt document. These three files are:
mysql-5.6.15-osx10.7-x86_64.pkg
MySQLstartupitem.pkg
MySQL.PrefPane
You need to install these three files one by one. After MySQLStartupItem.pkg is installed, mysql will start automatically when the system starts. MySQL.prefPane indicates that you can see the mysql option in the system preferences, and there is also a mysql installation item.
2. After the three files are installed, enter "System Preferences". At the bottom of the panel you will see a MySQL setting item. Click it to start MySQL.
You can also start mysql through the command: sudo /usr/local/mysql/support-files/mysql.server start
If you want to view MySQL version, you can use the following command:
/usr/local/mysql/bin/mysql -v
After running the above command, you will log in to MySQL directly from the command line, enter the command \q that is Can exit.
At this point MySQL has been configured and can run.
3. In order to make it more convenient to use, it is best to set the system environment variables, that is, the mysql command can be started directly in any path (no need to enter a long list of accurate paths).
It is also very convenient to set environment variables. You can use the command directly (here I use the vi editor as an example): cd
vi .bash_profile
Then press the letter i to enter the editing mode, and paste the following code:
export PATH="/usr/local/mysql/bin:$PATH"
Then press esc to exit the editor. Then enter: wq (don’t forget the colon) to save and exit. Of course, if you use nano or other editors, the operation method may be different from this. Anyway, it means writing the above sentence into the .bash_profile file.
Next, you need to reload the Shell to make the above environment variables take effect:
source ~/.bash_profile
After that, you can use the mysql command in any directory of the terminal. You can try running mysql -v.
4. The last step. After installation, the default user name is root and the password is empty. You should also set a root user password for your MySQL. The command is as follows: mysqladmin -u root password 'Fill in the password you want to set here'
(Please remember that the password must be enclosed in half-width single quotes)
For the mysqladmin command above, I did not write the full path . Because we have set the environment variables above, if you have not set the environment variables, you need to use /usr/local/mysql/bin/mysqladmin ** to run.
END
5. Install phpMyAdmin or administrator
1. Before installing phpMyAdmin, please fix the 2002 socket error first: sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Then you can download the installation package from the phpMyAdmin official website. It is recommended to download english.tar.gz , you can also download all-languages.tar.gz to use the Chinese version. After decompressing, rename the decompressed folder to "phpmyadmin" and place it in the "Site" directory created above (~/Sites).
Then create a config folder under phpmyadmin:
Once you are done, you can then visit http://localhost/~haibor/phpmyadmin/
to pass phpmysql manages your database.
You can also use adminer to manage. It is very convenient to say that we recommend related articles: Adminer, a lightweight mainstream database web management tool.
END
6. Set up the virtual host
1. Configure the Apache file:
sudo vi /etc/apache2/httpd.conf
Find "#Include /private/etc/apache2/extra/httpd-vhosts.conf" in httpd.conf, remove the "#" in front, ":wq!" Save and exit.
Restart Apache: sudo apachectl restart
2. Configure the virtual host file httpd-vhost.conf
sudo vi /etc/apache2/extra/httpd-vhosts.conf
In fact, these two virtual hosts do not exist when no other virtual hosts are configured. , may cause the following prompt to appear when accessing localhost:
Forbidden You don't have permission to access /index.php on this server
The simplest way is to add # in front of each line, Just comment it out so that it can be referenced without causing other problems.
END
7. About php.ini
1. First make a copy of php.ini, and then you can configure various PHP functions through php.ini. sudo cp /etc/php.ini.default /etc/php.ini
For example, modify the three values of upload_max_filesize, memory_limit, post_max_size to adjust the maximum value of PHP submitted files , such as the maximum value of imported data in phpMyAdmin.
Composer installation:
http://www.phpcomposer.com/composer-the-new-age-of-dependency-manager-for-php/
The above is the detailed content of What should I do if my Mac cannot use PHP after upgrading it?. For more information, please follow other related articles on the PHP Chinese website!