Run Apache + PHP + MySQL in MacOSX

Source: Internet
Author: User
Tags mcrypt zts
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:

  1. Start Apache
  2. RunPHP
  3. Install MySQL
  4. Use phpMyAdmin
  5. Configure the MCrypt extension library of PHP
  6. Set VM
Start Apache

There are two methods:

  1. Choose System Preferences> Sharing> Web Sharing )"
  2. Open terminal, and then
    1. Run"sudo apachectl start", And then enter the account password so that Apache canRun.
    2. 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
  1. In the terminalRun"sudo vi /etc/httpd.confOpen 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 .)
  2. Find"#LoadModule php5_module libexec/apache2/libphp5.so", Remove the # sign, save and exit vi.
  3. 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.
  4. Run"sudo apachectl restart", Restart Apache, so that PHP can be used.
  5. Run"cp /Library/WebServer/Documents/index.html.en /Library/WebServer/Documents/info.phpCopy the index.html. en file in the apacheroot directory and rename it info. php.
  6. In the terminalRun"vi /Library/WebServer/Document/info.phpIn 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.

  1. Download MySQL 5.1. Select the appropriate version, for example, the mysql-5.1.46-osx10.6-x86_64.dmg here.
  2. 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.
  3. Click to install the 2nd file MySQLStartupItem. pkg, so that MySQL will automatically start at startup.
  4. 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.
  5. PassRun"sudo vi /etc/bashrc", Add it to the bash configuration filemysqlAndmysqladminAlias
    #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, suchrootThe 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.

  1. Download phpMyAdmin. Select the desired version, for example, phpmyadmin-3.3.2-all-languages.tar.bz2.
  2. Copy the phpMyAdmin-3.32-all-languages folder in downloads to/Users/[user name]/SiteIn "s", the name is changed to phpmyadmin.
  3. Copy"/Users/[user name]/Sites/phpmyadmin/"Config. sample. inc. php, and name it config. inc. php.
  4. 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;
  5. In this way, you can useHttp: // localhost /~ [User name]/phpmyadminAccess 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:

  1. Download and decompress libmcrypt-2.5.8.tar.bz2.
  2. Run the following command on the terminal:
    cd ~/Downloads/libmcrypt-2.5.8/./configure --disable-posix-threads --enable-staticmakesudo make install
  3. 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.
  4. 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/
  5. 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]/phpmyadminYou 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
  1. On the terminalRun"sudo vi /etc/apache2/httpd.confOpen the Apche configuration file.
  2. In httpd. conf, find"#Include /private/etc/apache2/extra/httpd-vhosts.conf", Remove the previous" # ", save and exit.
  3. Run"Sudo apachectl restart". After Apache is restarted, its VM configuration function is enabled.
  4. 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.

  5. 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.

  6. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.