In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This is an article on configuring php+mysql+apache under mac os in super detail. Very detailed
Most of my configuration is based on the above, for example, PHP can't connect to the database, just change the default pdo_mysql.default_socket in php.ini [because PDO is now used. Do not use the mysql connection library]
Because I use navicat, I don't care much about the configuration of phpmyadmin. However, the installation of MCrypt can be referred to.
Mac OS X has built-in Apache and PHP, which is very easy to use. This paper takes Mac OS X 10.6.3 as an example. The main contents include:
Start Apache
Run PHP
Install MySQL
Use phpMyAdmin
Configure the MCrypt extension library for PHP
Set up a virtual host
Start Apache
There are two ways:
Open system Settings preferences (System Preferences)-> sharing (Sharing)-> Web sharing (Web Sharing)
Open the "terminal (terminal)" and then (Note: the password required by sudo is the root account password of the system)
Run "sudo apachectl start" and enter the account password so that Apache runs.
Run "sudo apachectl-v" and you will see the Apache version number in Mac OS X 10.6.3:
Server version: Apache/2.2.14 (Unix) Server built: Feb 11 2010 14:40:31
So type "http://localhost"" in the browser, and you can see that a content appears as "It works!" Which is located under "/ Library (repository) / WebServer/Documents/", which is the default root directory for Apache.
Note: when Apache is enabled, "Web sharing" is enabled, and networked users will access the / Library (resource library) / WebServer/Documents/ directory through "http://[ local IP] /" and access the "/ Users/ [user name] / Sites /" directory through "http://[ local IP] / ~ [user name]". You can disable this access by setting Firewall (Firewall) in Security (Security) of system preferences.
Run PHP
Run "sudo vi / etc/apache2/httpd.conf" in the terminal to open the configuration file for Apache. (if you are not used to operating the terminal and vi, you can set up to show all system hidden files in Finder, remember to restart Finder, so that you can find the corresponding files and edit them at will, but it should be noted that some file changes need to open the root account, but on the whole, it is safer to use sudo on the terminal to get root permissions temporarily. )
Find "# LoadModule php5_module libexec/apache2/libphp5.so", remove the previous #, save (enter: W on the command line) and exit vi (enter: Q on the command line).
Run "sudo cp / etc/php.ini.default / etc/php.ini" so that you can configure various PHP functions through php.ini. For example:
Adjust the maximum value of the PHP submission file by the following two items, such as the maximum value of imported data in phpMyAdmin upload_max_filesize = 2m post_max_size = 8m; for example, through display_errors to control whether to display the error report of the PHP program display_errors = Off
Run "sudo apachectl restart" and restart Apache so that PHP can be used.
Run "cp / Library/WebServer/Documents/index.html.en / Library/WebServer/Documents/info.php", that is, copy the index.html.en file in the root directory of Apache and rename it to info.php
Run "vi / Library/WebServer/Document/info.php" in the terminal so that you can edit the info.php file in vi. In "It's works!" Add "" after it, and then save it. This allows you to see information about PHP in http://localhost/info.php, such as version 5.3.1.
Install MySQL
Since MySQL is not pre-installed in Mac OS X, you need to install it manually. Currently, the most stable version of MySQL is 5.1. MySQL provides installation instructions under Mac OS X.
Download MySQL 5.1. Choose the appropriate version, for example, mysql-5.1.46-osx10.6-x86_64.dmg here.
Run dmg and you will find that there are four files in it. First click to install mysql-5.1.46-osx10.6-x86_64.pkg, which is the main installation package for MySQL. In general, the installation file automatically installs MySQL to a folder with the same name under / usr/local. For example, clicking to run "mysql-5.1.46-osx10.6-x86_ 64.dmg" will install MySQ into "/ usr/local/mysql-5.1.46-osx10.6-x86_64". It can be installed by default all the way.
Click to install the second file, MySQLStartupItem.pkg, so that MySQL will start automatically when you boot.
Click to install the third file, MySQL.prefPane, and you will see an ICON called "MySQL" in system setup preferences, which allows you to set whether MySQL starts or stops, and whether it runs automatically when you boot. At this point, MySQL is basically installed.
Add aliases for mysql and mysqladmin to the configuration file of bash by running "sudo vi / etc/bashrc"
# mysql alias mysql='/usr/local/mysql/bin/mysql' alias mysqladmin='/usr/local/mysql/bin/mysqladmin'
In this way, it is relatively simple to perform the corresponding operation through the command in the terminal. For example, after installation, the root default password of MySQL is empty. If you want to set the password, you can run "mysqladmin-u root password" mysqlpassword "on the terminal, where mysqlpassword is the password of root. For more information, please refer to B.5.4.1. How to Reset the Root Password .
Note: upgrade of Mac OS X or other reasons may cause MySQL to start or boot automatically. "Warning:The / usr/local/mysql/data directory is not owned by the 'mysql' or' _ mysql'" will be prompted on the operator panel of MySQL, or "Can't connect to local MySQL server through socket'/ tmp/mysql.sock' (2)" on the command line. This should cause the host of / usr/local/mysql/data to change under some circumstances, just run "sudo chown-R mysql/ usr/local/mysql/data".
In addition, using PHP to connect to MySQL may report an error "Can't connect to local MySQL server through socket'/ var/mysql/mysql.sock'", or 127.0.0.1 may not be able to connect to MySQL using localhost, because php defaults to / var/mysql/mysql.sock when connecting, but the MAC version of MYSQL has changed the location of the file and put it under / tmp. The solution is to modify the php.ini as follows:
Mysql.default_socket = / tmp/mysql.sock
Use phpMyAdmin
PhpMyAdmin is a program developed with PHP to manage MySQL, which is very popular and practical. Being able to use phpMyAdmin to manage MySQL is a very effective way to verify the results of the previous steps.
Download phpMyAdmin. Choose the right version, for example, I chose the phpMyAdmin-3.3.2-all-languages.tar.bz2 version.
Copy the phpMyAdmin-3.32-all-languages folder in "download (downloads)" to "/ Users/ [user name] / Sites" and rename it to phpmyadmin.
Copy the config.sample.inc.php in "/ Users/ [user name] / Sites/phpmyadmin/" and name it config.inc.php
Open config.inc.php and make the following changes:
For Cookie encryption, the random long string $cfg ['blowfish_secret'] =''; when "# 2002 cannot log in to MySQL server" appears in phpMyAdmin, please change localhost to 127.0.0.1 and ok. This is because the MySQL daemon binds IP (bind-address = 127.0.0.1) to $cfg ['Servers'] [$I] [' host'] = 'localhost' Change false to true so that you can access the MySQL without a password, even if the password is set for MySQL, and then enter the password $cfg ['Servers'] [$I] [' AllowNoPassword'] = false when logging in to phpMyAdmin.
This allows you to access phpMyAdmin through the http://localhost/~[ user name] / phpmyadmin. At this point, you see a message, "unable to load the mcrypt extension, please check your PHP configuration." Which involves installing the MCrypt extension in the next section
Configure MCrypt extensions for PHP
MCrypt is a powerful encryption algorithm extension library, it includes 22 algorithms, phpMyAdmin relies on this PHP extension library. But its installation under Mac OS X is not so friendly, as follows:
Download and extract the libmcrypt-2.5.8.tar.bz2.
Execute the following command on the terminal (note that the following command requires xcode support to be installed):
Cd ~ / Downloads/libmcrypt-2.5.8/. / configure-- disable-posix-threads-- enable-static make sudo make install
Download and extract the PHP source file php-5.3.1.tar.bz2. The pre-installed PHP version in Mac OS X 10.6.3 is 5.3.1, but now the latest PHP version is 5.3.2. You need to choose the corresponding version according to your actual situation.
Execute the following command on the terminal:
Cd ~ / Downloads/php-5.3.1/ext/mcrypt phpize. / configure make cd modules sudo cp mcrypt.so / usr/lib/php/extensions/no-debug-non-zts-20090626/ Open php.inisudo vi / etc/php.ini
Add the following code to php.ini, save it, exit, and then restart Apache
Extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so
When you visit the http://localhost/~[ user name] / phpmyadmin, you will find that "the mcrypt extension cannot be loaded, please check your PHP configuration." Is gone, which means that the MCrypt extension library is installed successfully.
Set up a virtual host
Run "sudo vi / etc/apache2/httpd.conf" on the terminal to open the configuration file of Apche
Find "# Include / private/etc/apache2/extra/httpd-vhosts.conf" in httpd.conf, remove the previous "#", save and exit.
Run "sudo apachectl restart" and restart Apache to turn on its virtual host configuration function.
Run "sudo vi / etc/apache2/extra/httpd-vhosts.conf", which opens the file httpd-vhost.conf that configures the virtual host and configures the virtual host you need. It should be noted that this file opens two virtual hosts as examples by default:
ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/ usr/docs/dummy-host.example.com" ServerName dummy-host.example.com ErrorLog "/ private/var/log/apache2/dummy-host.example.com-error_log" CustomLog "/ private/var/log/apache2/dummy-host.example.com-access_log" common ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "/ usr/docs/dummy-host2.example.com" ServerName dummy-host2.example.com ErrorLog "/ private/var / log/apache2/dummy-host2.example.com-error_log "CustomLog" / private/var/log/apache2/dummy-host2.example.com-access_log "common
In fact, these two virtual hosts do not exist, and when no other virtual hosts are configured, it may result in the following prompt when accessing localhost:
Forbidden You don't have permission to access / index.php on this server
The easiest way is to put a # in front of each line and comment it out so that it can be referenced without causing other problems.
Add the following configuration
DocumentRoot "/ Users/ [user name] / Sites" ServerName sites ErrorLog "/ private/var/log/apache2/sites-error_log" CustomLog "/ private/var/log/apache2/sites-access_log" common
Save the exit and restart Apache.
Run "sudo vi / etc/hosts", open the hosts configuration file, and add "127.0.0.1 sites" so that you can configure the sites virtual host and access it with "http://sites"", which is exactly the same as the "http://localhost/~[ user name].
This configuration is implemented using the native support in Mac OS X 10.6.3. You can also refer to "Mac OS X Leopard: configuring Apache, PHP, SQLite, MySQL, and phpMyAdmin (1)" and "Mac OS X Leopard: configuring Apache, PHP, SQLite, MySQL, and phpMyAdmin (2)". In fact, you can also use third-party integration solutions such as XAMPP or MacPorts for simple installation and use.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.