Local MAMP web server for Mac OS. Personal experience of Web development on Mac OS X Local server on Mac

In fact, there are a lot of articles about how to raise a local server (and here we will talk specifically about OS X). But as I was disappointed when I just wanted to use the instructions and not bother. I'm not a programmer, though.

I was not interested in any additional super cool all containing programs like MAMP. They will gobble up disk space for me and make a bunch of incomprehensible folders. I knew for sure that Linux-like OS X has almost everything in itself, you just need to know how to use it. But I didn't think I would be so lucky! And I will be able to bring up a local server in any folder (i.e. my project structure on disk will not be broken at all).

Here I will describe a small sequence of actions that allowed me to install Wordpress in one of my chosen (and not by the developers of the super programs mentioned above) folder. Of course, a local server is needed not only for WordPress, but I will describe specifically my case.

Initial data

To begin with, it should be noted that the instructions concern \u003e OS X 10.10 (Yosemite)... On versions below it will also most likely work, but I do not guarantee that everything is exactly the same (it depends on the system presets).

Now let's decide what needs to be installed in order for the local server to work. It depends on your goals:

  1. If you need a server for html layout (well, for example, for ajax, or to test how many requests your layout will send to the server), then you don't need to install anything at all. See the section “A Simple Python Web Server”.
  2. If you need to install WordPress, then you need to look at the requirements of this CMS. At the time that I installed WordPress, these are: PHP 5.4 and higher, MySQL 5.5 and higher, Apache module.

Instructions

1. Install everything you need for the server

Enter in the console:

type - a python

Should show something like this:

python is / usr / local / bin / python python is / usr / bin / python

