MacOSX has built-in Apache and PHP, which is very convenient to use. This article takes MacOSX10.6.3 as an example. The main content includes: start Apache, run PHP, install MySQL, and use phpMyAdmin to configure the MCrypt extension library of PHP to set the virtual host to start Apache. There are two methods: Enable System Preferences (SystemPreferences )-
Mac OS X has built-in Apache and PHP, which is very convenient to use. This article takes Mac OS X 10.6.3 as an example. The main content includes: start Apache, run PHP, install MySQL, and use phpMyAdmin to configure the MCrypt extension library of PHP to set the virtual host to start Apache. There are two methods: Enable System Preferences (System Preferences )-
Mac OS X has built-in Apache and PHP, which is very convenient to use. This article takes Mac OS X 10.6.3 as an example. The main content includes:
- Start Apache
- RunPHP
- Install MySQL
- Use phpMyAdmin
- Configure the MCrypt extension library of PHP
- Set VM
Start Apache
There are two methods:
- Choose System Preferences> Sharing> Web Sharing )"
- Open terminal, and then
- Run"
sudo apachectl start
", And then enter the account password so that Apache canRun.
- Run"
sudo apachectl -v
", 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
In this way, enter "http: // localhost" in the browser, and you can see that the content is "It works !" Is located under "/Library (resource Library)/WebServer/Documents/", which is the default root directory of Apache.
NOTE: If Apache is enabled, "Web Sharing" is enabled, and connected users access "/Library (resource Library)" through "http: // [local IP address) /WebServer/Documents/"directory, through" http: // [local IP address]/~ [User name] to access the "/Users/[user name]/Sites/" directory. You can set "Firewall" in "Security" of "system preference settings) to prohibit such access.
RunPHP
- In the terminalRun"
sudo vi /etc/httpd.conf
Open the Apache configuration file. (If you are not familiar with operating terminal and vi, you can set to display all system hidden files in the Finder. Remember to restart the Finder so that you can find the corresponding file and edit it as you like, note that you need to enable the root account to modify some files, but it is safer to use sudo on the terminal to temporarily obtain the root permission .)
- Find"
#LoadModule php5_module libexec/apache2/libphp5.so
", Remove the # sign, save and exit vi.
- Run"
sudo cp /etc/php.ini.default /ect/php.ini
", You can use php. ini to configure various PHP functions. For example:The following two items are used to adjust the maximum value of the submitted PHP file. For example, the maximum value of data imported in phpMyAdmin is upload_max_filesize = 2Mpost_max_size = 8 M; for example, display_errors is used to control whether to display the error display_errors = Off of the PHP program.
- Run"
sudo apachectl restart
", Restart Apache, so that PHP can be used.
- Run"
cp /Library/WebServer/Documents/index.html.en /Library/WebServer/Documents/info.php
Copy the index.html. en file in the apacheroot directory and rename it info. php.
- In the terminalRun"
vi /Library/WebServer/Document/info.php
In this way, you can edit the info. php file in vi. In "It's works !" Add "" and save it. In this way, you can see information about php in http: // localhost/info. PHP, for example, the version number is 5.3.1.
Install MySQL
Because MySQL is not pre-installed in Mac OS X, you need to manually install it. Currently, the most stable MySQL version is 5.1. MySQL provides installation instructions for Mac OS X.
- Download MySQL 5.1. Select the appropriate version, for example, the mysql-5.1.46-osx10.6-x86_64.dmg here.
- RunDmg, you will find four files in it. First click Install mysql-5.1.46-osx10.6-x86_64.pkg, This is the MySQL main installation package. Generally, the installation file automatically installs MySQL to a folder with the same name under/usr/local. For example, clickRunMysql-5.1.46-osx10.6-x86_64.dmg will install MySQ to
/usr/local/mysql-5.1.46-osx10.6-x86_64
. The installation is complete by default.
- Click to install the 2nd file MySQLStartupItem. pkg, so that MySQL will automatically start at startup.
- Click to install MySQL 3rd files. prefPane. In this way, the ICON "MySQL" is displayed in "system setting Preferences". Through this ICON, you can set whether to start or stop MySQL and whether to automatically start MySQL.Run. MySQL is basically installed.
- PassRun"
sudo vi /etc/bashrc
", Add it to the bash configuration filemysql
Andmysqladmin
Alias#mysqlalias mysql='/usr/local/mysql/bin/mysql'alias mysqladmin='/usr/local/mysql/bin/mysqladmin'
In this way, you can simply perform operations through commands on the terminal, suchroot
The default password is blank. If you want to set a password, you canRun"mysqladmin -u root password "mysqlpassword"
Mysqlpassword is the root password. For more information, see B .5.4.1. How to Reset the Root Password.
Use phpMyAdmin
PhpMyAdmin is a MySQL management program developed with PHP. It is very popular and practical. Using phpMyAdmin to manage MySQL is a very effective way to verify the results of the previous steps.
- Download phpMyAdmin. Select the desired version, for example, phpmyadmin-3.3.2-all-languages.tar.bz2.
- Copy the phpMyAdmin-3.32-all-languages folder in downloads to
/Users/[user name]/Site
In "s", the name is changed to phpmyadmin.
- Copy"
/Users/[user name]/Sites/phpmyadmin/
"Config. sample. inc. php, and name it config. inc. php.
- Open config. inc. php and make the following changes:
For Cookie encryption, the arbitrary long string $ cfg ['blowfish _ secret'] = ''; when" #2002 cannot log on to MySQL Server "appears in phpMyAdmin, change localhost to 127.0.0.1. This is because the MySQL daemon has bound IP addresses (bind-address = 127.0.0.1) $ cfg ['servers'] [$ I] ['host'] = 'localhost'; change false to true, so that you can access MySQL without a password, even if the MySQL password is set, you can set it like this, and then enter the password $ cfg ['servers'] [$ I] ['allownopassword'] = false when logging on to phpMyAdmin;
- In this way, you can use
Http: // localhost /~ [User name]/phpmyadmin
Access phpMyAdmin. At this time, you will see a prompt saying "The mcrypt extension cannot be loaded. Please check your PHP configuration .", This involves installing the MCrypt extension in the next section.
Configure the MCrypt extension of PHP
MCrypt is a powerful extension library for encryption algorithms. It includes 22 algorithms. phpMyAdmin depends on this PHP extension library. However, it is not so friendly to install on Mac OS X, as follows:
- Download and decompress libmcrypt-2.5.8.tar.bz2.
- Run the following command on the terminal:
cd ~/Downloads/libmcrypt-2.5.8/./configure --disable-posix-threads --enable-staticmakesudo make install
- Download and decompress the PHP source code file php-5.3.1.tar.bz2. In Mac OS X 10.6.3, the pre-installed PHP version is 5.3.1, and the latest PHP version is 5.3.2. You need to select the corresponding version based on your actual situation.
- Run the following command on the terminal:
cd ~/Downloads/php-5.3.1/ext/mcryptphpize./configuremakecd modulessudo cp mcrypt.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
- Open php. ini
sudo vi /etc/php.ini
Add the following code to php. ini, save the code, exit, and restart Apache.
extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so
When you accessHttp: // localhost /~ [User name]/phpmyadmin
You will find that "the mcrypt extension cannot be loaded. Please check your PHP configuration ." The prompt "no" indicates that the MCrypt extension library has been successfully installed.
Set VM
- On the terminalRun"
sudo vi /etc/apache2/httpd.conf
Open the Apche configuration file.
- In httpd. conf, find"
#Include /private/etc/apache2/extra/httpd-vhosts.conf
", Remove the previous" # ", save and exit.
- Run"Sudo apachectl restart". After Apache is restarted, its VM configuration function is enabled.
- Run"Sudo vi/etc/apache2/extra/httpd-vhosts.conf" opens the file httpd-vhost.conf for configuring the VM and configuring the VM you need. Note that two virtual hosts are enabled for this file 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. when no other virtual hosts are configured, the following prompt may appear when accessing localhost:
ForbiddenYou don't have permission to access /index.php on this server
The simplest way is to add # 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 and 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, so that you can access it with" http: // sites ", its content and" http: // localhost /~ [User name] "is completely consistent.
This is a configuration that is supported by Mac OS x 10.6.3. For more information, see "Mac OS X Leopard: Configure Apache, PHP, SQLite, MySQL, and phpMyAdmin (1) "and" Mac OS X Leopard: Configure Apache, PHP, SQLite, MySQL, and phpMyAdmin (2 )". In fact, you can also use an integrated solution provided by a third party such as XAMPP or MacPorts for simple installation and use.