The file will open, you need to find the line LoadModule php5_module libexec / apache2 / libphp5.so (the hotkey for finding text in vi is ?) and uncomment it (remove the # in front of the line).

MySQL is hardly installed. And then laziness comes into play. In order not to download, install or configure anything ourselves, we simply execute the script by entering in the console:

bash<(curl -Ls http://git.io/eUx7rg)

bash< (curl - Ls http : //git.io/eUx7rg)

I found this script. I checked that this self-written script did not do anything terrible with my poppy, everything is as promised. Namely, it does the following:

  • Checks if MySQL is installed on the system
  • Download the latest MySQL version
  • Sets the password for root, shows the password
  • Writes the password to a file on the desktop (it came in handy for me later, since of course I did not write down the password during installation)
  • Configures something, asks if you want to configure something else (I just answered no, I'm not interested and don't need it)
  • It offers to install the Sequel Pro program (database manager, useful thing). I answered yes and did not regret it.

Everything, now we reboot. And install WordPress wherever they look.

2. Raise the server and install WordPress

A simple Python web server

Remember that this option is only suitable for testing layout and other simple tasks, where nothing other than HTTP requests is needed. If you also need to install WordPress on the LAN, scroll down to the section below.

1. Open the console, go to the desired folder:

2. We type the command in the console: python -m SimpleHTTPServer

The console will display Serving HTTP on 0.0.0.0 port 8000 ...

Now we enter into the address bar of the browser http: // localhost: 8000 / some_your_file.html

Full-featured local server + WordPress

1. Go to the folder with the intended WordPress for the project:

2. Start the server with PHP support with the command php -S 127.0.0.1:8000

3. Open the Sequel Pro programs, enter the address, username and password, connect to our local server:

4. Create a new WordPress database in Sequel Pro.

5. Go to the address http: // localhost: 8000 / wp-admin / install.phpto start the installation.

Related links

How to use SimpleHTTPServer - a little about python server
Install MySQL on OS X 10.9 Mavericks - worked for Yosemite too

Hello Habr!

As a web developer who chose Mac OS X as my primary working tool, I faced the challenge of setting up the required environment. According to the long-term habit of working with Linux servers, hands reached out to the console to install everything, but they stopped - wait, wait, but why would I turn this OS into another Linux server? I have enough of this shamanism with the console on the servers, thanks. We will use built-in components as much as possible.

Web server

Apache comes preinstalled on Mac OS and is more than enough for local development.
A little trick - if you don't need a virtual host, then this trick helps a lot:
/etc/apache2/extra/httpd-userdir.conf
Options Indexes Order allow, deny Allow from all
It remains to throw the project into ~ / Sites /% project_name% and open in browser localhost / ~% user_name% /% project_name%
As a last resort, if you need a complete copy of the production environment, you can always install Vagrant.

PHP

PHP is preinstalled on Mac OS. If you are satisfied with its version, then just enable the loading of the module php5_module: /etc/apache2/httpd.conf
LoadModule php5_module libexec / apache2 / libphp5.so
If you are not satisfied, then you can install PHP according to the manual from php-osx.liip.ch. This version will not replace the system version, it will find Apache itself and generally install in / usr / local / php5... Installation is extremely simple - one line in the console (example for PHP 5.5):
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5

MySQL

There are several ways to install MySQL, for example, through Homebrew. But compile from MySQL source just because the package manager allows it? It seems to me that it's easier to take the DMG archive from the official site and install it. After installation, the MySQL tab will appear in System Preferences:

FTP / SFTP

In addition to working on the main project, you have to be distracted and fix / finish something for clients. Usually this is someone else's hosting with FTP access. So you need an FTP client. The choice fell on Cyberduck:




Why Cyberduck? Because it stores passwords in the Keychain, translated into Russian, is free and supports FTP, SFTP, WebDAV, Amazon S3, Google Cloud Storage and Rackspace Cloud Files.

MySQL client

For a long time I was choosing between MySQL Workbench and Sequel Pro. Sequel Pro won by lightness.

Why local application and not phpmyadmin or mysql in hosting console? Because all the supervised databases are in one place and it is not necessary to open the console, SSH and remember passwords for the task "look what is in the client's database". Yes, this is a remote connection and MySQL on the hosting looks outward. But access via IP or SSH tunnel saves the father of Russian democracy.
The program has a lot of possibilities, it is better to read on the official website.

Sublime text

Without it, nowhere. A little trick in the settings:
("open_files_in_new_window": false,)
By default it is set to TRUE and because of this Cyberduck opens new files in a new window instead of in a new tab of an existing window.

In addition, it happens that you need to quickly run a small piece of PHP code, but it is not convenient to do this in the IDE. It is possible to execute PHP code from Sublime Text by adding a new Build System ( Tools –> Build System -> New):
("cmd": ["php", "$ file"])
Now we press CMD + B and the result of the code will appear in the Sublime Text console.

Dash


This is a handy collection of documentation, here are its features:

  • Auto-update documentation from official sites
  • Offline access
  • Cheat Sheets
  • Creating your own snippets
  • Integration into PhpStorm and Sublime Text

Of course, you can still start singing praises to touch gestures and full screen mode of applications, but that is beyond the scope of this article.

Hello Habr!

As a web developer who chose Mac OS X as my primary working tool, I faced the challenge of setting up the required environment. According to the long-term habit of working with Linux servers, hands reached out to the console to install everything, but they stopped - wait, wait, but why would I turn this OS into another Linux server? I have enough of this shamanism with the console on the servers, thanks. We will use built-in components as much as possible.

Web server

Apache comes preinstalled on Mac OS and is more than enough for local development.
A little trick - if you don't need a virtual host, then this trick helps a lot:
/etc/apache2/extra/httpd-userdir.conf
Options Indexes Order allow, deny Allow from all
It remains to throw the project into ~ / Sites /% project_name% and open in browser localhost / ~% user_name% /% project_name%
As a last resort, if you need a complete copy of the production environment, you can always install Vagrant.

PHP

PHP is preinstalled on Mac OS. If you are satisfied with its version, then just enable the loading of the module php5_module: /etc/apache2/httpd.conf
LoadModule php5_module libexec / apache2 / libphp5.so
If you are not satisfied, then you can install PHP according to the manual from php-osx.liip.ch. This version will not replace the system version, it will find Apache itself and generally install in / usr / local / php5... Installation is extremely simple - one line in the console (example for PHP 5.5):
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5

MySQL

There are several ways to install MySQL, for example, through Homebrew. But compile from MySQL source just because the package manager allows it? It seems to me that it's easier to take the DMG archive from the official site and install it. After installation, the MySQL tab will appear in System Preferences:

FTP / SFTP

In addition to working on the main project, you have to be distracted and fix / finish something for clients. Usually this is someone else's hosting with FTP access. So you need an FTP client. The choice fell on Cyberduck:




Why Cyberduck? Because it stores passwords in the Keychain, translated into Russian, is free and supports FTP, SFTP, WebDAV, Amazon S3, Google Cloud Storage and Rackspace Cloud Files.

MySQL client

For a long time I was choosing between MySQL Workbench and Sequel Pro. Sequel Pro won by lightness.

Why local application and not phpmyadmin or mysql in hosting console? Because all the supervised databases are in one place and it is not necessary to open the console, SSH and remember passwords for the task "look what is in the client's database". Yes, this is a remote connection and MySQL on the hosting looks outward. But access via IP or SSH tunnel saves the father of Russian democracy.
The program has a lot of possibilities, it is better to read on the official website.

Sublime text

Without it, nowhere. A little trick in the settings:
("open_files_in_new_window": false,)
By default it is set to TRUE and because of this Cyberduck opens new files in a new window instead of in a new tab of an existing window.

In addition, it happens that you need to quickly run a small piece of PHP code, but it is not convenient to do this in the IDE. It is possible to execute PHP code from Sublime Text by adding a new Build System ( Tools –> Build System -> New):
("cmd": ["php", "$ file"])
Now we press CMD + B and the result of the code will appear in the Sublime Text console.

Dash


This is a handy collection of documentation, here are its features:

  • Auto-update documentation from official sites
  • Offline access
  • Cheat Sheets
  • Creating your own snippets
  • Integration into PhpStorm and Sublime Text

Of course, you can still start singing praises to touch gestures and full screen mode of applications, but that is beyond the scope of this article.

There are many ways to deploy a local server on Mac OS X, but the system itself already contains the pre-installed Apache web server and PHP interpreter, which must be activated and configured.

This tutorial requires some command line skills and knowledge of the nano editor, so I recommend reading a good book on command line and terminal basics in Mac OS X.

The material below is universal and will be useful to users of any operating system.

You can enable the web server in the settings: System Preferences\u003e Sharing\u003e enable the Web Sharing service.

If you type http: // localhost / in the address bar of your browser, the server will return a page with the text “It works!”.

Commands for working with Apache via the command line:

sudo apachectl start | stop | restart

Apache error on Mac OS X 10.6.5 and higher

The following error is observed when restarting Apache on Mac OS X 10.6.5 and higher, if you try to restart the server through the command line, Apache will return an error:

/ usr / sbin / apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument

You need to make changes to the apachectl script (/ usr / sbin / apachectl):

sudo nano / usr / sbin / apachectl

let's comment out line 82:

ULIMIT_MAX_FILES \u003d "ulimit -S -n ʻulimit -H -n`"

and add below it:

ULIMIT_MAX_FILES \u003d ""

Save the script and restart Apache.

Apache configuration

To configure Apache, open the /etc/apache2/httpd.conf file:

sudo nano /etc/apache2/httpd.conf

Go to line 116 and include PHP (you need to uncomment the line):

LoadModule php5_module libexec / httpd / libphp5.so

Let's set our own directory for the local server, change the path to the root directory on lines 168 and 195. After these changes, the root directory will be the Sites folder located in the user's home directory.

DocumentRoot "/ Library / WebServer / Documents"

DocumentRoot "/ Users / username / Sites"

Similarly, replace the old path on line 195:

On line 230, we write down which file types and in what sequence Apache should process:

DirectoryIndex index.php index.html

On line 264, you can set the location to store the Apache error log:

ErrorLog "/ private / var / log / apache2 / error_log"

Uncomment line 469 to include a file in which we will write virtual hosts:

Include /private/etc/apache2/extra/httpd-vhosts.conf

Save all changes in the httpd.conf file and restart Apache. If you go to the address http: // localhost /, the start page from the sites folder will be loaded with the greeting "Your website".

Let's check PHP functionality by creating a test PHP script in the Sites directory:

touch ~ / Sites / index.php
sudo nano ~ / Sites / index.php

and write a script to show the PHP configuration:

Save the index.php file and go to http: // localhost / again, the page with information about the PHP version should open. If the welcome page still loads, you need to check your Apache settings (line 230).

The php.ini configuration file is located in the /private/etc/php.ini.defaults folder, it must be renamed to php.ini:

sudo mv /private/etc/php.ini.default /private/etc/php.ini

Configuration of virtual hosts.

All projects will be located in the user's Sites directory (/ Users / username / Sites /). Let's create in this directory a new folder called test, and in it a file index.php with a test script. The local site will open at http: // test /. Go to the command line and enter the following commands:

mkdir ~ / Sites / test
cd ~ / Sites / test
touch index.php
nano index.php

and add a script:

Now let's start configuring virtual hosts. First, open the / etc / hosts file and add the local site address (http: // test /) to the exceptions. Let's go to the command line:

sudo nano / etc / hosts

and add the line:

Add entries with the configuration of the new virtual host:

sudo nano /private/etc/apache2/extra/httpd-vhosts.conf

And add records to the end of the file:

ServerAdmin DocumentRoot "/ Users / username / Sites / test" ServerName test AllowOverride All Order allow, deny Allow from all

Save changes and restart Apache. Now, if you go to the address http: // test / a page with a greeting "Hello world!" Will open.

All the instructions above are given taking into account my tastes and preferences, the purpose of this guide is to understand the basic principles of configuring native Apache and PHP on Mac OS X. With great pleasure I will listen to suggestions and comments on the availability of the material presented.

Today we will talk about a local web server available for both Windows and OS X. Moreover, its key feature is the presence of a simple and intuitive interface. You don't need to be a bearded administrator to run the server. It is enough just to thoughtfully read the instructions, and you can easily revive the local version of the site.

So, meet MAMP and MAMP PRO. The first one is free, but with stripped down features, which are still enough for most of your needs. The second one is paid, it will cost 4,000 rubles. If after reading you decide to download MAMP or buy MAMP PRO, welcome to the developer's site.

Let's talk about the free version of MAMP first, because this is the easiest way to get started with a local web server. Immediately after installation, you will have a working web server with Apache, MySQL and PHP.

mamp.info

After starting MAMP, you will see a simple menu of the most requested options. You can start or stop the web server, go to the main page of the web interface, or change any settings. You can configure the ports for Apache and MySQL, select the PHP version and specify the root folder of your project. In general, even with the default settings, you can start working.


mamp.info

The possibilities for customizing MAMP PRO are incomparably greater. Moreover, MAMP PRO is an add-on for free MAMP, so it can be installed at any time without harm to your current project. If you feel that the free version does not allow you to turn around, then moving will not be a hassle.

Now let's quickly go over the differences between MAMP PRO.

The developers are betting on the additional one and recommend running the web server in MAMP PRO under the www / mysql entry. This is especially true if the computer is constantly connected to the Internet. The full version also allows you to enable or disable individual Apache modules.


mamp.info

MySQL advanced options are also aimed at security. You can set or change the MySQL master password, and also restrict external access to your database. Also error logs are available for both Apache and MySQL, which can be useful. It is noteworthy that in MAMP PRO the phpMyAdmin interface is completely Russified, but the free version cannot boast of this.

The full version of the web server has Dynamic DNS support. It is possible to match the site name and your current IP address. In addition, there is support from the providers dyndns.com and easydns.com. It is enough to have an account with one of them to take advantage of Dynamic DNS support.


mamp.info

MAMP PRO will allow you to set up sending emails from your local web server, if the need arises.

The paid version also features the ability to create an unlimited number of hosts with a minimum of effort. In other words, you can run multiple sites at the same time. Free MAMP is limited to just one.


mamp.info

MAMP and MAMP PRO are the friendliest local web server solutions. A clear interface and detailed documentation will allow you to quickly understand all the intricacies. The need for an expensive paid version can arise if your work on a site or several resources goes beyond mere curiosity. It is a serious tool for web developers.

Did you like the article? To share with friends: